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

How to impove small object detection #3198

Open
ChungChinKei opened this issue May 21, 2019 · 8 comments
Open

How to impove small object detection #3198

ChungChinKei opened this issue May 21, 2019 · 8 comments

Comments

@ChungChinKei
Copy link

@AlexeyAB Hi,

Thank you so much for sharing this project.
I am trying to detect some small defects on Metal surface.

Some information about dataset:
Only 1 class.
Grayscale images.
200 images for training(100 images of positive data and 100 negative).
50 images for validation(all positive).
Images resolution is 1600 x 1200.
objects size is about 30 x 30.(even smaller)
yolov3-tiny_3l.cfg with generated anchors.

Positive sample
NG(4)
NG(7)

Negative sample
OK12

Could you give me some advise to impove mAP?
chart_1024X768_8000

Some details of cfg:
[net]
batch=64
subdivisions=32
width=1024
height=768
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1
exposure = 1.5
hue= 0

learning_rate=0.005
burn_in=1000
max_batches = 10000
policy=steps
steps=8000,9000
scales=.1,.1

[yolo]
mask = 6,7,8
anchors = 21, 19, 29, 19, 27, 23, 30, 29, 36, 24, 48, 27, 40, 35, 77, 22, 56, 42
classes=1
num=9
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1

@jonasmuriboe
Copy link

I would recommend using the full size YOLOv3 architecture like in yolov3.cfg, or maybe even yolov3-spp.cfg as this has an even higher mAP. You should try the two following modifications as well as I have personally had a drastic improvement in performance by applying them to a network that attempts to find very small objects, typically in the same size-range as you.

for training for small objects (smaller than 16x16 after the image is resized to 416x416) - set layers = -1, 11 instead of

layers = -1, 36
and set stride=4 instead of
stride=2

As well as this

recalculate anchors for your dataset for width and height from cfg-file: darknet.exe detector calc_anchors data/obj.data -num_of_clusters 9 -width 416 -height 416 then set the same 9 anchors in each of 3 [yolo]-layers in your cfg-file. But you should change indexes of anchors masks= for each [yolo]-layer, so that 1st-[yolo]-layer has anchors larger than 60x60, 2nd larger than 30x30, 3rd remaining. Also you should change the filters=(classes + 5)* before each [yolo]-layer. If many of the calculated anchors do not fit under the appropriate layers - then just try using all the default anchors.

@AlexeyAB
Copy link
Owner

@ChungChinKei Hi,

  1. Try to train with default anchors.

  2. Also you can try to train with SGDR:
    change these lines:

    policy=steps
    steps=180000,190000
    scales=.1,.1

    to these lines:

policy=sgdr
sgdr_cycle=1000
sgdr_mult=2
steps=4000,6000,8000,9000
#scales=1, 1, 0.1, 0.1

Also you can try to use one of new models (without LSTM in filename - since LSTM is only for detection on video): #3114 (comment)

But they are supported only by this repository.

@ChungChinKei
Copy link
Author

@AlexeyAB @jonasmuriboe

Thanks for your reply and suggestions .
But some errors occurred when I used the new PANet models.
How can I fix it?
errors

@Look4-you
Copy link

Look4-you commented May 23, 2019

@AlexeyAB Thanks for the great work!
I wonder Why is the calculated anchors less fit than the default anchors. I've try to set the anchors (which is calculated by the darknet.exe detector) at each mask layer(0.1.2/3.4.5/.6.7.8) to replace the default anchors sizes,but the come out was very unsatisfied.
If I do this wrong,how can I use the calculated anchors correctly?Could you please give me some advisement.(May be just replace some of the defult anchors but not all of them?)
Here is the calculated anchors pic:
1558585053(1)

@AlexeyAB
Copy link
Owner

@shadowmooon

How can I fix it?

You must use the latest versions of this repository: https://github.com/AlexeyAB/darknet

If I do this wrong,how can I use the calculated anchors correctly?Could you please give me some advisement.

You must change the masks (or you must change only some anchors): https://github.com/AlexeyAB/darknet#how-to-improve-object-detection

recalculate anchors for your dataset for width and height from cfg-file: darknet.exe detector calc_anchors data/obj.data -num_of_clusters 9 -width 416 -height 416 then set the same 9 anchors in each of 3 [yolo]-layers in your cfg-file. But you should change indexes of anchors masks= for each [yolo]-layer, so that 1st-[yolo]-layer has anchors larger than 60x60, 2nd larger than 30x30, 3rd remaining. Also you should change the filters=(classes + 5)* before each [yolo]-layer. If many of the calculated anchors do not fit under the appropriate layers - then just try using all the default anchors.

@Look4-you
Copy link

Look4-you commented May 23, 2019

@AlexeyAB
How to change the masks.Could you take an example?

@duohappy
Copy link

@shadowmooon
refer to
#3372
#2960

@sadimoodi
Copy link

@ChungChinKei

did Alexy suggesiton work for you? i am doing something similiar to you so it would help me if you have any further suggestions,
thanks

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

No branches or pull requests

6 participants