-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Tiny YOLO: Looking for suggestions to improve training on a custom dataset #406
Comments
For example add this code at the end of the function, before this line: Line 384 in 3ff4797
float max_prob = 0;
int max_index = 0, max_j = 0;
int i,j,n;
for (i = 0; i < l.w*l.h; ++i){
int row = i / l.w;
int col = i % l.w;
for(n = 0; n < l.n; ++n){
int index = i*l.n + n;
for(j = 0; j < l.classes; ++j){
if(probs[index][j] > max_prob) {
max_prob = probs[index][j];
max_index = index;
max_j = j;
}
}
}
}
for (i = 0; i < l.w*l.h; ++i){
int row = i / l.w;
int col = i % l.w;
for(n = 0; n < l.n; ++n){
int index = i*l.n + n;
for(j = 0; j < l.classes; ++j){
if(index != max_index || j != max_j) probs[index][j] = 0;
}
}
}
|
is it a good idea to pad images during preprocessing to make it compatible with I don't mean resizing them all to |
@VanitarNordic There are positive and negative points here for each case: #232 (comment)
Because I train my models on training dataset with the same image size (1280x720 or 1920x1080) as sizes of detection dataset, then I shouldn't keep aspect ratio, so for me the best option is to use this Darknet repository with the maximum object size. |
Okay, therefore this Darknet Repo does not keep the aspect ratio. I think it is the same with SSD. |
@VanitarNordic
Do you mean, that you will do as in original Darknet, but by yourself? It will keep aspect ratio, but you will have the smallest size of object. If you have small object - then this is bad idea. But if you have big objects, but all your images has different size - then this is good idea. |
By doing it myself outside before starting the training, You said this repo does not keep the aspect ratio, therefore I want to do the padding outside to make a correct fraction or multiplication of 416 for all images, by the padding method. Therefore even if the network does not keep the aspect ratio, but because of the correct numbers, then the object will not have un-normal shapes. |
Thanks a lot for the detailed reply! I will note your suggestions. Replies:
I used
As of now, just the defaults: 416x416.
|
Thanks a lot for the tips! The one that made the biggest difference was using 640x352 with random=0. Strangely, regenerating the anchors actually reduced the IoU (and map). Is this possible? Also, would you happen to have any tips for improving training only on certain classes? My training data is somewhat unbalanced: some classes have a lot more images than others, and running
Although the map/IoU looks really good on validation, it is slightly lower on test data: so I am just curious if I can improve training for only specific classes. |
@saihv Simple solution is to do many duplicates of images+labels of classes which have small number of images. Then re-generate train.txt by using Yolo_mark. |
Got it, thank you! I will try that. Just one last question in the custom dataset area, if you don't mind: I am working on an object detection contest, where I only have access to training data. I am supposed to train a model, which is then evaluated on a test set with the same classes (I don't have access to these test images); and the evaluation metric is the average IoU. I am splitting the given data into train and validation (as usual) and training my tiny YOLO model: but there is a noticeably big difference in IoU between validation and test (avg. 80% on validation vs 60% on test). I guess this could be because of multiple reasons: the test data might be more challenging, or perhaps it has a different distribution of images per class etc. But conceptually, this seems like a tricky problem because the model does perform well in validation, but it still looks like there is some overfitting when it comes to new data. So that makes me curious, are there any tips or tricks to making a model more generalized? Thanks! |
Yes.
Increase params in the data augmentation and train 10x times more iterations. Also fix this mistake: Line 175 in 8b5344e
mask = 0,1,2
|
Thanks! I'm using Tiny YOLO v2 right now at 640x352 (all images, training
and test are at 640x360) because of FPS requirements. I'll try changing
random and jitter.
…On Tue, May 15, 2018, 9:37 AM Alexey ***@***.***> wrote:
the test data might be more challenging, or perhaps it has a different
distribution of images per class etc.
Yes.
------------------------------
So that makes me curious, are there any tips or tricks to making a model
more generalized?
Increase params in the data augmentation and train 10x times more
iterations.
random=1 jitter=0.4 increase width and height to 608 or 832.
If you should detect objects with different colors as the same class_id,
increase hue=0.2 saturation=1.8 exposure=1.8
Also fix this mistake:
https://github.com/AlexeyAB/darknet/blob/8b5344ee2dc551dbe673020a33021e7f84f305f1/cfg/yolov3-tiny.cfg#L175
mask = 0,1,2
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#406 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACKz1oIKV6NniMEnONR6G-znTTtC_06Cks5tywQwgaJpZM4SSLnq>
.
|
If you want to use Also did you re-calculate anchors? You can do it too for |
I tried regenerating anchors in the past through this command:
But using those anchors actually decreased the IoU. I now see that I should probably try with those width and height arguments (net.w/32 and net.h/32 I guess?) |
@saihv Set here: darknet/scripts/gen_anchors.py Lines 17 to 18 in 8b5344e
|
Oops, I should have looked at that! Thanks for pointing it out, will change it and try. |
I tried training with Would it be helpful to train at a higher resolution (more than 640x360 but still non-square) and |
@saihv What mAP can you get for random=1 and random=0? |
random=0:
random=1:
Please note the difference in AP for classes 1, 4 and 9: which are the challenging ones with smaller object sizes. Both configurations were trained for about ~120k iterations after which the mAP settles and does not change by much. |
@saihv Try to change these lines: Lines 132 to 134 in 4403e71
to these: float random_val = rand_scale(1.4); // *x or /x
int dim_w = roundl(random_val*init_w / 32) * 32;
int dim_h = roundl(random_val*init_h / 32) * 32; And train with |
Trained it for 120k iterations with those changes, and now the mAP is pretty close to random=0:
But I guess because random=1 switches between low and high resolutions, it might be beneficial to train for more iterations. |
Yes. random=1 is almost the same as if there will be 2x more images, so it requires 2x more itrations. What jitter do you use in all these cases? |
I am still using jitter=0.2. I remember one of your suggestions was to move to 0.4, but I was just testing one thing at a time, so that's next on my list. |
Yes, better to test one thing at a time. Changing jitter from 0.2 to 0.4 requires about 5-10x times more iterations. |
I am currently working on object detection on a custom dataset, where a close to real time implementation on a Jetson TX2 is the final goal. Hence, I am trying to achieve a performance of ~30 fps (20-30 would be acceptable too as long as accuracy is not too bad) as well as a decent IoU.
As of now, I am using Tiny YOLO as my framework through Darknet, compiled with GPU and CUDNN support. The images are 640x360 in dimensions and I have about 100000 of them with around 10 classes of objects in total. I've trained tiny YOLO for about 80000 iterations and on an average, this has given me IoUs of around 50% on the test dataset with a performance of around 18 fps on the Jetson TX2: I am currently looking to improve these numbers while not affecting the performance too much. I was hoping to get some suggestions regarding this:
(I see in the README two points relating to this: parameters
small_object=1
andrandom=1
. Do these affect the performance adversely at the cost of increased accuracy?)Does YOLO have a performance boost when working on square images? i.e., is there any noticeable improvement in resizing the images to square?
Is IoU the best metric to check when trying to increase or derease network-resolution (width and height)? I gather from the README that these values create an accuracy vs speed trade-off, how should I pick the best values for my application?
When performing training or inference, in my application, each image has only one class of object in it. Can I somehow exploit this fact to improve the performance a little (somehow tell YOLO that the maximum number of objects it needs to finally detect is just one)?
Any other general comments aimed at improving accuracy or speed are very welcome too. Thanks!
The text was updated successfully, but these errors were encountered: