Hi, I am trying to train on my dataset.
Thus I 'd like to know how to load bounding boxes.
In train.py, DataLoader reads the txt file which has the absolute paths of image data (trainvalidno5K.txt).
However, I cannot find where their annotations and bounding boxes are loaded.
How and Where does this code load bounding boxes for COCO dataset?
Look in utils/datasets.py -> line 118. 'filled_labels' contain your bounding boxes.
If you are running the detect.py script he doesn't load any boxes since it uses the 'ImageFolder' class. If you are running the train / test.py scripts it instead uses the ListDataset which returns your bounding boxes
Thanks!
I should setup txt files whose each line is
"'class` number' 'relative bb x1' 'relative bb y1' relative bb x2' relative bb y2'"
, for example,
1 0.5 0.3 0.6 0.4
right?
Almost. Yolo wants the bounding boxes to mark the center coordinate, the width, and the height.
So the label file should look like -> CLASS X-CORD Y-CORD X-WIDTH Y-WIDTH
Also, if you are training on your own dataset, make sure to change the number of classes in the config file and the number of activations coming to the detection layer. The default is 80 classes and 255 activations. You need to change them in three places. Search the issues for more info :) gl!
Received your pointing out, I understand that X and Y-CORD are the relative value of the center coordinates of the bounding box (bb),and X-WIDTH and Y-WIDTH are the relative value of the width and the height of the bb, respectively, where the 'relative' means the original image width and height.
For example, in a 400x400 image, a bb exists on (100,200) and its size is 50x80, then
X-CORD = 100/400 = 0.25,
Y-CORD = 200/400 = 0.5,
X-WIDTH = 50/400 = 0.125,
Y-WIDTH = 80/400 = 0.2
I looked at COCO_val2014_000000000042.jpg and txt and the above understanding may be correct.
Thank you for pointing out.
I am also glad that you advised to change not only classes .names file but also the activations. I had not think the activations are also important until your comment.
Np! You seem to understand it correctly now. I want to point out that YOLOv3 can take square input images that are divisible by 32. An image of 256x256 -> 256 / 32 = 8
This code resizes & pads your images before inputing them to YOLOv3 so it should be fine :)
Thank you. '400' is just for example. Fortunately, my dataset images have size 512x512 :)
Recently, I have seen the compute of the bounding boxes in this project.
I think it is calculated like this in the annotations of the labels/val2014, such as the COCO_val2014_000000001448.jpg(w×h→ [500×375]).
The original label in COCO is (x, y, width, height)→[113.11, 14.13, 257.22, 327.17]
but the labels in labels/val2014 are (x_center, y_center, width, height) → [0.4834, 0.473907, 0.51440, 0.872453].
The calculation process is as follows:
0.51440 = 257.22 / 500
0.872453 = 327.17 / 375
0.4834 = 113.11 / 500 + 0.5144 / 2
0.473907 = 14.13 / 375 + 0.872453 / 2
Most helpful comment
Received your pointing out, I understand that X and Y-CORD are the relative value of the center coordinates of the bounding box (bb),and X-WIDTH and Y-WIDTH are the relative value of the width and the height of the bb, respectively, where the 'relative' means the original image width and height.
For example, in a 400x400 image, a bb exists on (100,200) and its size is 50x80, then
I looked at COCO_val2014_000000000042.jpg and txt and the above understanding may be correct.
Thank you for pointing out.
I am also glad that you advised to change not only classes
.namesfile but also the activations. I had not think the activations are also important until your comment.