weixin_39950824
weixin_39950824
2020-11-26 16:19

modify yolov4.cpp, stride=4, don't support?

I use the https://github.com/AlexeyAB/darknet repo to train my own model

when I try to convert the .weights model to tensorRT .engine. The error comes out. I found that the cfg file I used is a little bit different with your trt implementation.As following:

(1) deconv layer 128 [upsample] stride=4

your implementation is stride=2

(2) layer 141 [convolutional] batch_normalize=1 size=3 stride=4 pad=1 filters=256 activation=leaky

your implementation is stride=2

I try to modify yolov4.cpp like the following:

(1) float *deval2 = reinterpret_cast(malloc(sizeof(float) * 128 * 4 * 4)); for (int i = 0; i < 128 * 4 * 4; i++) { deval2[i] = 1.0; }

Weights deconvwts128{DataType::kFLOAT, deval2, 128 * 4 * 4};
IDeconvolutionLayer* deconv128 = network->addDeconvolutionNd(*l127->getOutput(0), 128, DimsHW{4, 4}, deconvwts128, emptywts);
assert(deconv128);
deconv128->setStrideNd(DimsHW{4, 4});
deconv128->setNbGroups(128);

(2) auto l141 = convBnLeaky(network, weightMap, *l140->getOutput(0), 256, 3, 4, 1, 141);

I successfully convert the model with the path: .weights -> .wts -> .engine

I test the .engine with my test samples. But the result is in a mess. Could you please help to check the above code? thanks a lot.

该提问来源于开源项目:wang-xinyu/tensorrtx

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

5条回答

  • weixin_39950824 weixin_39950824 5月前

    any ideas?

    点赞 评论 复制链接分享
  • weixin_39876877 weixin_39876877 5月前

    there is a debug trick. You can set any layer as output, and compare the output values with pytorch output. If the values are right, it means the model before this layer is fine. For example, you can set the layer before deconv as output and compare.

    点赞 评论 复制链接分享
  • weixin_39950824 weixin_39950824 5月前

    thanks. BTW, I try to run tensorRT with specified GPU DEVICE, but it seems that the tensorRT can only run on DEVICE, which lies here #define DEVICE 4. Any suggetions?

    点赞 评论 复制链接分享
  • weixin_39876877 weixin_39876877 5月前

    remove this line in yolov4.cpp if you want to set gpu_id outside.

    
    cudaSetDevice(DEVICE);
    
    点赞 评论 复制链接分享
  • weixin_39950824 weixin_39950824 5月前

    thanks a lot.

    点赞 评论 复制链接分享

相关推荐