sampleUffSSD with custom resolution for ssd_mobilenet_v1

TensorRT Version 7.0:
CUDA Version 10.2:
TensorFlow Version 1.14:

Hello everyone, I’m converting the model as the author of this article did and it works on the ssd_mobilenet_v1_coco_2018_01_28:
https://forums.developer.nvidia.com/t/sampleuffssd-with-custom-ssd-mobilenet-v1-model/70508

I retrained this model for one class and a resolution of 320 * 544 according to this article:
https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10

changed config.py:
import graphsurgeon as gs
import tensorflow as tf

Input = gs.create_node("Input",
    op="Placeholder",
    dtype=tf.float32,
    shape=[1, 3, 320, 544])
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=1,
    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:0": Input,
    "MultipleGridAnchorGenerator/Concatenate": concat_priorbox,
    "MultipleGridAnchorGenerator/Identity": concat_priorbox,
    "concat": concat_box_loc,
    "concat_1": concat_box_conf
}

namespace_remove = {
    "ToFloat",
    "image_tensor:0",
    "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)

and sampleUffSSD.cpp:
> …

	std::vector<samplesCommon::PPM<3, 320, 544>> mPPMs;
	..
	parser->registerInput(mParams.inputTensorNames[0].c_str(), DimsCHW(3,320,544), nvuffparser::UffInputOrder::kNCHW);
	..
	const int imageC = 3;
	const int imageH = 320;
	const int imageW = 544;
	..
	params.outputClsSize = 1;
	..

Conversion to uff is successful, but when I run ./sample_uff_ssd I get this error:

./sample_uff_ssd
&&&& RUNNING TensorRT.sample_uff_ssd # ./sample_uff_ssd
[09/10/2020-19:23:57] [I] Building and running a GPU inference engine for SSD
[09/10/2020-19:23:58] [E] [TRT] Parameter check failed at: ../builder/Layers.h::setAxis::367, condition: axis >= 0
[09/10/2020-19:23:58] [E] [TRT] Concatenate/concat: all concat input tensors must have the same dimensions except on the concatenation axis (0), but dimensions mismatched at input 1 at index 1. Input 0 shape: [2,7668,1], Input 1 shape: [2,4332,1]
[09/10/2020-19:23:58] [E] [TRT] Concatenate/concat: all concat input tensors must have the same dimensions except on the concatenation axis (0), but dimensions mismatched at input 1 at index 1. Input 0 shape: [2,7668,1], Input 1 shape: [2,4332,1]
[09/10/2020-19:23:58] [E] [TRT] Concatenate/concat: all concat input tensors must have the same dimensions except on the concatenation axis (0), but dimensions mismatched at input 1 at index 1. Input 0 shape: [2,7668,1], Input 1 shape: [2,4332,1]
[09/10/2020-19:23:58] [E] [TRT] Concatenate/concat: all concat input tensors must have the same dimensions except on the concatenation axis (0), but dimensions mismatched at input 1 at index 1. Input 0 shape: [2,7668,1], Input 1 shape: [2,4332,1]
[09/10/2020-19:23:58] [E] [TRT] Concatenate/concat: all concat input tensors must have the same dimensions except on the concatenation axis (0), but dimensions mismatched at input 1 at index 1. Input 0 shape: [2,7668,1], Input 1 shape: [2,4332,1]
[09/10/2020-19:23:58] [E] [TRT] UffParser: Parser error: BoxPredictor_0/ClassPredictor/BiasAdd: The input to the Scale Layer is required to have a minimum of 3 dimensions.
&&&& FAILED TensorRT.sample_uff_ssd # ./sample_uff_ssd

origin mobilnet model:
http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_2018_01_28.tar.gz

my trained graph:

I didn’t work with neural networks at the layer level, so it is all very hard for me, can someone tell me what is wrong?

Hi @Aleksandr1988,

UFF Parser has been deprecated from TRT 7 onwards.
We recommend you to try the below conversion flow.
pb << ONNX << TRT Engine.

Thanks!

Thank you for your answer. I researched this direction, and got the same error as the author of this post:

Hi @Aleksandr1988,
I am afraid, TRT currently doesnt support UINT8.

Thanks!