47. SSD_Inception_V2 vs SSD_MobileNet_V2

COMPARING MODELS
Last week, I was able to deploy SSD_mobileNet_v2, so for comparison, this time I deployed SSD_Inception_V2.

PREREQUISITE
– DeepStream 5.0.1
– Jetpack 4.4
– Tensorflow 1.15.0 ( If you haven’t installed it yet, check out my last post)

REFERENCES
https://havedatawilltrain.com/stream-of-the-jest/
– https://github.com/NVIDIA/TensorRT/tree/main/samples/sampleUffSSD



IMPLEMENTATION
1. Get the model and save it to /tmp/ directory

wget -qO- http://download.tensorflow.org/models/object_detection/ssd_inception_v2_coco_2017_11_17.tar.gz | tar xvz -C /tmp

2. Change the directory to where all the pre-ready deepstream-app config files are saved.

cd /opt/nvidia/deepstream/deepstream-5.0/sources/objectDetector_SSD

3. Create config_ssd_inception.py file

sudo nano config_ssd_inception.py

Inside config_ssd_inception.py

import graphsurgeon as gs
import tensorflow as tf

Input = gs.create_node("Input",
                       op="Placeholder",
                       dtype=tf.float32,
                       shape=[1, 3, 300, 300])
PriorBox = gs.create_plugin_node(name="GridAnchor", op="GridAnchor_TRT",
                                 numLayers=6,
                                 minSize=0.2,
                                 maxSize=0.95,
                                 aspectRatios=[1.0, 2.0, 0.5, 3.0, 0.33],
                                 variance=[0.1, 0.1, 0.2, 0.2],
                                 featureMapShapes=[19, 10, 5, 3, 2, 1])
NMS = gs.create_plugin_node(name="NMS", op="NMS_TRT",
                            shareLocation=1,
                            varianceEncodedInTarget=0,
                            backgroundLabelId=0,
                            confidenceThreshold=1e-8,
                            nmsThreshold=0.6,
                            topK=100,
                            keepTopK=100,
                            numClasses=91,
                            inputOrder=[0, 2, 1],
                            confSigmoid=1,
                            isNormalized=1)
concat_priorbox = gs.create_node(
    name="concat_priorbox", op="ConcatV2", dtype=tf.float32, axis=2)
concat_box_loc = gs.create_plugin_node(
    "concat_box_loc", op="FlattenConcat_TRT", dtype=tf.float32, axis=1, ignoreBatch=0)
concat_box_conf = gs.create_plugin_node(
    "concat_box_conf", op="FlattenConcat_TRT", dtype=tf.float32, axis=1, ignoreBatch=0)

namespace_plugin_map = {
    "MultipleGridAnchorGenerator": PriorBox,
    "Postprocessor": NMS,
    "Preprocessor": Input,
    "ToFloat": Input,
    "image_tensor": Input,
    "MultipleGridAnchorGenerator/Concatenate": concat_priorbox,
    "MultipleGridAnchorGenerator/Identity": concat_priorbox,
    "concat": concat_box_loc,
    "concat_1": concat_box_conf
}


def preprocess(dynamic_graph):
    # Now create a new graph by collapsing namespaces
    dynamic_graph.collapse_namespaces(namespace_plugin_map)
    # Remove the outputs, so we just have a single output node (NMS).
    dynamic_graph.remove(dynamic_graph.graph_outputs,
                         remove_exclusive_dependencies=False)

4. convert the model with config_ssd_inception.py and export it as samples_ssd_relu6.uff.

sudo python3 /usr/lib/python3.6/dist-packages/uff/bin/convert_to_uff.py \
/tmp/ssd_inception_v2_coco_2017_11_17/frozen_inference_graph.pb -O NMS \
-p /opt/nvidia/deepstream/deepstream-5.0/sources/objectDetector_SSD/config_ssd_inception.py \
-o /opt/nvidia/deepstream/deepstream-5.0/sources/objectDetector_SSD/sample_ssd_relu6.uff

