UNet Segmentation model conversion to UFF and TensorRT engine - Unsupported operation ResizeNearestNeighbor

Environment

On a Jetson Nano
TensorRT Version: 7.1.3
Python Version (if applicable): 3.6.9
TensorFlow Version (if applicable): 1.15

Description

I trained a U-Net segmentation model with Keras (TensorFlow backend), I then get a frozen graph (.pb). I wanted to make inference with my model on a Jetson Nano, so I try to convert my frozen graph to uff, and then to TensorRT engine.

I got an error saying that the operation _ResizeNearestNeighbor (present in 4 layers of this type : up_sampling2d_4/resize/ResizeNearestNeighbor) is unsupported by the UffParser, as can also confirmed this page.

On Stack Overflow, I found that TensorRT has an API called IResizeLayer which supports “Nearest” interpolation and can thus be used to implement upsampling, with no need of using custom layers/plugins.

I tried this using graphsurgeon, here is the code I used :

dynamic_graph = gs.DynamicGraph(os.path.abspath(os.path.join(DIR_NAME, 'frozen_model_backsub.pb')))
    nodes=[n.name for n in dynamic_graph.as_graph_def().node]
    ns={}
    for node in nodes:
        if "ResizeNearestNeighbor" in node:
            ns[node]=gs.create_plugin_node(name=node,op="IResizeLayer")
    dynamic_graph.collapse_namespaces(ns)

But I still get an error and I don’t know what I am doing wrong :
UffParser: Validator error: up_sampling2d_4/resize/ResizeNearestNeighbor: Unsupported operation _IResizeLayer

Any help would be very appreciated.
Thanks.
Camille

Hi @camille,
UFF Parser has been deprecated from TRT 7 onwards, hence we recommend you to try the below approach
pb << ONNX << TRT.

Thanks!

Thank you for your quick response.
I installed onnx-tensorrt but when trying to convert my model, I got the following error :

----------------------------------------------------------------
Input filename:   unet_backsub.onnx
ONNX IR version:  0.0.7
Opset version:    12
Producer name:    keras2onnx
Producer version: 1.7.0
Domain:           onnxmltools
Model version:    0
Doc string:       
----------------------------------------------------------------
WARNING: ONNX model has a newer ir_version (0.0.7) than this parser was built against (0.0.6).
Parsing model
Building TensorRT engine, FP16 available:1
    Max batch size:     32
    Max workspace size: 1024 MiB
[2020-10-15 10:14:57   ERROR] Network has dynamic or shape inputs, but no optimization profile has been defined.
[2020-10-15 10:14:57   ERROR] Network validation failed.
terminate called after throwing an instance of 'std::runtime_error'
  what():  Failed to create object
Aborted (core dumped)

Is there a way to solve this ?

I’ve seen this page : https://github.com/NVIDIA/TensorRT/tree/master/samples/opensource/sampleDynamicReshape#tensorrt-api-layers-and-ops
but I don’t understand what I have to modify or add.
I use the command line to launch the conversion.

Hi @camille,
Can you please share your onnx model?

Thanks!

Hi,
I solved my problem using trtexec
Thank you for your help.
Have a good day