[SSD] Small object detection
Hi all,
I have a question regarding the configuration of SSD. An interesting task for me is to fine-tuning the SSD_mobilenet_v1_coco_2017_11_17 with Bosch small traffic light dataset.
However, the default setting is to resize the image into 300 x 300 (image_resizer).
Here is the total loss during training.
It loss maintains around 6. (Please ignore the overlapping at 5000 steps, due to some re-launch trainign process.)

I think the trend of the total loss is okay. However, when I stop around 12k and feed with the test dataset (around 90 images for a short try). There is nothing detected.

Personally, I have some doubts about this issue:
- Maybe the small traffic lights are too small for SSD?
- However, why the total loss curve displayed a correct "learning" process?
Can I simply change the config of image size into 512 x 512 or even larger value (1000 x 1000)? Will this work correctly as well?
Regards, Hao
Did you try taking 300x300 crops from the images?
You could try training it on smaller images and feed in overlapping crops of size 300x300 that tile the original image, which could be bigger. I was able to train it on 1000x600 images, and it worked on my test set which was also 1000x600. This might be slightly hard since your original set is not 300x300, but if instead you could form a dataset out of random crops of size 300x300 from your original set then maybe...
The images I am actually working with are around 12MP, and I am feeding in crops of size 1000x600. However, with 1000x600, SSD is struggling to learn the classes, but the localization error is very low.
Hi @oneTimePad,
Thanks for your reply.
I have thought about this approach too. However, in this case, I need to take care of the annotation too right?
Did you first annotation all the images and then covert the annotations into the cropped corresponding image (with some python script I assume)?
Or you first crop them and then annotate manually on those 300x 300 images?
@Tsuihao you cropping already annotated images. SSD has issues with detecting small objects but Faster-RCNN much better at this.
Hi @Luonic,
Yes, I had successfully trained faster rcnn and obtained an accurate result.
As shown:

