WePCf / darknet-mobilenet-v2

Darknet for MobileNet v2
Other
80 stars 27 forks source link

Creating a detector with Yolov3 backbone #10

Open muck27 opened 5 years ago

muck27 commented 5 years ago

Hi @WePCf

Can you point me in the direction of creating a Yolov3 head for object detection?

kei97103 commented 5 years ago

I'm not sure my approach is appropriate way to achieve your goal.

test.weights is the weight trained for classification. If you want to use mobilenet-v2 for object detection, you should modify the "test.cfg" file to train the weights file for object detection.

you need to download imagenet1k dataset or prepare your own custom data.

in test.cfg, classification layer is defined as follows.

[avgpool]

[convolutional]
filters=1000
size=1
stride=1
pad=0
activation=linear

[softmax]
groups=1

[cost]
type=sse

modify this layer to object detection layer

[convolutional]
size=1
stride=1
pad=1
filters=5025 ##number of output
activation=linear

[region]
anchors = 0.57902026, 1.0078453, 1.0029074, 1.29959966, 1.08171949, 1.72203126, 1.3360696, 2.66518302, 1.75393635, 1.75037688
bias_match=1
classes= 1000 ##number of class
coords=4
num=5
softmax=1
jitter=.3
rescore=1

object_scale=5
noobject_scale=1
class_scale=1
coord_scale=1

absolute=1
thresh = .6
random=0

imagenet1k uses 1000 classes. using 5 anchors, you should use (1000 + 5) * 5 = 5025 filters at last conv layer. If you use your own train data, you should modify this number.

If you use modified cfg file to use "darknet detector test" command, you will get bad result.

As I mentioned earlier, I think that this problem occurs because test.weights is a weights file that train for classification rather than object detection.

So to make weights file for object detection, follow the procedure below

  1. Change your cfg file to training mode (ex. batch 64, subdivisions 8 learning_rate=0.00001)
  2. Move test.cfg & test.weights to basic darknet (this may not be required... but I did)
  3. Make initial weight file using darknet partial command (ex. ./darknet partial mobilenet/test.cfg mobilenet/test.weights initial.conv.weights 80)
  4. Train it