You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thanks for sharing, this repo has been so useful for me. I will explain a possible change to the script for those who want to use the CocoDetection class from PyTorch to load the dataset, just in case anyone faces the same issues as me.
I'm using PyTorch to train a Faster RCNN object detector, and all the model expects the data in the form defined by CocoDetection dataset class from PyTorch. The .json created with the script has one issue when using it with the mentioned dataset class. It has to do with image ids. The problem is that image ids are created as strings inside the .json, what then causes problems in CocoDetection class when loading images, as it uses the image id to lod the image and checks internally several times if the id is an integer, following a different loading path if not and causing exceptions.
In order to solve this, the easiest solution I've found is to just define the image ids as integers in the script, rather than strings. As images are labeled year_xxxxxxx.jpg, the id will be year_xxxxxxx. If this string is converted to integer, when converting the ids to a integers it just will convert them to yearxxxxxxx, therefore preserving the uniqueness of the id and not causing error when loading images with CocoDetection class.
The solution is to modify the voc2coco.py in the lines 51 to 56 of the script:
Current version:
Hello everyone,
First of all, thanks for sharing, this repo has been so useful for me. I will explain a possible change to the script for those who want to use the CocoDetection class from PyTorch to load the dataset, just in case anyone faces the same issues as me.
I'm using PyTorch to train a Faster RCNN object detector, and all the model expects the data in the form defined by CocoDetection dataset class from PyTorch. The .json created with the script has one issue when using it with the mentioned dataset class. It has to do with image ids. The problem is that image ids are created as strings inside the .json, what then causes problems in CocoDetection class when loading images, as it uses the image id to lod the image and checks internally several times if the id is an integer, following a different loading path if not and causing exceptions.
In order to solve this, the easiest solution I've found is to just define the image ids as integers in the script, rather than strings. As images are labeled
year_xxxxxxx.jpg
, the id will beyear_xxxxxxx
. If this string is converted to integer, when converting the ids to a integers it just will convert them toyearxxxxxxx
, therefore preserving the uniqueness of the id and not causing error when loading images with CocoDetection class.The solution is to modify the voc2coco.py in the lines 51 to 56 of the script:
Current version:
Modification:
And that's it, just casting the
img_id
variable to integer.I hope this will be useful for someone!
The text was updated successfully, but these errors were encountered: