pylabel
pylabel copied to clipboard
Multiple image extension for YOLOv5 dataset
My Yolov5 dataset has got multiple image extensions files such as jpg, jpeg, png, etc. What is the best way to handle these cases?
dataset = importer.ImportYoloV5(path=path_to_annotations, path_to_images=path_to_images, cat_names=yoloclasses,
img_ext="jpg", name="coco128")
in img_ext
we can only specify one extension format.
Hello @dnth, it doesn't work for multiple file types right now because they way it works is:
- Look for <image_x>.txt annotation file
- Look for an image in the path ../images/<image_x>.<image_ext>
I can think of a some solutions. Let me know what you think would make the most sense:
- Allow user to specify multiple file extension, then the code will check multiple file types and use the first one that it finds a match for. For example first check for <image_x>.jpg , if it doesn't find it, check for <image_x>.png. (I think this could be a little slow)
- Instead of look at the annotations and then look for the image, reverse and look for all the image files and then look for an annotation file. I think this might be cleaner, but it could have problems if there are extra images without annotations files.
Also would it be possible for you to share your dataset so I could use it for testing whatever solution we can come up with.
I am working with this dataset https://www.kaggle.com/nischallal/rice-disease-dataset
Thank you.
I checked the Yolo documentation and they support all of the image types "bmp, jpg, jpeg, png, tif, tiff, dng, webp, mpo"
I think the best fix would be to let the img_ext param take a comma seperated list like "bmp, jpg, jpeg, png, tif, tiff, dng, webp, mpo" and then check for any of those files until it finds a match.
I think I could work on the change and release a new version this weekend.
Or you are welcome to try and make the change yourself and make a pull request.
The change needs to be made in https://github.com/pylabel-project/pylabel/blob/dev/pylabel/importer.py around line 310
row["img_folder"] = path_to_images
row["img_filename"] = filename.name.replace("txt", img_ext)
# Get the path to the image file to extract the height, width, and depth
image_path = PurePath(path, path_to_images, row["img_filename"])`
Hello @dnth I have released a new version [v0.1.32] with support for multiple file types. Please give it a try!
img_ext (str, comma separated): Specify the file extension(s) of the images used in your dataset: .jpeg, .png, etc. This is required because the YOLO format does not store the filename of the images. It could be any of the image formats supported by YoloV5. PyLabel will iterate through the file extensions specified until it finds a match.
Thanks @alexheat! The conversion works now. However, I found another issue: there are files with the same filename in different folders.
Eg. valid/blast_orig_001.jpg
and test/blast_orig_001.jpg
because of this I suspect the annotations were mixed up.
This is the result of the conversion
Hi @dnth , yes I think there can be issue is the image names are not unique. That particular dataset looks like it has the same image in more than one split, which doesn't seem like a good thing to do in general.
Can you share the code that you used to import the data set and create the image in the screenshot?
Also I am curious what you are trying to do the with the dataset in general. Would you tell me more about your project?
Thanks! Alex
I would like to make an object detector model that can recognize disease on rice leaves. This is one dataset i found that comes with bbox annotations. I agree that the dataset might not be properly curated with the overlapping names. I should probably spend time to clean them up first i guess..
This is the repo to the codes I was using to generate the above screenshot https://github.com/dnth/paddy_disease_detection/blob/main/convert_data.ipynb