Git Product home page Git Product logo

pytorch-tensorrt-plugins's Introduction

Plugins for Pytorch & TensorRT

It's a personal backup repository, but I will try my best to help you understand how to use them.

Now it contains:

Plugins Support
DCNv2 pytorch1.5+/tensorrt7
yolov5 detection tensorrt7/tensorrt8
Models Support
mobilenetv3-centernet pytorch1.5+/tensorrt7
yolov5 (integrated with detection and nms) tensorrt7/tensorrt8

Installation

Pytorch

cd pytorch
python setup.py install --user(optioanl)
cd ../examples python
from dcn_v2_wrapper import DeformableConv2DLayer as DCN

TensorRT

  1. Copy plugin folders from tensorrt to NVIDIA/TensorRT/plugin

  2. Add relative head file and initializePlugin() to InferPlugin.cpp at proper place, for example

#include "dcnv2Plugin.h"
#include "yoloPlugin.h"

initializePlugin<nvinfer1::plugin::DCNv2PluginCreator>(logger, libNamespace); initializePlugin<nvinfer1::plugin::YoloPluginCreator>(logger, libNamespace);

  1. Add name of plugin folder to PLUGIN_LISTS in CMakeLists.txt

  2. Build and use libnvinfer_plugin.so following offical introduction.

EXAMPLES

There are two pytorch2tensorrt transfer scripts in examples to show how these plugins work.

Evaluation

cd examples
python mbv3_centernet_trt7.py

The evaluation output is as follow which are mean values of hm, wh, reg
eval

pytorch-tensorrt-plugins's People

Contributors

invix-yihang avatar ssisyphustao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pytorch-tensorrt-plugins's Issues

IndexError: _Map_base::at

Thank you very much for your materials. I managed to use your pytorch dcn to train my model. However, when I convert this model to ONNX format, this error apprears. Do you know why?

  File "/data1/hoangbm/codes/CenterNet/src/lib/models/networks/dcnv2_torch15/dcn_v2_wrapper.py", line 105, in forward
    return DeformableConv2DFunction.apply(inputs, self.weight, self.bias, offset, mask, self.stride, self.pad, self.dilation, self.deformable_groups)
  File "/data1/hoangbm/codes/CenterNet/src/lib/models/networks/dcnv2_torch15/dcn_v2_wrapper.py", line 28, in forward
    ctx.deformable_groups
IndexError: _Map_base::at

This code produce this error

onnx.export(model, input_, '/data1/hoangbm/temp/pp_cnet15_dla.onnx', 
            keep_initializers_as_inputs=True,
            verbose=False, operator_export_type=OperatorExportTypes.ONNX)

Plugin dcn_v2 only works at batch_size=1 in tensorrt

Hi @SsisyphusTao, great job!
I found that if one uses batch_size greater than 1, the only first tensor in batch is correct, the others are zero or nearly zero.

For example, if change several lines of code in examples/mbv3_centernet_trt7.py let's say
at line 216 builder.max_batch_size = 4
at line 225 img = np.random.randn(4,3,224,224).astype(np.float32)
at line 254 [hm, wh, reg, _] = common.do_inference(context, bindings=bindings, inputs=inputs, outputs=outputs, stream=stream, batch_size=4)

