Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple image extension for YOLOv5 dataset #26

Closed
dnth opened this issue Feb 18, 2022 · 8 comments · Fixed by #27
Closed

Multiple image extension for YOLOv5 dataset #26

dnth opened this issue Feb 18, 2022 · 8 comments · Fixed by #27

Comments

@dnth
Copy link
Contributor

dnth commented Feb 18, 2022

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.

@alexheat
Copy link
Contributor

Hello @dnth, it doesn't work for multiple file types right now because they way it works is:

  1. Look for <image_x>.txt annotation file
  2. 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:

  1. 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)
  2. 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.

@dnth
Copy link
Contributor Author

dnth commented Feb 18, 2022

I am working with this dataset https://www.kaggle.com/nischallal/rice-disease-dataset

@alexheat
Copy link
Contributor

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"])`

alexheat added a commit to alexheat/pylabel that referenced this issue Feb 20, 2022
Add support to be able to import a Yolov5 dataset with images in multi image formats. For example jpg and png. 
This will resolve issue pylabel-project#26 (Multiple image extension for YOLOv5 dataset)
@alexheat alexheat linked a pull request Feb 20, 2022 that will close this issue
@alexheat
Copy link
Contributor

Hello @dnth I have released a new version [v0.1.32] with support for multiple file types. Please give it a try!

@alexheat
Copy link
Contributor

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.

@alexheat alexheat reopened this Feb 20, 2022
@dnth
Copy link
Contributor Author

dnth commented Feb 21, 2022

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
image

@alexheat
Copy link
Contributor

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

@dnth
Copy link
Contributor Author

dnth commented Feb 22, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants