Transfer Learning on YOLOv3

0xfede: <p>I’m trying to do transfer learning on a pre-trained YOLOv3 implementation (<a href="https://github.com/ultralytics/yolov3" class="inline-onebox" rel="noopener nofollow ugc">GitHub - ultralytics/yolov3: YOLOv3 in PyTorch &gt; ONNX &gt; CoreML &gt; TFLite</a> as of now) so that instead of detecting the classic 80 coco classes it detects just 2 classes ‘related’ to ‘person’ (e.g., glasses / no glasses, hat / no hat). However I’m not being able to get the network to even properly overfit to my small dataset so I’m clearly doing something wrong and would be great if someone could point me in the right direction.</p>
<p>From my understanding of vanilla yolov3, there’s the darknet53 feature extractor, followed by the ‘yolo’ part of the network, of which layers 81, 93 and 105 (0-indexed) do the 1x1 convolutions that ultimately regress the boxes and assign class probabilities.</p>
<p>So I was expecting that I could:</p>
<ol>
<li>
<p>annotate a small dataset with examples of the 2 classes I’m interested in. I did this with makesense.ai and have currently 200 example images with one or more instances of either classes per image. I used 70% for training and 30% for validation.</p>
</li>
<li>
<p>modify conv layers 81, 93 and 105, along with their respective ‘yolo’ ones (in the cfg file) to have the appropriate number of filters and classes: (5+2)*3 for conv; 2 for ‘yolo’.</p>
</li>
<li>
<p><code>require_grad = False</code> on all parameters of the net other than the weights and biases for the conv layers mentioned in 2.</p>
</li>
<li>
<p>weight initialization: I tried the following initialization schemes:<br>
a- the darknet53.conv.74 file (i.e., only initializing the feature extractor trained on ImageNet)<br>
b- initializing all weights from a pre-trained yolo3 (i.e., the whole network trained on coco)<br>
c- same as b but then, for the layers in 1, I set all biases to 0 and all weights to xavier uniform.</p>
</li>
<li>
<p>Finally I trained with the settings most repos implementing yolo use: 300 epochs, 16 batch-size, 320 image size, SGD/momentum and learn rate decay, etc.</p>
</li>
</ol>
<p>I was hoping to overfit to my little dataset but the trained model doesn’t detect a single instance of my classes. Not even in the same images I trained on. So yeah, I’m doing something wrong. Maybe I need to do something about the 9 bounding boxes priors too? Any hints?</p>
<p>Here’s the training stats for case 3.a, which also look a bit off:</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/f/c/fccc6dc5aa2c7f72bbbb614d276464abab91dcba.png" data-download-href="https://discuss.pytorch.org/uploads/default/fccc6dc5aa2c7f72bbbb614d276464abab91dcba" title="Capture"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/f/c/fccc6dc5aa2c7f72bbbb614d276464abab91dcba_2_641x499.png" alt="Capture" data-base62-sha1="A4mjaGxu1hUHWjCe2ZRVsKFfmLE" width="641" height="499" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/f/c/fccc6dc5aa2c7f72bbbb614d276464abab91dcba_2_641x499.png, https://discuss.pytorch.org/uploads/default/optimized/3X/f/c/fccc6dc5aa2c7f72bbbb614d276464abab91dcba_2_961x748.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/f/c/fccc6dc5aa2c7f72bbbb614d276464abab91dcba.png 2x" data-dominant-color="FAFBFC"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Capture</span><span class="informations">1244×970 78.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>