Unable to visualize and extract masks when using Mask-RCNN with default Deepstream App

Hi All,

I am currently trying to draw masks in addition to the bounding boxes using the Mask-RCNN custom app given here: https://github.com/NVIDIA-AI-IOT/deepstream_4.x_apps/tree/master/nvdsinfer_customparser_mrcnn_uff and the default Deepstream App. However the default application does not support visualizing the masks or extracting the mask data with the default metadata output. I am able to dump the masks separately using the nvdsinfer_custombboxparser_mrcnn_uff.cpp to text files but not with the default Deepstream app.

Is there any way we can modify the existing deepstream app to draw the masks on the output videos and get the masks as part of the deepstream metadata?

Hi,

Currently, our NvOSD can support bounding boxes, texts, and polygons.
Do you think if you can convert the mask into several tiny bounding box or polygons for drawing?
https://docs.nvidia.com/metropolis/deepstream/plugin-manual/index.html#page/DeepStream_Plugin_Manual%2Fdeepstream_plugin_details.02.06.html%23wwpID0E0AR0HA

Thanks.

Hi,

I can potentially use polygons to drawing. However, the major issue currently faced by us is how do we pass on the mask data to the deepstream application?

One potential way of solving this could be by modifying the following function in the file nvdsinfer_custombboxparser_mrcnn_uff.cpp (I’ve removed some code intentionally here for better readability) :

extern "C"
bool NvDsInferParseCustomMrcnnUff (std::vector<NvDsInferLayerInfo> const &outputLayersInfo,
                                   NvDsInferNetworkInfo  const &networkInfo,
                                   NvDsInferParseDetectionParams const &detectionParams,
                                   std::vector<NvDsInferObjectDetectionInfo> &objectList) {

    float* out_det = (float *) outputLayersInfo[detIndex].buffer;
    float* out_mask = (float *) outputLayersInfo[maskIndex].buffer;

    std::vector<MRCNNBBoxInfo> binfo = decodeOutput(out_det, out_mask);
    for (unsigned int roi_id = 0; roi_id < binfo.size(); roi_id++) {


        <b>NvDsInferObjectDetectionInfo object;</b>

        object.classId = binfo[roi_id].label;
        object.detectionConfidence = binfo[roi_id].prob;

        /* Clip object box co-ordinates to network resolution */
        object.left = CLIP(binfo[roi_id].box.x1 * networkInfo.width, 0, networkInfo.width - 1);
        object.top = CLIP(binfo[roi_id].box.y1 * networkInfo.height, 0, networkInfo.height - 1);
        object.width = CLIP((binfo[roi_id].box.x2 - binfo[roi_id].box.x1) * networkInfo.width, 0, networkInfo.width - 1);
        object.height = CLIP((binfo[roi_id].box.y2 - binfo[roi_id].box.y1) * networkInfo.height, 0, networkInfo.height - 1);

        objectList.push_back(object);

    }

    return true;
}

In line 14 above we are making an object of type NvDsInferObjectDetectionInfo which is then pushed into objectList, I’m assuming this vector is then passed on to the main deepstream app. Would it be possible to modify. the struct NvDsInferObjectDetectionInfo in nvdsinfer.h and add in another variable e.g. an array or a vector?

typedef struct
{
  /** ID of the class to which the object belongs. */
  unsigned int classId;

  /** Horizontal offset of the bounding box shape for the object. */
  unsigned int left;
  /** Vertical offset of the bounding box shape for the object. */
  unsigned int top;
  /** Width of the bounding box shape for the object. */
  unsigned int width;
  /** Height of the bounding box shape for the object. */
  unsigned int height;
  /** Object detection confidence. Should be a float value in the range [0,1] */
  float detectionConfidence;
} NvDsInferObjectDetectionInfo;

I did adding an extra integer variable in this struct but I ran into issues. The code compiles fine but when I run the deepstream app I end up getting an Segmentation Fault. Any leads as to why changing the struct leads to this error?

Or maybe there is another approach we could use to get the masks to the main deepstream app in addition to the bounding box coordinates, classIds etc.

Hi,

We are trying to reproduce the the segmentation fault issue.
Will update more information with you later.

Hi,

We can update the structure of nvinfer without issue.
Have you run ‘make install’ after updating the structure?

There is another plugin may help you to visualize the mask called nvsegvisual.
You can find the detail for this component here:
https://docs.nvidia.com/metropolis/deepstream/plugin-manual/index.html#page/DeepStream_Plugin_Manual%2Fdeepstream_plugin_details.02.11.html

Thanks.

Hi thanks for the reply I was able to make changes to the structs using your answer. Thanks for the reply!

Hi, I’m also getting the ‘segmentation fault’. How did you resolve this?

You’ll make to run “make” followed by “make install” in the following directories:

  • ~/deepstream_sdk_v4.0.2_x86_64/sources/gst-plugins/gst-nvinfer
  • ~/deepstream_sdk_v4.0.2_x86_64/sources/libs/nvdsinfer/
1 Like

Thank you very much!