However, it is too slow for my use case. That is why I want to try the fastest SSD mobilenet model :)
I have some concerns regarding the annotated information.
When you crop the annotated images, how did you "update" the information in the original annotation?
Let's say:
Original image 1280 x 720 and the annotated traffic light is :
boxes:
{label: Green, occluded: false, x_max: 752.25, x_min: 749.0, y_max: 355.125, y_min: 345.125}
when you crop it into 300 x 300, the annotated image coordinate system need to be updated. Did you manually re-annotate them or there is some crop image tool can help you do this?
Regards, Hao
Ah, yes. Completely forgot about the annotation. In my case I have program that generates all of my training data, so I can easily change the training data image size (which will then change the annotations). However, yeah, you could write a program that converts the bounding box coordinates as you mentioned, but as mentioned I am still struggling with getting the classification accuracy up.
An idea I had, was to first train mobilenet base network, fine tuning from the checkpoint trained on the coco dataset or a classification checkpoint, to just classify small crops of the the objects of interest. In your case, crops of traffic lights classifying their color. Then go back to SSD and fine-tune the model from these weights trained to classify. I haven't tried this yet, but it might help mostly with the classification accuracy.
You mentioned mobilenet(s); have you tried a different base network?
Hi @oneTimePad,
Thanks for the reply. So there is one way I could do is: crop the traffic light image and then re-annotate all the images I was trying to avoid this since the manual crop and re-annotate will take few days I assume :p.
In my case, I also used the pre-trained SSD mobilenet on coco dataset and fine tuning with the traffic light dataset.
There are two assumptions I made (please correct me if I am wrong):
-
during the image_resize to 300 x 300, Tensorflow will also resize the annotation in "tf.record" data: In my case, it does not work just because the original images 1280 x 720 resize into 300 x 300, the small traffic light just nearly vanishes. I suspect that is the reason I could not have the correct result.
-
I assume that the release Tensorflow SSD mobilenet is under SSD300 architecture, not SSD500 architecture : And this is why I was trying to change the image_resizer into larger value (512 x 512); however, it still not worked.
Maybe the last way is really like what you say, crop and re-annotate everything. that will be a lot overhead.
If you want to train an SSD512 model, you need to start from scratch. The pre-trained model can only be fine-tuned as SSD300 model.
Hi @Tsuihao Did you successfully train the SSD model on small objects? If so how did you get around it?
My original images are 512x512 I am thinking about cropping them to 300x300 around the areas of interest and create the TFrecords file from the cropped ones. Would this be ok?
Hi @augre,
I have not tried it yet. I am also thinking about the same approach as you described and will try it as long as I have time.
I am not sure how the performance will be of cropping training images. Maybe you can share your experience later :)
Hi @Tsuihao
Could you share your trained model(faster-rcnn)?
And what framework did you use for training, caffe or tensorflow?
Thanks
@Tsuihao Any progress on this method ? I'm having the same issue, do you have any interesting findings that you remember you could share ? Thanks !
Try this paper S3FD: Single Shot Scale-invariant Face Detector https://arxiv.org/abs/1708.05237 They modified SSD OHEM and IOU criterion to be more sensitive to small object like faces
Hi, I'm interested in training ssd500 mobilenet from scratch, can someone give me some hints? Thank you.
Hi @Tsuihao
I have a problem with ssd_mobilenet_v2_coco. My images are 600x600 size but with resizing in the config file 300x300. Is there any possibility to work 600x600 in this case? Do my training images have to be 300x300? How did you solved small object problem?
@sapjunior : Have you used the implementation on some application other than faces?
@jungchan1 sorry I could not provide my trained work. I was using TensorFlow
@cyberjoac Nope, I did not go further on this topic; however, I am still looking forward to see if anyone can share the experience in this community :)
@elifbykl 600X600 for me sounds acceptable to resize into 300x300; however, it also depends on the relative object size you are working on. Based on the above discussion, you training image will resize inito 300x 300 due to the fixed architecture SSD provided by Tensorflow. I am still not solving the small object detection with SSD yet.
I trained a model capable of recognizing 78 German traffic signs. I used Tensorflow's Object Detection API for the training. The model can recognize the characters at a signsof about 15 meters. Here you can download the model and try it out.
Model: http://eugen-lange.de/download/ssd-4-traffic-sign-detection-frozen_inpherence_graph-pb/
@Tsuihao i had a similar problem and i needed to slice the image into smaller tiles/crops. however i already labelled my dataset and i was not sure what size of tiles were suitable for training. So i wrote a python script that slices the image in a giving size and recalculates the annotations for you in separate .xml files per tile/image it creates.
Here is the code, its far from perfect but i needed a quick solution. https://github.com/julianklumpers/slice_image_with_annotations/blob/master/slice_image_with_annotations.py
It uses openCV rather then PIL because i tested both and openCV was much quicker with sliceing and saving the images. It creates tiles with coordinates from the original image as a name, this way i can stich the image back together. Feel free to adjust it to your needs. i will probably make a library some day
The function creates 2 rows and 2 columns. so if you have a image that is 1000x1000 and you need 500x500 tiles. you just put size=(2,2) 1000 / 2 = 500.
Hello @Tsuihao,
have you tried the stock SSD_mobilenet_v1_coco_2017_11_17 without training and see the result visually?
My situation is the performance from stock SSD_inception_v2_coco_2017_11_17 is better than my trained-with-kitti model on car detection.
I am still working on this and hopefully can get back to you ASAP.
Best,
Hi @willSapgreen,
Yes, I have tried to use the pure SSD_mobilenet_v1_coco_2017_11_17 to do the traffic light detection. And the result is better than my trained SSD with traffic light dataset.
However, this result can be foreseen due to the fact that SSD_mobilenet_v1_coco_2017_11_17 trained with the COCO dataset. In my case, I need a more details about the detected traffic lights e.g. red, green, yellow, red left, etc.
In your case, you wanted to detect car, I believed that car in the image is much bigger than the traffic light; therefore, you should not have the same issue (traffic light is too small) as mine. I will suggest you to:
- Check your tensorboard report (see whether training result is good or bad)
- Change with different model e.g. faster_rcnn (see whether your data/label is valid)
Regards,