NVIDIA / TensorRT

NVIDIA® TensorRT™ is an SDK for high-performance deep learning inference on NVIDIA GPUs. This repository contains the open source components of TensorRT.
https://developer.nvidia.com/tensorrt
Apache License 2.0
10.78k stars 2.13k forks source link

Assertion `inputs[0].nbDims == 4 && inputs[0].d[1] == mNbClasses * 4' failed. #1418

Closed pra-dan closed 3 years ago

pra-dan commented 3 years ago

Throughout this experiment, I used the GPU-enabled Google Colab ipython notebook with NVIDIA TESLA.

I am trying to optimise my custom Mask-RCNN model (.h5) using TensorRT 8.0.0.3

I successfully converted my custom model (with 4 classes) to Uff.

For running inference, I compile the given sample_uff_maskRCNN by simply altering its config file and replacing

 // Number of classification classes (including background)
-static const int NUM_CLASSES = 1 + 80; // COCO has 80 classes
+static const int NUM_CLASSES = 1 + 3; // COCO has 80 classes

 // COCO Class names
 static const std::vector<std::string> CLASS_NAMES = {
-    "BG",
-    "person",
-    "bicycle",
-    "car",
-    "motorcycle",
-    "airplane",
-    "bus",
-    "train",
-    "truck",
-    "boat",
-    "traffic light",
-    "fire hydrant",
-    "stop sign",
-    "parking meter",
-    "bench",
-    "bird",
-    "cat",
-    "dog",
-    "horse",
-    "sheep",
-    "cow",
-    "elephant",
-    "bear",
-    "zebra",
-    "giraffe",
-    "backpack",
-    "umbrella",
-    "handbag",
-    "tie",
-    "suitcase",
-    "frisbee",
-    "skis",
-    "snowboard",
-    "sports ball",
-    "kite",
-    "baseball bat",
-    "baseball glove",
-    "skateboard",
-    "surfboard",
-    "tennis racket",
-    "bottle",
-    "wine glass",
-    "cup",
-    "fork",
-    "knife",
-    "spoon",
-    "bowl",
-    "banana",
-    "apple",
-    "sandwich",
-    "orange",
-    "broccoli",
-    "carrot",
-    "hot dog",
-    "pizza",
-    "donut",
-    "cake",
-    "chair",
-    "couch",
-    "potted plant",
-    "bed",
-    "dining table",
-    "toilet",
-    "tv",
-    "laptop",
-    "mouse",
-    "remote",
-    "keyboard",
-    "cell phone",
-    "microwave",
-    "oven",
-    "toaster",
-    "sink",
-    "refrigerator",
-    "book",
-    "clock",
-    "vase",
-    "scissors",
-    "teddy bear",
-    "hair drier",
-    "toothbrush",
+    "BG",
+    "rocket",
+    "shuttle",
+    "aliens"
 };

I also replace the sample uff file with mine but with the same name.

On running I get:

&&&& RUNNING TensorRT.sample_maskrcnn [TensorRT v8001] # ./sample_uff_maskRCNN --datadir /content/TensorRT-8.0.0.3/data/faster-rcnn --fp16
[07/30/2021-06:43:29] [I] Building and running a GPU inference engine for Mask RCNN
[07/30/2021-06:43:30] [I] [TRT] [MemUsageChange] Init CUDA: CPU +0, GPU +0, now: CPU 0, GPU 254 (MiB)
sample_uff_maskRCNN: detectionLayerPlugin.cpp:254: void nvinfer1::plugin::DetectionLayer::check_valid_inputs(const Dims*, int): Assertion `inputs[0].nbDims == 4 && inputs[0].d[1] == mNbClasses * 4' failed.

As per the error, the following assertion fails. I can't understand how to debug this.

https://github.com/NVIDIA/TensorRT/blob/c2668947ea9ba4c73eb1182c162101f09ff250fd/plugin/detectionLayerPlugin/detectionLayerPlugin.cpp#L254

pra-dan commented 3 years ago

@ttyio @Tyler-D Can you guys please look into this ? I can dive deeper into this problem but can't debug this. I tried printing inputs[0].nDims using printf() but nothing gets printed on the console.

Tyler-D commented 3 years ago

Did you change the num_classes here ?https://github.com/NVIDIA/TensorRT/blob/master/samples/sampleUffMaskRCNN/converted/config.py#L26 .

You can check your .uff model in txt by setting this parameter to True: https://github.com/NVIDIA/TensorRT/blob/master/samples/sampleUffMaskRCNN/converted/mrcnn_to_trt_single.py#L154

pra-dan commented 3 years ago

Referring to this

You can check your .uff model in txt by setting this parameter to True: https://github.com/NVIDIA/TensorRT/blob/master/samples/sampleUffMaskRCNN/converted/mrcnn_to_trt_single.py#L154

I tried this but didn't see any extra file getting saved, other than the .pbtxt and uff

Tyler-D commented 3 years ago

You can use txt editor to open .pbtxt, and search the DetectionLayer_TRT to check the parameter of this plugin.

I don't know why you cannot print the message in the c++ sample. Maybe you could compile it with debug flag.

pra-dan commented 3 years ago

Thanks for the tip tyler. It worked. I think I was missing changing num_classes in this config.py. I had already changed it in mrcnn/config.py and thought it was enough.

Also, the .pbtxt is helpful and as an alternative to that, I could also use netron to search for the layer. I got the hint about the layer name in the docs for plugins: https://github.com/NVIDIA/TensorRT/plugin/.

Screenshot 2021-09-03 at 1 12 00 PM