-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add NMS with Tensorflow Model (that was converted to ONNX) #1379
Comments
@pranavm-nvidia can you help me out with this |
@letdivedeep It doesn't look like |
@pranavm-nvidia Thanks for your reply. This may be a very nerd question Attaching the tflite->onnx model for references |
@letdivedeep The goal of the script is to replace a group of nodes in the original graph with a This is not required in TRT 8, which supports the ONNX NMS op out-of-the-box, so your tflite model should work without any modifications. |
@pranavm-nvidia thanks for the clarification The Nvidia jetpack SDK still officially supports TensorRT 7.1.3 : https://developer.nvidia.com/embedded/jetpack Any Idea on when we going to get an upgrade to 8.0 of jetpack SDK? |
it says that "it has the limitation that the output shape is always padded to length" please can you clarify on this, what post processing is required. Have you got an example somewhere please. |
I'm not sure, sorry |
Can you clarify what you mean by "it"? If you mean the NMS plugin, the output shape is determined by some of the plugin parameters. |
@pranavm-nvidia Thanks for your reply and i really appreciate your efforts. I want to use tensorRT 7.1 itself, thus need to replace those NMS layers for it to work I am very new to this tensorRT part , I am still not clear about the names. I have taken the above shared tflite to onnx converted model as an references and attached an screen shot Now as i want to replace the NonMaxSuppression node it has two inputs (Transpose__656:0,Concat__652:0) and two outputs (Slice__661:0,Slice__669:0)
Your Inputs will be of great help |
@letdivedeep One issue with that is that the behavior of the BatchedNMS plugin is different from ONNX NMS (e.g. different outputs), so it won't work as a drop-in replacement here. So I'd recommend starting off by reading about the outputs of the plugin and then determining how those should map to the tensors in the model (I'm guessing you'll probably just want to connect the NMS directly to the model outputs). Once you know the tensor names, it's just a matter of looking them up in the tensor map ( graph.trt_batched_nms(tmap["Transpose__656"], tmap[["Concat__652"], ...) Also keep in mind that the BatchedNMS plugin has 4 outputs (not just 1), so you'll probably want to change return self.layer(op="BatchedNMS_TRT", attrs=attrs,
inputs=[boxes_input, scores_input],
outputs=[nms_output]) you could do: return self.layer(op="BatchedNMS_TRT", attrs=attrs,
inputs=[boxes_input, scores_input],
outputs=outputs) # Outputs is a List[Tensor] |
Hello, Please what am I doing wrong. Help me please. My tensorrt conversion keeps failing with this error. WARNING: ONNX model has a newer ir_version (0.0.7) than this parser was built against (0.0.6). — End node — I have used onnx-simplifier yet it the error persists. I have also used polygraphy surgeon all to no avail. |
@pranavm-nvidia thanks for the detailed explanation this helped me understand and debug better I followed certain steps : 1) Get the output node names prior to NMS from frozen graph :
2) Clear the output of this two nodes and use this as inputs to the BatchedNMSDynamic_TRT node. 3) Clear the inputs to the output nodes (["TFLite_Detection_PostProcess", "TFLite_Detection_PostProcess:1", "TFLite_Detection_PostProcess:2","TFLite_Detection_PostProcess:3"]) and add this as output of BatchedNMSDynamic_TRT node.
the other nodes which were earlier there is the graph which contributed to the NMS output part were removed Am i on the right direction or need to do something more |
@letdivedeep Yes, that seems right to me. Were you able to try running it? |
@pranavm-nvidia ... No i am getting this error
using tensorrt version 7.1.3 |
What does your code look like? Are you calling |
@pranavm-nvidia .. No i am not calling initLibNvInferPlugins()? I have generated new model with BatchedNMS_TRT, as tensorRT v7.1 does not support BatchedNMSDynamic_TRT this is my code base
|
What does your TRT code look like? i.e. how are you building the engine? |
I am trying to convert the onnx model to .trt using the trtexec on docker with tensort 7.2.3.4 : Getting the following error :
I Tried various approaches
But all this lead to the same above error, @pranavm-nvidia can you help me figure out what's going wrong I have attached all the three onnx model {BatchedNMS_TRT, BatchedNMSDynamic_TRT, without_Squeeze and polygraphy} |
@letdivedeep Can you check if the exported ONNX model (prior to adding the BatchedNMS node) works with ONNX-Runtime? You can use Polygraphy to try it out:
I'm wondering if it could be a bug in |
sure will try this out |
Moreover i have converted to onnx using the tflite model |
And if you run that original ONNX model with TRT, does it still fail in the same place? The error you posted seems to be happening well before the NMS, so I'm guessing the problem is probably not with your node replacement script. |
@pranavm-nvidia Ya Agree If i try to run the original ONNX model with TRT i get this error :
the Above error suggests that the NMS op is not supported ... thus I added the BatchedNMS node using the following script
cant figure out whats going wrong |
Hi @pranavm-nvidia, i was able to resolve the above error by commenting these lines in the above code, which deal with change in the dtype
logs from polygraphy for this model where there is a warning for " Unsupported operator BatchedNMS_TRT. No schema registered for this operator."
And when trying to convert to .trt with the trtexec command i get this error
the detailed logs is available here I even tried with using an lower of opset 11 as suggested in this issue still the same error. @pranavm-nvidia can you guide me on this |
@letdivedeep The plugin accepts various attributes, which you'd need to populate in attrs = {
"shareLocation": share_location,
"numClasses": num_classes,
# etc.
} Note: The plugin attributes should be
|
@pranavm-nvidia thanks for the reply I even added this set of attribute
after that once i run the trtexec cmd i get the following error
|
I think you also need to set ...
"clipBoxes": True,
"scoreBits": 16,
} |
@pranavm-nvidia thanks for the quick reply ...
|
Can you try using the |
cool will try that and let you know |
An different error related to output_trt_dtype
|
You could probably work around this by setting the output data types in your script: for out in graph.outputs:
out.dtype = np.float32 |
I have added the above part but it gives the same error. I think its while converting to .trt its cast down to int32
|
Would you be able to share the model? |
Ah I got the error backwards - it expects the first output to be int32, but it's float in the model. graph.outputs[0].dtype = np.int32 fixes that, but now I'm seeing:
I think the reason is that the model is only producing boxes for a single class ( |
@pranavm-nvidia .. thanks for the debug .. I really appreciated your help. when I changed numClasses to 1. It successfully converted to .trt file But I am still confused about why this is happening. My model has 8 classes I even tried with the ssdlite mobilenetV2model from the tfod 1.x model zoo model Generate an tflite out from it, see the graph its with 90 coco classes : converted to onnx tf2onnx converter : And later used the same code to add
Ideally, in tflite it was the NMS layer that is to handle this part, don't know if I am wrong on this But still i will try to run the file and let you know @pranavm-nvidia Once again @pranavm-nvidia thanks for your help |
I think you'd have to set |
Maybe ... let me try to infer over few images and check whats the output |
What I found was the output we get from the model is not actual bbox coordinates, it is just anchor boxes which are 1917 in the count. Ideally, the Tensorflow NMS operator handles this part internally. While in ONNX, I think the batchedNMS plugin needs the bbox coordinates as an input info This is what is causing the issue |
I have raised an support ticket on the Nvidia forum: https://forums.developer.nvidia.com/t/adding-batchednmsdynamic-trt-plugin-in-the-ssd-mobilenet-onnx-model/185874 But have received no reply yet. |
@letdivedeep Maybe you could try with TRT 8 since it's available in JP now? https://developer.nvidia.com/embedded/jetpack As I mentioned before, TRT 8 should be able to import the ONNX NMS node, so you won't need to replace it with the |
@pranavm-nvidia thanks for the update and make sense |
I have taken an ssdlite mobile net v2 model from the tensorflow model zoo
steps :
generated the onnx model using the tf2onnx lib
python -m tf2onnx.convert --graphdef mv2/ssdlite_mobilenet_v2_coco_2018_05_09/frozen_inference_graph.pb --output MODEL_frozen.onnx \ --fold_const --opset 11 \ --inputs image_tensor:0 \ --outputs num_detections:0,detection_boxes:0,detection_scores:0,detection_classes:0
add the nms layers in the onnx model based on refferences from this issue
I am not able to figure it out in the onnx graph which nodes i should repalce in place of "Postprocessor/BatchMultiClassNonMaxSuppression/MultiClassNonMaxSuppression/non_max_suppression_with_scores_2/NonMaxSuppressionV5__1712:0" and other
MODEL_frozen.onnx.zip
I have also attach the onnx file. Any sugeestions how to find it ?
The text was updated successfully, but these errors were encountered: