I can generate a TensorRT engine with the .pb file you shared without error.
Would you mind to use the this GitHub and also the patch shared in #19 first?
[url]https://github.com/AastaNV/TRT_object_detection[/url]
CAST is an operation for converting data type.
In general, you don’t need to write a plugin for it.
It should be supported by TensorRT automatically.
Fine-tuned on 1 class (200K epochs) using Tensorflow’s object-detection API (latest git version).
Exported my final training checkpoint using Tensorflow’s “export_inference_graphp.py” (passing input_shape=1,-1,-1,3 as an arg to “export_inference_graph.py”)
Built “libflattenconcat.so” in /usr/src/tensorrt/samples/python/uff_ssd/build and pointed the ctypes.CDLL() in your main.py to this file:
Made the changes you have been recommending in #19
Changed “node_manipulation.py” as recommended
When I run main.py from your GitHub I get the following error:
[TensorRT] ERROR: Could not register plugin creator: FlattenConcat_TRT in namespace:
WARNING:tensorflow:From /usr/lib/python3.6/dist-packages/graphsurgeon/StaticGraph.py:125: The name tf.gfile.GFile is deprecated. Please use tf.io.gfile.GFile instead.
WARNING: To create TensorRT plugin nodes, please use the `create_plugin_node` function instead.
UFF Version 0.6.5
=== Automatically deduced input nodes ===
[name: "Input"
op: "Placeholder"
input: "Cast"
attr {
key: "dtype"
value {
type: DT_FLOAT
}
}
attr {
key: "shape"
value {
shape {
dim {
size: 1
}
dim {
size: 3
}
dim {
size: 300
}
dim {
size: 300
}
}
}
}
]
=========================================
Using output node NMS
Converting to UFF graph
Warning: No conversion function registered for layer: NMS_TRT yet.
Converting NMS as custom op: NMS_TRT
WARNING:tensorflow:From /usr/lib/python3.6/dist-packages/uff/converters/tensorflow/converter.py:179: The name tf.AttrValue is deprecated. Please use tf.compat.v1.AttrValue instead.
Warning: No conversion function registered for layer: FlattenConcat_TRT yet.
Converting concat_box_conf as custom op: FlattenConcat_TRT
Warning: No conversion function registered for layer: Cast yet.
Converting Cast as custom op: Cast
Warning: No conversion function registered for layer: FlattenConcat_TRT yet.
Converting concat_box_loc as custom op: FlattenConcat_TRT
Warning: No conversion function registered for layer: GridAnchor_TRT yet.
Converting GridAnchor as custom op: GridAnchor_TRT
DEBUG [/usr/lib/python3.6/dist-packages/uff/converters/tensorflow/converter.py:96] Marking ['NMS'] as outputs
No. nodes: 554
UFF Output written to tmp.uff
[TensorRT] ERROR: UffParser: Validator error: Cast: Unsupported operation _Cast
[TensorRT] ERROR: Network must have at least one output
Traceback (most recent call last):
File "main.py", line 45, in <module>
buf = engine.serialize()
AttributeError: 'NoneType' object has no attribute 'serialize'
and the error comes here as
Begin parsing model…
testssd: /home/nvidia/Desktop/ssd_trt/testssd.cpp:260: (line 8 in the above example ) FlattenConcat::FlattenConcat(int, bool): Assertion `mConcatAxisID == 1 || mConcatAxisID == 2 || mConcatAxisID == 3’ failed.
Aborted (core dumped)
Also, I have a trained a custom model of ssd_inception_v2_coco_2018_01_28 and the config file is not working even with python github repository shared by you !
if the input order is [0,2,1], then the error I get is:
python3: nmsPlugin.cpp:136: virtual void nvinfer1::plugin::DetectionOutput::configureWithFormat(const nvinfer1::Dims*, int, const nvinfer1::Dims*, int, nvinfer1::DataType, nvinfer1::PluginFormat, int): Assertion `numPriors * param.numClasses == inputDims[param.inputOrder[1]].d[0]’ failed.
Aborted (core dumped)
if the input order is [0,2,1]:
python3: 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)
Hello AastaLLL,
Last week, I update my Object detection API and I retrained the ssd with the same object and same model (ssd_inception_v2_coco_2017_11_17) and used python for inferece. Now I am getting the same error as pushkar.chatterji in the comments. I tried using all the config files from the config folder and modified them but same result.
I was able to get rid of the cast operation error by adding the line in the config file :
but after adding these line, i get the error:
…
…
[TensorRT] INFO: UFFParser: parsing BoxPredictor_0/BoxEncodingPredictor/weights
[TensorRT] INFO: UFFParser: parsing BoxPredictor_0/BoxEncodingPredictor/Conv2D
[TensorRT] INFO: UFFParser: parsing BoxPredictor_0/BoxEncodingPredictor/biases
[TensorRT] INFO: UFFParser: parsing BoxPredictor_0/BoxEncodingPredictor/BiasAdd
[TensorRT] INFO: UFFParser: parsing BoxPredictor_0/Shape
[TensorRT] INFO: UFFParser: parsing BoxPredictor_0/strided_slice/stack
[TensorRT] INFO: UFFParser: parsing BoxPredictor_0/strided_slice/stack_1
[TensorRT] INFO: UFFParser: parsing BoxPredictor_0/strided_slice/stack_2
[TensorRT] INFO: UFFParser: parsing BoxPredictor_0/strided_slice
[TensorRT] INFO: UFFParser: parsing BoxPredictor_0/Reshape/shape/1
[TensorRT] INFO: UFFParser: parsing BoxPredictor_0/Reshape/shape/2
[TensorRT] INFO: UFFParser: parsing BoxPredictor_0/Reshape/shape/3
[TensorRT] INFO: UFFParser: parsing BoxPredictor_0/Reshape/shape
[TensorRT] INFO: UFFParser: parsing BoxPredictor_0/Reshape
[TensorRT] ERROR: UFFParser: Parser error: BoxPredictor_0/Reshape: Reshape: -1 dimension specified more than 1 time
[TensorRT] ERROR: Network must have at least one output
Traceback (most recent call last):
File “main.py”, line 44, in
buf = engine.serialize()
AttributeError: ‘NoneType’ object has no attribute ‘serialize’
Could you help me, what is happening ???
I did make the changes suggested by you in the comment 19, and they work with model I shared with you ( trained with old object detection model and old tensorflow version), now after updating the Object detection API and TensorFlow version 1.14.0. the trained models is throwing the above error.
I think I was able to solve the problem. The steps I followed :
Trained a custom ssd models using the latest TensorFlow object Detection API and tensorflow version 1.14.0
On another PC, I had another Tensorflow Object Detection API from early 2018, I used this to export my model from step 1 to frozen_graph. IMPORTANT : Before exporting into frozen graph, remove the below line from the pipeline.config file
override_base_feature_extractor_hyperparams: true
After removing the line, export it into frozen_graph.
I used the config file shared by AastaLLLL to get the uff file and used it to create the engine and perform inference.
Resutls:
Network trained on 1 custom object.
The fps is counted as : Batch_size/ difference between time at which an image is given input to the network and the time at which the network outputs the prediction. It does not in consider the time to display the image with prediction.
With frames shown : Batch_size/ difference between time at which an image is given input to the network and the time at which a frame is displayed with the prediction.
I have same as sandeepkumarjangir0 when I convert my custom ssd-mobilenet-v1-fpn model:
env:
tensorlfow: 1.14.0
tensorRT: 6.0.1.5
google OD API: latest
cuda:10.0
error info as:
DEBUG [/usr/local/lib/python3.6/dist-packages/uff/converters/tensorflow/converter.py:96] Marking [‘NMS’] as outputs
No. nodes: 998
UFF Output written to /media/york/F/GitHub/tensorflow/train_model/ssd_mobilenet_v1_fpn_shared_trafficlight/export_train_bdd100k_baidu_truck_zl004_class4_wh640640_depth1.0_level35_num1_focal_trainval299287_step320000_640640_320000/frozen_inference_graph.uff
UFF Text Output written to /media/york/F/GitHub/tensorflow/train_model/ssd_mobilenet_v1_fpn_shared_trafficlight/export_train_bdd100k_baidu_truck_zl004_class4_wh640640_depth1.0_level35_num1_focal_trainval299287_step320000_640640_320000/frozen_inference_graph.pbtxt
[TensorRT] ERROR: Could not register plugin creator: FlattenConcat_TRT in namespace:
TensorRT inference engine settings:
Inference precision - DataType.FLOAT
Max batch size - 1
[TensorRT] ERROR: UffParser: Validator error: MultiscaleGridAnchorGenerator/ToNormalizedCoordinates_2/Cast_1: Unsupported operation _Cast
[TensorRT] ERROR: Network must have at least one output
Building TensorRT engine. This may take few minutes.
Traceback (most recent call last):
File “/media/york/F/GitHub/tensorflow/models/research/uff_ssd-TensorRT-6.0.1.5/detect_objects_trafficlight.py”, line 250, in
main()
File “/media/york/F/GitHub/tensorflow/models/research/uff_ssd-TensorRT-6.0.1.5/detect_objects_trafficlight.py”, line 224, in main
batch_size=args.max_batch_size)
File “/media/york/F/GitHub/tensorflow/models/research/uff_ssd-TensorRT-6.0.1.5/utils/inference.py”, line 117, in init
engine_utils.save_engine(self.trt_engine, trt_engine_path)
File “/media/york/F/GitHub/tensorflow/models/research/uff_ssd-TensorRT-6.0.1.5/utils/engine.py”, line 132, in save_engine
buf = engine.serialize()
AttributeError: ‘NoneType’ object has no attribute ‘serialize’
Process finished with exit code 1
May someone help me???
problem:
1 FlattenConcat_TRT
2 Cast
why have to use old google od api to export .pb file??? my custom model is ssd-mobilenet-v1-fpn about traffic_lgiht recognization
May be you are using the latest version of TensorFlow object detection API. It also gave me error when I used version a version from mid 2018 onward. As I mentioned previously , I used Tensorflow Object Detection API from early 2018 to convert the checkpoints into frozen graph. I will try to upload the version that I used to convert the frozen graph on this thread.
Hello @sandeepkumarjangir07,
Could you please provide the versiosn that you used : Iwould like to use correct the tensorflow version and Tensorlfow object detection api version to train ssd inception v2 model and run inference using sampleUffSSD in tensorRT on jetson nano.