Table Of Contents
This sample, sampleUffMaskRCNN, performs inference on the Mask R-CNN network in TensorRT. Mask R-CNN is based on the Mask R-CNN paper which performs the task of object detection and object mask predictions on a target image. This sample’s model is based on the Keras implementation of Mask R-CNN and its training framework can be found in the Mask R-CNN Github repository. We have verified that the pre-trained Keras model (with backbone ResNet101 + FPN and dataset coco) provided in the v2.0 release can be converted to UFF and consumed by this sample. And, it is also feasible to deploy your customized Mask R-CNN model trained with specific backbone and datasets.
This sample makes use of TensorRT plugins to run the Mask R-CNN model. To use these plugins, the Keras model should be converted to Tensorflow .pb
model. Then this .pb
model needs to be preprocessed and converted to the UFF model with the help of GraphSurgeon and the UFF utility.
The main components of this network are the ResizeNearest
, ProposalLayer
, PyramidROIAlign
, DetectionLayer
and SpecialSlice
.
ResizeNearest
- Nearest neighbor interpolation for resizing features. This works for the FPN (Feature Pyramid Network) module.ProposalLayer
- Generate the first stage's proposals based on anchors and RPN's (Region Proposal Network) outputs (scores, bbox_deltas).PyramidROIAlign
- Crop and resize the feature of ROIs (first stage's proposals) from the corresponding feature layer.DetectionLayer
- Refine the first stage's proposals to produce final detections.SpecialSlice
- A workaround plugin to slice detection output [y1, x1, y2, x2, class_id, score] to [y1, x1, y2 , x2] for data with more than one index dimensions (batch_idx, proposal_idx, detections(y1, x1, y2, x2)).In this sample, the following layers are used. For more information about these layers, see the TensorRT Developer Guide: Layers documentation.
Activation layer The Activation layer implements element-wise activation functions. Specifically, this sample uses the Activation layer with the type kRELU
.
Convolution layer The Convolution layer computes a 2D (channel, height, and width) convolution, with or without bias.
Deconvolution layer The IDeconvolutionLayer computes a 2D (channel, height, and width) deconvolution, with or without bias.
Padding layer The IPaddingLayer implements spatial zero-padding of tensors along the two innermost dimensions.
Plugin layer Plugin layers are user-defined and provide the ability to extend the functionalities of TensorRT. See Extending TensorRT With Custom Layers for more details.
Pooling layer The Pooling layer implements pooling within a channel. Supported pooling types are maximum
, average
and maximum-average blend
.
We use the Tensorflow 19.10-py3 container for generating the UFF model for MaskRCNN.
conv2d_transpose
conversion function in UFF, for example /usr/lib/python3.6/dist-packages/uff/converters/tensorflow/converter_functions.py
. ```bash uff_graph.conv_transpose( inputs[0], inputs[2], inputs[1], strides, padding, dilation=None, number_groups=number_groups, left_format=lhs_fmt, right_format=rhs_fmt, name=name, fields=fields ) ```PYTHONPATH
. ```bash git clone https://github.com/matterport/Mask_RCNN.git export PYTHONPATH=$PYTHONPATH:$PWD/Mask_RCNN ```Download the pre-trained Keras model ```bash wget https://github.com/matterport/Mask_RCNN/releases/download/v2.0/mask_rcnn_coco.h5 ```
Note: The md5sum of model file is e98aaff6f99e307b5e2a8a3ff741a518.
/data
folder with the following test images. ``` /usr/src/tensorrt/data/faster-rcnn/001763.ppm /usr/src/tensorrt/data/faster-rcnn/004545.ppm ```Switch back to the TensorRT container/environment for running the sample.
Compile this sample by running make
in the <TensorRT root directory>/samples/sampleUffMaskRCNN
directory. The binary named sample_uff_mask_rcnn
will be created in the <TensorRT root directory>/bin
directory. ``` cd <TensorRT root directory>/samples/sampleUffMaskRCNN make ```
Where <TensorRT root directory>
is where you installed TensorRT.
Run the sample to perform object detection and object mask prediction.
To run the sample in FP32 mode: ``` ./sample_uff_mask_rcnn -d path/to/data ```
To run the sample in FP16 mode: ``` ./sample_uff_mask_rcnn -d path/to/data –fp16 ```
This output shows that the sample ran successfully;
PASSED`.--help
optionsTo see the full list of available options and their descriptions, use the -h
or --help
command line option.
The following resources provide a deeper understanding about sampleUffMaskRCNN.
Documentation
For terms and conditions for use, reproduction, and distribution, see the TensorRT Software License Agreement documentation.
July 2019 This is the first release of the README.md
file and sample.
pip install tensorflow-gpu
) requires CUDA 10.1 and is incompatible with CUDA 11.x. To generate the UFF model required for this sample, use a container built with CUDA_VERSION=10.1
.