Sunday, May 10, 2020

Deep Learning 6-Object Detection with Retinanet

Learn A-Z Deep Learning in 15 Days


In this Lecture, will learn about Objection Detection with Retinanet


Retinanet

The one-stage RetinaNet network architecture uses a Feature Pyramid Network (FPN) backbone on top of a feedforward ResNet architecture (a) to generate a rich, multi-scale convolutional feature pyramid (b). To this backbone, RetinaNet attaches two subnetworks, one for classifying anchor boxes (c) and one for regressing from anchor boxes to ground-truth object boxes (d). The network design is intentionally simple, which enables this work to focus on a novel focal loss function that eliminates the accuracy gap between our one-stage detector and state-of-the-art two-stage detectors like Faster R-CNN with FPN while running at faster speeds.




Data Preprocessing with Berekely dataset


Categories         frequency

    car-----------------------713211
   traffic sign---------------239686
traffic light-------------186117
    person--------------------91349
     truck-----------------------29971
   bus-----------------------11672
  bike-----------------------7210
  rider-----------------------4517
     motor-----------------------3002
train-----------------------136

  • Total annotation count = 1286871
  • Total images = 69863


**Run the Code in Google Colab

import os
import pandas as pd
import json

df = pd.DataFrame()
filepath='./bdd100k/labels/bdd100k_labels_images_train.json'
jsfile = json.loads(open(filepath).read())

for js in jsfile:
    for label_point in js['labels']:
        if label_point['category']=='bike' :
            
            df=df.append({'label':label_point['category'],
            'xmin': str(label_point['box2d']['x1']), 'ymin': str(label_point['box2d']['y1']),
            'xmax': str(label_point['box2d']['x2']), 'ymax':str(label_point['box2d']['y2']),
            'name':js['name']
}, ignore_index=True)

df.to_csv('./bdd100k_train.csv', index=False, sep=",", header= False)




Create Mapping for class
  • class name to ID mapping file should contain one mapping per line


Retinanet Implementation

!git clone https://github.com/fizyr/keras-retinanet.git

cd /content/keras-retinanet/

 !python setup.py build_ext --inplace

 !pip install keras_retinanet


Train Retinanet
  • Upload the 'bdd100k_train.csv' file in the 'keras-retinanet'
  • Upload the 'mapping_file.csv' file in the 'fkeras-retinanet'

!python keras_retinanet/bin/train.py --batch-size 1 --epochs 50 --tensorboard-dir ./Tensorboard_files/ --steps 171487 csv bdd100k_train.csv mapping_file.csv 


Convert the 'resnet50' to 'inference' model
!python keras_retinanet/bin/convert_model.py snapshots/resnet50_csv_02.h5 inference/inference_v20.h5


Test Retinanet model
  • Use the link below the to test the images








In the next blog, we will cover  Object Detection with YOLO.
https://sngurukuls247.blogspot.com/2020/05/deep-learning-7-object-detection-with.html

                                                                                                                                                  

Follow the link below to access Free Python Lectures-
https://www.youtube.com/sngurukul

Feel free contact me on-
Email - sn.gurukul24.7uk@gmail.com

1 comment:

  1. This post is very simple to read and appreciate without leaving any details out. Great work ! Call center Software Solution

    ReplyDelete