Ubuntu 18.04
CUDA 10.0.117
CUDNN 7.3.1.20
Python 3.6
Tensorflow 1.12.0+nv19.1 (official from https://developer.download.nvidia.com/compute/redist/jp/v411)
TensorRT 5.0.3.2
Jetson AGX Xavier, L4T R31.1
Hi.
I was able to convert ssd_mobilenet_v1_coco_2018_01_28 model to UFF and run it with sampleUffSSD using the next config.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,
scoreConverter="SIGMOID")
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,
"concat": concat_box_loc,
"concat_1": concat_box_conf
}
namespace_remove = {
"ToFloat",
"image_tensor",
"Preprocessor/map/TensorArrayStack_1/TensorArrayGatherV3"
}
def preprocess(dynamic_graph):
# remove the unrelated or error layers
dynamic_graph.remove(dynamic_graph.find_nodes_by_path(namespace_remove), remove_exclusive_dependencies=False)
# 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)
# Remove the Squeeze to avoid "Assertion `isPlugin(layerName)' failed"
Squeeze = dynamic_graph.find_node_inputs_by_name(dynamic_graph.graph_outputs[0], 'Squeeze')
dynamic_graph.forward_inputs(Squeeze)
But was unable to do the same for my custom ssd_mobilenet_v1 model fine-tuned on top of ssd_mobilenet_v1_coco_2017_11_17 for my own 4 classes. Config.py used was
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=5,
inputOrder=[2, 0, 1],
confSigmoid=1,
isNormalized=1,
scoreConverter="SIGMOID")
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,
"Concatenate": concat_priorbox,
"concat_1": concat_box_loc,
"concat": concat_box_conf
}
namespace_remove = {
"ToFloat",
"image_tensor",
"Preprocessor/map/TensorArrayStack_1/TensorArrayGatherV3",
"Preprocessor/stack_1",
"Preprocessor/ResizeImage/stack_1"
}
def preprocess(dynamic_graph):
# remove the unrelated or error layers
dynamic_graph.remove(dynamic_graph.find_nodes_by_path(namespace_remove), remove_exclusive_dependencies=False)
# 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)
# Remove the Squeeze to avoid "Assertion `isPlugin(layerName)' failed"
Squeeze = dynamic_graph.find_node_inputs_by_name(dynamic_graph.graph_outputs[0], 'Squeeze')
dynamic_graph.forward_inputs(Squeeze)
Here I changed
numClasses=5 (have 4 custom classes)
inputOrder=[2, 1, 0] (input nodes to NMS are ['concat_priorbox', 'concat_box_conf', 'concat_box_loc'])
Number of classes in sampleUffSSD was modified accordingly.
"concat": concat_box_loc,
"concat_1": concat_box_conf
was changed to
"concat_1": concat_box_loc,
"concat": concat_box_conf
because of different node names.
According to https://devtalk.nvidia.com/default/topic/1037412/tensorrt/sampleuffssd-with-newer-tensorflow-models-2018-/post/5295479/
I decreased the number of inputs from 4 to 3 by adding
"Preprocessor/stack_1",
"Preprocessor/ResizeImage/stack_1"
to namespace_remove.
Also changed
"MultipleGridAnchorGenerator/Concatenate": concat_priorbox,
to
"Concatenate": concat_priorbox,
because of different node names.
But sampleUffSSD returns with error
Begin parsing model...
End parsing model...
Begin building engine...
sample_uff_ssd: nmsPlugin.cpp:135: virtual void nvinfer1::plugin::DetectionOutput::configureWithFormat(const nvinfer1::Dims*, int, const nvinfer1::Dims*, int, nvinfer1::DataType, nvinfer1::PluginFormat, int): Assertion `numPriors * numLocClasses * 4 == inputDims[param.inputOrder[0]].d[0]' failed.
Aborted (core dumped)
Any ideas on what else should be modified?
Corresponding files can be found here:
pb - https://drive.google.com/open?id=1sq_fkR3Zi4NNuTMZSTdnwDTCP0ikVdK7,
uff - https://drive.google.com/open?id=1y8ndKp-m8t6wXhvNW9kq_quofDrXUvDR,
pbtxt - https://drive.google.com/file/d/1BuT074bc6Mdxy7xRo9WEF_9WIcU51s1f