Skip to content

Commit

Permalink
Update convert_segment_masks_to_yolo_seg to support custom datasets (
Browse files Browse the repository at this point in the history
  • Loading branch information
RizwanMunawar authored and Noobtoss committed Sep 12, 2024
1 parent 19adba7 commit b691090
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/en/usage/simple-utilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The converted masks will be saved in the specified output directory.
```python
from ultralytics.data.converter import convert_segment_masks_to_yolo_seg

# For COCO dataset we have 80 classes
# The classes here is the total classes in the dataset, for COCO dataset we have 80 classes
convert_segment_masks_to_yolo_seg(masks_dir="path/to/masks_dir", output_dir="path/to/output_dir", classes=80)
```

Expand Down
6 changes: 3 additions & 3 deletions ultralytics/data/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,13 @@ def convert_segment_masks_to_yolo_seg(masks_dir, output_dir, classes):
Args:
masks_dir (str): The path to the directory where all mask images (png, jpg) are stored.
output_dir (str): The path to the directory where the converted YOLO segmentation masks will be stored.
classes (int): Total classes in the dataset i.e for COCO classes=80
classes (int): Total classes in the dataset i.e. for COCO classes=80
Example:
```python
from ultralytics.data.converter import convert_segment_masks_to_yolo_seg
# for coco dataset, we have 80 classes
# The classes here is the total classes in the dataset, for COCO dataset we have 80 classes
convert_segment_masks_to_yolo_seg('path/to/masks_directory', 'path/to/output/directory', classes=80)
```
Expand All @@ -373,7 +373,7 @@ def convert_segment_masks_to_yolo_seg(masks_dir, output_dir, classes):
"""
import os

pixel_to_class_mapping = {i + 1: i for i in range(80)}
pixel_to_class_mapping = {i + 1: i for i in range(classes)}
for mask_filename in os.listdir(masks_dir):
if mask_filename.endswith(".png"):
mask_path = os.path.join(masks_dir, mask_filename)
Expand Down

0 comments on commit b691090

Please sign in to comment.