Skip to content

Commit

Permalink
Refactor COCO utility functions and test imports
Browse files Browse the repository at this point in the history
- Simplify import and error handling in `coco.py`
- Clean up import statements in test file
- Minor code formatting improvements
  • Loading branch information
fcakyon committed Mar 8, 2025
1 parent 58c8453 commit e983fff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 3 additions & 4 deletions sahi/utils/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,9 +1357,7 @@ def export_as_yolo(
try:
import yaml
except ImportError:
raise ImportError(
'Please run "pip install -U pyyaml" to install yaml first for yolo formatted exporting.'
)
raise ImportError('Please run "pip install -U pyyaml" to install yaml first for yolo formatted exporting.')

# set split_mode
if 0 < train_split_rate and train_split_rate < 1:
Expand Down Expand Up @@ -2401,7 +2399,7 @@ def remove_invalid_coco_results(
return fixed_result_list


def export_coco_as_yolov5(
def export_coco_as_yolov5(
output_dir: str,
train_coco: Optional[Coco] = None,
val_coco: Optional[Coco] = None,
Expand Down Expand Up @@ -2519,6 +2517,7 @@ def export_coco_as_yolo(

return yaml_path


def export_coco_as_yolov5_via_yml(
yml_path: str, output_dir: str, train_split_rate: float = 0.9, numpy_seed=0, disable_symlink=False
):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_cocoutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,7 @@ def test_cocovid(self):
pass

def test_bbox_clipping(self):
from sahi.utils.coco import (Coco, CocoAnnotation, CocoCategory,
CocoImage)
from sahi.utils.coco import Coco, CocoAnnotation, CocoCategory, CocoImage

coco = Coco()
coco.add_category(CocoCategory(id=0, name="box", supercategory="box"))
Expand Down

0 comments on commit e983fff

Please sign in to comment.