Perform slicing yolo format #755
-
Hi, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hello @CesareDavidePace. You have to convert your dataset into coco format, then slice the dataset using sahi, then convert the sliced dataset into yolov5 format.
from sahi.slicing import slice_coco
coco_dict, coco_path = slice_coco(
coco_annotation_file_path=coco_annotation_file_path,
image_dir=image_dir,
slice_height=512,
slice_width=512,
overlap_height_ratio=0.2,
overlap_width_ratio=0.2,
)
from sahi.utils.coco import Coco, export_coco_as_yolov5
# init Coco object
train_coco = Coco.from_coco_dict_or_path("train_coco.json", image_dir="coco_images/")
val_coco = Coco.from_coco_dict_or_path("val_coco.json", image_dir="coco_images/")
# export converted YoloV5 formatted dataset into given output_dir with given train/val split
data_yml_path = export_coco_as_yolov5(
output_dir="output/folder/dir",
train_coco=train_coco,
val_coco=val_coco
) |
Beta Was this translation helpful? Give feedback.
-
Ive did a project to do exactly that, but as i coded it for my personal needs it may not be suited to your application(for example it doesnt save slices without labels). But it is easy modyfiable. https://github.com/andresinsitu/YOLO_slicing |
Beta Was this translation helpful? Give feedback.
Hello @CesareDavidePace. You have to convert your dataset into coco format, then slice the dataset using sahi, then convert the sliced dataset into yolov5 format.
You can use fiftyone to convert yolov5 dataset into coco format.
Then you can use this snippet to slice your dataset: