TensorRT icon indicating copy to clipboard operation
TensorRT copied to clipboard

PReLU conversion in caffe parser

Open golunovas opened this issue 7 years ago • 9 comments

Hi,

I have found that the implementation of PReLU conversion in the Caffe parser isn't correct. The issue goes from here when channelShared==false: https://github.com/NVIDIA/TensorRT/blob/466657173a93d72ab07942cf6b634a92986fa922/parsers/caffe/caffeParser/opParsers/parsePReLU.cpp#L40 Apparently, slopesDims should look like this (C, 1, 1) in the 2-d case and (C, 1) in the 1-d case. In your implementation, it looks like (1, H, 0) in the 2-d case which is completely incorrect and leads to some errors because one of the dimensions is 0 or (1, H) in the 1-d case which seems to be incorrect as well.

golunovas avatar Oct 29 '19 11:10 golunovas

Hi @golunovas,

Thanks for bringing this up. Can you provide a minimal example that I can run that reproduces this bug, showing the incorrect results vs. the expected results?

rmccorm4 avatar Oct 30 '19 05:10 rmccorm4

Hi @rmccorm4,

This is the model I had issues with https://github.com/DaFuCoding/MTCNN_Caffe/blob/master/examples/MTmodel/det1.prototxt

golunovas avatar Oct 30 '19 10:10 golunovas

@golunovas,

Can you also provide the full code you're using to parse the model and build + run instructions so I can reproduce this? You can attach files via drag and drop in a comment.

rmccorm4 avatar Nov 04 '19 01:11 rmccorm4

@rmccorm4 I was using this sample https://github.com/NVIDIA/TensorRT/tree/master/samples/opensource/sampleGoogleNet I changed the model name:

params.prototxtFileName = locateFile("det1.prototxt", params.dataDirs);
params.weightsFileName = locateFile("det1.caffemodel", params.dataDirs);

and the output name:

params.outputTensorNames.push_back("prob1");

golunovas avatar Nov 06 '19 07:11 golunovas

Hi @golunovas,

I was able to reproduce this, assuming this is the error you originally got:

root@5b37960c8eb7:/usr/src/tensorrt/bin# ./sample_googlenet
&&&& RUNNING TensorRT.sample_googlenet # ./sample_googlenet
[10/06/2019-21:16:14] [I] Building and running a GPU inference engine for GoogleNet
[10/06/2019-21:16:15] [E] [TRT] Parameter check failed at: ../builder/Network.cpp::addConstant::562, condition: allDimsGtEq(dimensions, 1)
Segmentation fault (core dumped)

Steps to Reproduce

I repro'd this inside of the NGC 19.10-py3 TensorRT container with steps similar to here: https://github.com/NVIDIA/TensorRT/issues/190#issuecomment-550037253

Some extra steps before building the samples:

# Download models and move into data directory
wget https://github.com/DaFuCoding/MTCNN_Caffe/raw/master/examples/MTmodel/det1.prototxt
wget https://github.com/DaFuCoding/MTCNN_Caffe/raw/master/examples/MTmodel/det1.caffemodel
cp det1.* /usr/src/tensorrt/data/googlenet/

# Apply the changes to the sample file you mentioned above
patch samples/opensource/sampleGoogleNet/sampleGoogleNet.cpp < /mnt/issue179.patch 

issue179.patch.txt (added .txt because GitHub doesn't allow uploading .patch files)

I'll see if we can get this fixed.

rmccorm4 avatar Nov 06 '19 21:11 rmccorm4

Hi @golunovas,

This should be fixed in a future release, thanks for bringing this up.

rmccorm4 avatar Nov 12 '19 00:11 rmccorm4

I also have the same problem, with the current build from the master branch.

andviane avatar Dec 02 '19 15:12 andviane

I have fixed the bug in my project by change the following code

https://github.com/NVIDIA/TensorRT/blob/466657173a93d72ab07942cf6b634a92986fa922/parsers/caffe/caffeParser/opParsers/parsePReLU.cpp#L40-L42

to

int nWeights = channelShared ? 1 : inputDims.d[0];
Dims slopesDims{inputDims.nbDims, {nWeights, 1, 1}, {DimensionType::kCHANNEL, DimensionType::kSPATIAL, DimensionType::kSPATIAL}};    

yqbeyond avatar Dec 26 '19 04:12 yqbeyond

Fix change for trt6.0 (trt7.0 has no this issue):

Dims slopesDims{inputDims.nbDims, {1}, {DimensionType::kSPATIAL}};

--> Dims slopesDims{inputDims.nbDims, {}, {}}; std::fill(slopesDims.d, slopesDims.d + slopesDims.nbDims, 1);

cding-nv avatar Mar 18 '20 11:03 cding-nv