And try inference on batch size 4, the ouputs are correct only for first image in the batch.
The other outputs are zeros. I added print(hm[-200:]) to check and
as the output is:
[ 0.0000000e+00 1.7881393e-06 2.3245811e-06 1.4901161e-06 5.9604645e-08 -1.1920929e-07 -1.1920929e-07 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 -2.9802322e-07 -1.1920929e-07 1.7881393e-07 0.0000000e+00 0.0000000e+00 1.9490719e-05 2.5033951e-06 2.3603439e-05 4.7683716e-07 -1.0728836e-06 1.9669533e-06 0.0000000e+00 0.0000000e+00 -1.4901161e-06 5.9604645e-08 -3.5762787e-07 4.1127205e-05 3.9935112e-06 5.0365925e-05 0.0000000e+00 0.0000000e+00 0.0000000e+00 1.1920929e-07 9.5367432e-07 -1.1920929e-06 -2.2649765e-06 -3.3378601e-06 0.0000000e+00 0.0000000e+00 -3.2782555e-06 -2.3841858e-07 -2.5629997e-06 -3.9935112e-06 -7.0929527e-06 4.1723251e-07 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 1.1920929e-07 -2.9802322e-07 0.0000000e+00 0.0000000e+00 7.7486038e-07 -5.3644180e-07 -5.9604645e-08 2.3841858e-07 4.1723251e-07 2.0265579e-06 0.0000000e+00 0.0000000e+00 -2.9802322e-07 -5.9604645e-08 1.7881393e-07 1.7881393e-06 -1.3113022e-06 -5.9604645e-08 0.0000000e+00 0.0000000e+00 0.0000000e+00 -5.9604645e-08 0.0000000e+00 5.3644180e-07 5.9604645e-08 1.7881393e-07 0.0000000e+00 0.0000000e+00 1.3709068e-06 -1.2516975e-06 -7.1525574e-07 9.5367432e-07 -2.3365021e-05 4.9471855e-06 0.0000000e+00 0.0000000e+00 -2.9802322e-07 1.1920929e-07 5.9604645e-08 1.7881393e-07 -2.3841858e-07 2.3841858e-07 0.0000000e+00 0.0000000e+00 -3.7550926e-06 7.1525574e-07 -1.7285347e-06 -2.2053719e-06 1.3113022e-06 3.9339066e-06 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 -4.7683716e-07 -1.4901161e-06 -2.9802322e-07 0.0000000e+00 0.0000000e+00 -2.1457672e-06 -2.3841858e-07 5.9604645e-07 -1.0132790e-06 5.9604645e-08 7.1525574e-07 0.0000000e+00 0.0000000e+00 -1.1920929e-07 4.7683716e-07 -4.1723251e-07 -2.2053719e-06 1.4305115e-06 1.1324883e-06 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 9.2387199e-06 -7.0333481e-06 0.0000000e+00 0.0000000e+00 0.0000000e+00 1.7881393e-07 2.9802322e-07 -4.1723251e-07 -1.0251999e-05 -4.2915344e-06 1.8775463e-05 0.0000000e+00 0.0000000e+00 6.5565109e-07 -2.9802322e-07 6.5565109e-07 0.0000000e+00 -5.9604645e-07 -5.9604645e-07 0.0000000e+00 0.0000000e+00 1.8477440e-06 -2.6226044e-06 -1.7881393e-06 -2.9802322e-07 -1.7881393e-07 6.5565109e-07 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 -4.7683716e-07 2.3841858e-07 6.5565109e-07 0.0000000e+00 0.0000000e+00 -7.1525574e-07 5.9604645e-07 -6.5565109e-07 1.7881393e-07 -1.6093254e-06 1.1324883e-06 0.0000000e+00 0.0000000e+00 1.1920929e-07 -6.5565109e-07 5.9604645e-08 8.9406967e-07 -1.2516975e-06 6.5565109e-07 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 -3.7550926e-06 2.3841858e-07 -3.6954880e-06 0.0000000e+00 0.0000000e+00 0.0000000e+00 -1.1920929e-07 -1.1920929e-07 -1.8775463e-05 -6.1988831e-06 -1.3768673e-05 0.0000000e+00]
May be you know the problem and can point me in right direction? @SsisyphusTao

DCNv2 support for tensorrt8

Hi,

thanks a lot for this great repo. Very helpful!
We would like to use the DCNv2 plugin with tensorrt8 but it appears that is not yet supported yet. We are getting several errors when compiling.

Do you plan on upgrading the DCNv2 plugin to support tensorr8 as well or have any preliminary points/work that could help speed up the progress?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.