Object detection in fast.ai v1

Since the creation of the notebook model_size changed its behaviour. You can now use:
sfs_szs = model_sizes(encoder, size=imsize)
hooks = hook_outputs(encoder)
instead. That should work for you.

1 Like

Thanks @msandroid! I am one step further now, again running into an error that seems to come from changes in teh fastai source code…

For anybody working on this, you can use my GIST as a start …

3 Likes

Thanks @hkristen . So I think play with object detection in fast.ai now is quite difficult because it misses example and the library is still changing. I switch to read last year course with SSD and hope Jeremy will tell something about it in the last session of part 1 v3

No, it won’t be covered until part 2.

4 Likes

I think the conv2d_relu can be replaced by conv_layer. Or at least, that’s what I did, and it solved the issue.

I now have a notebook that runs until the learning part (included), but unfortunately, the loss function doesn’t go down when I’m trying to learn :frowning:

One more thing that I had to change in order to make the notebook run was to replace in the FocalLoss definition:

clas_loss = F.binary_cross_entropy_with_logits(clas_pred, encoded_tgt, weights, reduction=‘sum’)

by

weights_no_grad = weights.detach()
clas_loss = F.binary_cross_entropy_with_logits(clas_pred, encoded_tgt, weights_no_grad, reduction=‘sum’)

Otherwise, Pytorch was trying to compute the gradient of the weights and sending an error…

It’s frustrating, I feel like we’re close to making it work !!

3 Likes

I found a working object detection algorithm y’all will find interesting.

5 Likes

@divyansh and I have gotten object detection to work with fastai v1. The dev notebook is at https://github.com/rohitgeo/singleshotdetector

This creates a Dynamic SSD based on the number of grid cells, zoom levels and aspect ratios for the anchor boxes.

We haven’t trained the network fully in the dev notebook… like unfreezing and fine-tuning, and using Focal Loss (which is supported) etc, but are getting good results already. Hope you find it useful!

See Dynamic SSD implementation for fastai v1 for more details.

12 Likes

So the code in fastai v1 for object detection will not be ready until part 2? I see already in the docs the yolov3 architecture… It is not yet 100% ready?

1 Like

There is no YoloV3 in the fastai library and what’s in preparation is Retina Net, but no, it won’t be ready before part 2.

3 Likes

I think that what you saw is that darknet is available in the fastai CV model zoo. YOLOv3 uses darknet so that’s why YOLOv3 is mentioned.

Seems like yolo is more famous. Just for curiosity, why would we pick retina net over yolov3 for lecture? Is retina net easier to teach or other reasons?

RetinaNet uses a pretrained ResNet backbone, while Yolov3 uses Darknet53 as a backbone. There is no pretrained Darknet53 model available in fastai, which you would need to implement Yolov3. This is why fastai will use RetinaNet.

FWIW, I tried to load the weights from the original Darknet53 implementation in C into the fastai implementation. I could never get it to quite work. I think the weights were loaded correctly, but since fastai uses a slightly different output layer than the original C implementation, I couldn’t validate it. I’ve since moved on to trying to train fastai Darknet53 on imagenet from scratch. I’ll share my results on the forum when I get the top-1 accuracy into the 70%+ range.

11 Likes

Thanks for this, nice work!

I have a problem. When I run the code to transfer the pre-training model: learn=create_cnn(…), the code will automatically download the model, but it will be interrupted due to time and network speed, so I download the pre-training model in advance. When you run this code again, it will be stuck here. How can I solve this problem? Please help everyone.

Hi Sgugger,
I am trying to run the dev notebook 102a_coco and I receive the error objectdetectdataset not defined how do I fix this error?
Thanks


there are new notebook for retinaNet Objection

1 Like

Hi,

I tried to put all the pieces for object detection in fast.ai v1 with RetinaNet together.

With kind regrads,
Christian

18 Likes

Nice work! Have you tried to train on Pascal VOC and/or COCO datasets and measure mAPs?

I put everything together to do so including writing a callback for fast.ai, but I´m a little bit short on computational resources to do so.