Skip to main content

Uses RetinaNet with FastAi

Project description


Some experiments with object detection in PyTorch and FastAi. This repo is created for educational reasons and to get a deeper understanding of RetinaNet and object detection general. If you like it, please let me know, if you find any bugs or tips for improvements also.


pip install object-detection-fastai

Test: Coco Colab

Update old code

# Old imports:
from helper.object_detection_helper import *
from loss.RetinaNetFocalLoss import RetinaNetFocalLoss
from models.RetinaNet import RetinaNet
from callbacks.callbacks import BBLossMetrics, BBMetrics, PascalVOCMetric

# New imports
from object_detection_fastai.helper.object_detection_helper import *
from object_detection_fastai.loss.RetinaNetFocalLoss import RetinaNetFocalLoss
from object_detection_fastai.models.RetinaNet import RetinaNet
from object_detection_fastai.callbacks.callbacks import BBLossMetrics, BBMetrics, PascalVOCMetric

RetinaNet WSI

The basline for this notebook was created by Sylvain Gugger from FastAi DevNotebook. Thank you very much, it was a great starting point and I'm a big fan off your work.

Publications using this code:

[x] Deep Learning-Based Quantification of Pulmonary Hemosiderophages in Cytology Slides



Cell detection Coco Chair Coco Couch Coco Vase


[x] Coco Metric at train time via callback Coco Metrics [x] Flexibility

# use the feature map sizes 32,18,8,4 with 32 channels and two conv layers for detection and classification
RetinaNet(encoder, n_classes=data.train_ds.c, n_anchors=18, sizes=[32,16,8,4], chs=32, final_bias=-4., n_conv=2)
  (classifier): Sequential(
    (0): Sequential(
      (0): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
      (1): ReLU()
    (1): Sequential(
      (0): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
      (1): ReLU()
    (2): Conv2d(32, 18, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
# use the feature map sizes 32 with 8 channels and three conv layers for detection and classification
RetinaNet(encoder, n_classes=data.train_ds.c, n_anchors=3, sizes=[32], chs=8, final_bias=-4., n_conv=3)

[x] Debug anchor matches for training.

On the left image we see objects that are represented by anchors. On the right objects with no corresponding anchors for training. Anchors The size of the smallest anchors should be further decreased to match the small objects on the right image.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for object-detection-fastai, version 0.0.4
Filename, size File type Python version Upload date Hashes
Filename, size object_detection_fastai-0.0.4-py3-none-any.whl (27.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size object-detection-fastai-0.0.4.tar.gz (22.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page