PReLU conversion in caffe parser
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.
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?
Hi @rmccorm4,
This is the model I had issues with https://github.com/DaFuCoding/MTCNN_Caffe/blob/master/examples/MTmodel/det1.prototxt
@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 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");
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.
Hi @golunovas,
This should be fixed in a future release, thanks for bringing this up.
I also have the same problem, with the current build from the master branch.
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}};
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);