资源算法retinanet-examples

retinanet-examples

2019-12-23 | |  53 |   0 |   0

RetinaNet Examples

Fast and accurate single stage object detection with end-to-end GPU optimization.

Description

RetinaNet is a single shot object detector with multiple backbones offering various performance/accuracy trade-offs.

It is optimized for end-to-end GPU processing using:

  • The PyTorch deep learning framework with ONNX support

  • NVIDIA Apex for mixed precision and distributed training

  • NVIDIA DALI for optimized data pre-processing

  • NVIDIA TensorRT for high-performance inference

  • NVIDIA DeepStream for optimized real-time video streams support

Disclaimer

This is a research project, not an official NVIDIA product.

Performance

The detection pipeline allows the user to select a specific backbone depending on the latency-accuracy trade-off preferred.

BackboneResizemAP @[IoU=0.50:0.95]Training Time on DGX1vTensorRT Inference Latency FP16 on V100TensorRT Inference Latency INT8 on T4
ResNet18FPN8000.3185 hrs12 ms/im12 ms/im
ResNet34FPN8000.3436 hrs14 ms/im14 ms/im
ResNet50FPN8000.3587 hrs16 ms/im16 ms/im
ResNet101FPN8000.37610 hrs20 ms/im20 ms/im
ResNet152FPN8000.39312 hrs25 ms/im24 ms/im

Training results for COCO 2017 (train/val) after full training schedule with default parameters. Inference results include bounding boxes post-processing for a batch size of 1.

Installation

For best performance, we encourage using the latest PyTorch NGC docker container:

docker run --gpus all --rm --ipc=host -it nvcr.io/nvidia/pytorch:19.09-py3

From the container, simply install retinanet using pip:

pip install --no-cache-dir git+https://github.com/nvidia/retinanet-examples

Or you can clone this repository, build and run your own image:

git clone https://github.com/nvidia/retinanet-examples
docker build -t retinanet:latest retinanet/
docker run --gpus all --rm --ipc=host -it retinanet:latest

Usage

Training, inference, evaluation and model export can be done through the retinanet utility.

For more details refer to the INFERENCE and TRAINING documentation.

Training

Train a detection model on COCO 2017 from pre-trained backbone:

retinanet train retinanet_rn50fpn.pth --backbone ResNet50FPN 
    --images /coco/images/train2017/ --annotations /coco/annotations/instances_train2017.json 
    --val-images /coco/images/val2017/ --val-annotations /coco/annotations/instances_val2017.json

Fine Tuning

Fine-tune a pre-trained model on your dataset. In the example below we use Pascal VOC with JSON annotations:

retinanet train model_mydataset.pth 
    --fine-tune retinanet_rn50fpn.pth 
    --classes 20 --iters 10000 --val-iters 1000 --lr 0.0005 
    --resize 512 --jitter 480 640 --images /voc/JPEGImages/ 
    --annotations /voc/pascal_train2012.json --val-annotations /voc/pascal_val2012.json

Note: the shorter side of the input images will be resized to resize as long as the longer side doesn't get larger than max-size. During training, the images will be randomly randomly resized to a new size within the jitter range.

Inference

Evaluate your detection model on COCO 2017:

retinanet infer retinanet_rn50fpn.pth --images /coco/images/val2017/ --annotations /coco/annotations/instances_val2017.json

Run inference on your dataset:

retinanet infer retinanet_rn50fpn.pth --images /dataset/val --output detections.json

Optimized Inference with TensorRT

For faster inference, export the detection model to an optimized FP16 TensorRT engine:

retinanet export model.pth engine.plan

Note: for older versions of TensorRT (prior to TensorRT 5.1 / 19.03 containers) the ONNX opset version should be specified (using --opset 8 for instance).

Evaluate the model with TensorRT backend on COCO 2017:

retinanet infer engine.plan --images /coco/images/val2017/ --annotations /coco/annotations/instances_val2017.json

INT8 Inference with TensorRT

For even faster inference, do INT8 calibration to create an optimized INT8 TensorRT engine:

retinanet export model.pth engine.plan --int8 --calibration-images /coco/images/val2017/

This will create an INT8CalibrationTable file that can be used to create INT8 TensorRT engines for the same model later on without needing to do calibration.

Or create an optimized INT8 TensorRT engine using a cached calibration table:

retinanet export model.pth engine.plan --int8 --calibration-table /path/to/INT8CalibrationTable

Datasets

RetinaNet supports annotations in the COCO JSON format. When converting the annotations from your own dataset into JSON, the following entries are required:

{
    "images": [{
        "id" : int,
        "file_name" : str
    }],
    "annotations": [{
        "id" : int,
        "image_id" : int, 
        "category_id" : int,
        "bbox" : [x, y, w, h]
    }],
    "categories": [{
        "id" : int
    ]}
}

References


上一篇:enroot

下一篇:jetson-gpio

用户评价
全部评价

热门资源

  • Keras-ResNeXt

    Keras ResNeXt Implementation of ResNeXt models...

  • seetafaceJNI

    项目介绍 基于中科院seetaface2进行封装的JAVA...

  • spark-corenlp

    This package wraps Stanford CoreNLP annotators ...

  • capsnet-with-caps...

    CapsNet with capsule-wise convolution Project ...

  • inferno-boilerplate

    This is a very basic boilerplate example for pe...