5. Check CUDA Version (This time, it was 10.2)

nvcc -V

6. Specify the CUDA version you’ve just checked, and build the pre-readied post-processing parser

sudo CUDA_VER=10.2 make -C nvdsinfer_custom_impl_ssd

7. Copy pre-readied label data to the current directory

sudo cp /usr/src/tensorrt/data/ssd/ssd_coco_labels.txt .

8. Create deepstream_app_config_ssd_inception.txt

sudo nano deepstream_app_config_ssd_inception.txt

Inside deepstream_app_config_ssd_inception.txt

[application]
enable-perf-measurement=1
perf-measurement-interval-sec=1
gie-kitti-output-dir=streamscl

[tiled-display]
enable=0
rows=1
columns=1
width=1280
height=720
gpu-id=0
nvbuf-memory-type=0

[source0]
enable=1
#Type - 1=CameraV4L2 2=URI 3=MultiURI
type=3
num-sources=1
uri=file://../../samples/streams/sample_1080p_h264.mp4
gpu-id=0
cudadec-memtype=0

[streammux]
gpu-id=0
batch-size=1
batched-push-timeout=-1
## Set muxer output width and height
width=1920
height=1080
nvbuf-memory-type=0

[sink0]
enable=1
type=3
sync=1
source-id=0
gpu-id=0
qos=0
nvbuf-memory-type=0
overlay-id=1
container=1 #1=mp4,2=mkv
codec=1 #1=h264,2=h265
output-file=./out_ssd_inception.mp4

[osd]
enable=1
gpu-id=0
border-width=3
text-size=15
text-color=1;1;1;1;
text-bg-color=0.3;0.3;0.3;1
font=Serif
show-clock=0
clock-x-offset=800
clock-y-offset=820
clock-text-size=12
clock-color=1;0;0;0
nvbuf-memory-type=0

[primary-gie]
enable=1
gpu-id=0
batch-size=1
gie-unique-id=1
interval=0
labelfile-path=ssd_coco_labels.txt
config-file=config_infer_ssd_inception.txt
nvbuf-memory-type=0

9. Create config_infer_ssd_inception.txt

sudo nano config_infer_ssd_inception.txt

Inside config_infer_ssd_inception.txt

[property]
gpu-id=0
net-scale-factor=0.0078431372
offsets=127.5;127.5;127.5
model-color-format=0
model-engine-file=sample_ssd_relu6.uff_b1_gpu0_fp32.engine
labelfile-path=ssd_coco_labels.txt
uff-file=sample_ssd_relu6.uff
infer-dims=3;300;300
uff-input-order=0
uff-input-blob-name=Input
batch-size=1
## 0=FP32, 1=INT8, 2=FP16 mode
network-mode=0
num-detected-classes=91
interval=0
gie-unique-id=1
is-classifier=0
output-blob-names=MarkOutput_0
parse-bbox-func-name=NvDsInferParseCustomSSD
custom-lib-path=nvdsinfer_custom_impl_ssd/libnvdsinfer_custom_impl_ssd.so
#scaling-filter=0
#scaling-compute-hw=0

[class-attrs-all]
threshold=0.5
roi-top-offset=0
roi-bottom-offset=0
detected-min-w=0
detected-min-h=0
detected-max-w=0
detected-max-h=0


## Per class configuration
#[class-attrs-2]
#threshold=0.6
#roi-top-offset=20
#roi-bottom-offset=10
#detected-min-w=40
#detected-min-h=40
#detected-max-w=400
#detected-max-h=800

10. Run APP

sudo deepstream-app -c deepstream_app_config_ssd_inception.txt
SSD_INCEPTION_V2

RESULTS
SSD_Inception_V2 was able to display the bounding boxes consistently unlike SSD_MobileNet_V2(Video Below). SSD_Inception_V2 lets the model choose the appropriate kernel size as well, so the model’s data size is larger than MobileNet but has higher consistency.
This was actually my first time to compare performance between models so it was very educating and FUN!

SSD_MOBILENET_V2