ziheng
June 11, 2020, 2:51am
1
I am trying to write a custom layer in TensorRT using addPluginV2. I see this error:
[06/10/2020-22:47:08] [E] [TRT] Parameter check failed at: …/builder/Network.cpp::addPluginV2::997, condition: containsTensor(inputs[i])
i.e. the layer after my custom layer cannot find the output of the custom layer. Any pointers?
Thanks.
Error log implies that the input tensors are not owned by the network object.
Can you post a piece of sample code, so we can help better?
Thanks
ziheng
June 11, 2020, 6:52am
3
last_conv->setPadding(DimsHW{0, 0});
IActivationLayer* relu1 = network->addActivation(*last_conv->getOutput(0), ActivationType::kRELU);
std::cout << relu1->getOutput(0)->getDimensions() << std::endl;
IPoolingLayer* avg_pool = network->addPooling(*relu1->getOutput(0),PoolingType::kAVERAGE,DimsHW{7,7});
assert(avg_pool);
std::cout << avg_pool->getOutput(0)->getDimensions() << std::endl;
//add the plugin to the TensorRT network using the network API
nvinfer1::ITensor* const* point = (nvinfer1::ITensor* const*) &(*avg_pool->getOutput(0));
nvinfer1::PluginFieldCollection plugfc;
plugfc.nbFields = 0;
plugfc.fields = nullptr;
nvinfer1::IPluginV2* pluginV2 = getPluginRegistry()->getPluginCreator("Identity", "2")->createPlugin("testing", &plugfc);
assert(pluginV2);
auto layer = network->addPluginV2(point, 1280 * 4, *pluginV2);
layer->setName("testing");
nvinfer1::Weights fc_weight, fc_bias;
auto arr4 = cnpy::npy_load("mbnetv2/final_dense_kernel.npy");
fc_weight.values = arr4.data<short>();
fc_weight.count = arr4.shape[0] * arr4.shape[1];
auto arr5 = cnpy::npy_load("mbnetv2/final_dense_bias.npy");
fc_bias.values = arr5.data<short>();
fc_bias.count = arr5.shape[0];
fc_weight.type = DataType::kHALF;
fc_bias.type = DataType::kHALF;
IFullyConnectedLayer * fc = network->addFullyConnected(*layer->getOutput(0), 1000, fc_weight, fc_bias);
It seems that you are using the dim instead of input count. So TRT will check an out of bound memory, it is invalid (not owned by network)
Please refer to below API link:
https://docs.nvidia.com/deeplearning/tensorrt/archives/tensorrt-710-ea/api/c_api/classnvinfer1_1_1_i_network_definition.html#a0c6e2a0b4e1c8a4df1722a24cc7c0473
nvinfer1::IPluginV2* pluginV2 = mPluginRegistry.at(pluginName)->createPlugin(layerMsg.name().c_str(), &fc);
assert(pluginV2);
mNewPlugins.push_back(pluginV2);
std::vector<ITensor*> inputs;
for (int i = 0, n = layerMsg.bottom_size(); i < n; i++)
{
inputs.push_back((*mBlobNameToTensor)[layerMsg.bottom(i)]);
}
auto layer = network.addPluginV2(&inputs[0], int(inputs.size()), *pluginV2);
layer->setName(layerMsg.name().c_str());
if (pluginV2->getNbOutputs() != layerMsg.top_size())
{
std::cout << "Plugin layer output count is not equal to caffe output count" << std::endl;
ok = false;
}
for (int i = 0, n = std::min(layer->getNbOutputs(), layerMsg.top_size()); i < n; i++)
{
(*mBlobNameToTensor)[layerMsg.top(i)] = layer->getOutput(i);
}
Thanks