Error parsing UFF model "Unsupported operation _LeakyRelu"

Hello, I’m trying to convert my tensorflow model to tensorrt by using scripts from https://github.com/NVIDIA-AI-IOT/tf_to_trt_image_classification , but facing issue, because my graph contains LeakyRelu operation.

I’ve attempted to modify uff_to_plan.cpp (patch below), but w/o success. In general, i want to understand how i can add LeakyRelu support?

diff --git a/src/uff_to_plan.cpp b/src/uff_to_plan.cpp
index ab2b395..b3db8ea 100644
--- a/src/uff_to_plan.cpp
+++ b/src/uff_to_plan.cpp
@@ -10,6 +10,7 @@
 
 #include <NvInfer.h>
 #include <NvUffParser.h>
+#include <NvInferPlugin.h>
 
 
 using namespace std;
@@ -65,11 +66,17 @@ int main(int argc, char *argv[])
   DataType dataType = toDataType(argv[9]);
 
   /* parse uff */
+  bool ok = initLibNvInferPlugins(&gLogger, "");
   IBuilder *builder = createInferBuilder(gLogger);
   INetworkDefinition *network = builder->createNetwork();
   IUffParser *parser = createUffParser();
-  parser->registerInput(inputName.c_str(), DimsCHW(3, inputHeight, inputWidth));
+  IPluginV2 *lrelu = createLReLUPlugin(0.1);
+  lrelu->setPluginNamespace("");
+  parser->registerInput(inputName.c_str(), DimsCHW(3, inputHeight, inputWidth), UffInputOrder::kNCHW);
   parser->registerOutput(outputName.c_str());
+  parser->registerOutput("orientation/l2_normalize");
+  parser->registerOutput("confidence/Softmax");
+  parser->setPluginNamespace("");
   if (!parser->parse(uffFilename.c_str(), *network, dataType))
   {
     cout << "Failed to parse UFF\n";
@@ -79,6 +86,7 @@ int main(int argc, char *argv[])
     return 1;
   }
 
+

https://gist.github.com/r7vme/ee90289a593a856303b3718d42686936 output from command.

configuration:

Small update. I was able to use LeakyRelu plugin.

  1. For that i need to add collapse_namespaces operation in graphsurgeon
+    dynamic_graph = gs.DynamicGraph(frozen_graph_filename)
+    dynamic_graph.collapse_namespaces(
+        {
+            "input_1": gs.create_plugin_node(name="input_1", op="Placeholder", dtype=tf.float32, shape=[1,3,224,224]),
+            "leaky_re_lu_1/LeakyRelu": gs.create_plugin_node(name="trt_lrelu1", op="LReLU_TRT", negSlope=0.1),
+            "leaky_re_lu_2/LeakyRelu": gs.create_plugin_node(name="trt_lrelu2", op="LReLU_TRT", negSlope=0.1),
+            "leaky_re_lu_3/LeakyRelu": gs.create_plugin_node(name="trt_lrelu3", op="LReLU_TRT", negSlope=0.1),
+            "leaky_re_lu_4/LeakyRelu": gs.create_plugin_node(name="trt_lrelu4", op="LReLU_TRT", negSlope=0.1),
+            "dimension/LeakyRelu": gs.create_plugin_node(name="dimension/LeakyRelu", op="LReLU_TRT", negSlope=0.1)
+        }
+    )
  1. And in uff_to_plan.cpp only require these lines
+#include <NvInferPlugin.h>
...
+  bool ok = initLibNvInferPlugins(&gLogger, "");
+  if (!ok) { return 1; }

Now i’m debugging new error

UFFParser: Parser error: reshape_1/Reshape: Reshape: -1 dimension specified more than 1 time

So far the network that i’m trying to convert defined https://github.com/cersar/3D_detection/blob/master/net/bbox_3D_net.py

More updates. Reshape problem was solved by defining exact shape in model definition

-    orientation = Reshape((bin_num, -1))(orientation)
+    orientation = Reshape((bin_num, 2))(orientation)

Now seems quite last thing

UFFParser: parsing orientation/l2_normalize/Maximum
UFFParser: Parser error: orientation/l2_normalize/Maximum: Unsupported binary op max with constant right
Failed to parse UFF

Just for info. Seems last issue that i was not able to resolve with l2_normalize same as in other thread (still not solved). Closing this thread in favor

[url]https://devtalk.nvidia.com/default/topic/1030077/tensorrt/seeing-quot-unsupported-binary-op-max-with-constant-right-quot-when-converting-tensorflow-graph-to-tensorrt-engine-/post/5348901/#5348901[/url]

1 Like

Please see final solution with custom plugin here.