Are here some samples of tensorrt 4 plugin api for tensorflow uff?

Hi, I want to use the uff plugin api, but I don’t know how to use it. can anyone tell me about some samples?

Hi,

Please remember that UFF plugin is supported until TensorRT 4.
We don’t have dedicated sample currently. You can refer to Caffe plugin sample for more information.

class MyUffPlugin : public IPlugin
...
int main(int argc, char** argv)
{
    ...
    IBuilder* builder = createInferBuilder(gLogger);
    INetworkDefinition* network = builder->createNetwork();
    parser->setPluginFactory(pluginFactory);

    if(!parser->parse(uffFile, *network, nvinfer1::DataType::kFLOAT))
        RETURN_AND_LOG(ERROR, "Fail to parse");
    ...
    ICudaEngine* engine = runtime->deserializeCudaEngine(gieModelStream->data(), gieModelStream->size(), &pluginFactory);
    ...

Thanks.

I get a segmentation fault when i converted the caffe samplePlugin to use .uff
ERROR: Parameter check failed at: …/builder/Network.cpp::addInput::377, condition: isValidDims(dims)
Segmentation fault (core dumped)

void UFFtoGIEModel(const char* uffFile, int maxBatchSize, nvuffparser::IPluginFactory* pluginFactory, IHostMemory *&gieModelStream)
{
    IBuilder* builder = createInferBuilder(gLogger);
    INetworkDefinition* network = builder->createNetwork();
    IUffParser* parser = createUffParser();
    parser->setPluginFactory(pluginFactory);
    parser->parse(uffFile, *network, nvinfer1::DataType::kFLOAT);
    parser->registerInput("Input/input", DimsCHW(1, 28, 28));
    parser->registerOutput("fc2/Relu");
    // specify which tensors are outputs
	/* we create the engine */
    builder->setMaxBatchSize(maxBatchSize);
    builder->setMaxWorkspaceSize(1 << 20);

    ICudaEngine* engine = builder->buildCudaEngine(*network);
    assert(engine);

    // serialize the engine, then close everything down
    network->destroy();
    parser->destroy();
	// serialize the engine, then close everything down
	gieModelStream = engine->serialize();
    engine->destroy();
    builder->destroy();
    shutdownProtobufLibrary();
}

Backtrace

(gdb) run
Starting program: samples/bin/sample_plugin_debug
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
../../data/mnist/model.uff
[New Thread 0x7fffccb6d700 (LWP 161079)]
[New Thread 0x7fffcc36c700 (LWP 161080)]
[New Thread 0x7fffcbaea700 (LWP 161081)]
ERROR: Parameter check failed at: ../builder/Network.cpp::addInput::377, condition: isValidDims(dims)

Thread 1 "sample_plugin_d" received signal SIGSEGV, Segmentation fault.

0x00007fffe9b8145b in UffParser::parseConv(uff::Node const&, std::unordered_map<std::string, uff::Data, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, uff::Data> > > const&, std::unordered_m
ap<std::string, FullNode, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, FullNode> > >&) () from /usr/lib/x86_64-linux-gnu/libnvparsers.so.4.1.0
(gdb) bt
#0  0x00007fffe9b8145b in UffParser::parseConv(uff::Node const&, std::unordered_map<std::string, uff::Data, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, uff::Data> > > const&, std::unorder
ed_map<std::string, FullNode, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, FullNode> > >&) () from /usr/lib/x86_64-linux-gnu/libnvparsers.so.4.1.0
#1  0x00007fffe9b8caf1 in UffParser::parseMetaGraph(uff::MetaGraph, nvinfer1::INetworkDefinition&, nvinfer1::DataType) () from /usr/lib/x86_64-linux-gnu/libnvparsers.so.4.1.0
#2  0x00007fffe9b8e9e6 in UffParser::parseBuffer(char const*, unsigned long, nvinfer1::INetworkDefinition&, nvinfer1::DataType) () from /usr/lib/x86_64-linux-gnu/libnvparsers.so.4.1.0
#3  0x00007fffe9b77975 in UffParser::parse(char const*, nvinfer1::INetworkDefinition&, nvinfer1::DataType) () from /usr/lib/x86_64-linux-gnu/libnvparsers.so.4.1.0
#4  0x000000000040577d in UFFtoGIEModel (uffFile=0x88f450 "../../data/mnist/model.uff", maxBatchSize=1, gieModelStream=@0x7fffffffd528: 0x0) at samplePlugin.cpp:52
#5  0x0000000000405f7f in main (argc=1, argv=0x7fffffffda18) at samplePlugin.cpp:311
(gdb) frame 5
#5  0x0000000000405f7f in main (argc=1, argv=0x7fffffffda18) at samplePlugin.cpp:311
311         UFFtoGIEModel(fileName.c_str(),  1,  gieModelStream);
(gdb) frame 4
#4  0x000000000040577d in UFFtoGIEModel (uffFile=0x88f450 "../../data/mnist/model.uff", maxBatchSize=1, gieModelStream=@0x7fffffffd528: 0x0) at samplePlugin.cpp:52
52          parser->parse(uffFile, *network, nvinfer1::DataType::kFLOAT);
(gdb) frame 3
#3  0x00007fffe9b77975 in UffParser::parse(char const*, nvinfer1::INetworkDefinition&, nvinfer1::DataType) () from /usr/lib/x86_64-linux-gnu/libnvparsers.so.4.1.0
(gdb) frame 2
#2  0x00007fffe9b8e9e6 in UffParser::parseBuffer(char const*, unsigned long, nvinfer1::INetworkDefinition&, nvinfer1::DataType) () from /usr/lib/x86_64-linux-gnu/libnvparsers.so.4.1.0
(gdb) frame 1
#1  0x00007fffe9b8caf1 in UffParser::parseMetaGraph(uff::MetaGraph, nvinfer1::INetworkDefinition&, nvinfer1::DataType) () from /usr/lib/x86_64-linux-gnu/libnvparsers.so.4.1.0
(gdb) frame 0
#0  0x00007fffe9b8145b in UffParser::parseConv(uff::Node const&, std::unordered_map<std::string, uff::Data, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, uff::Data> > > const&, std::unorder
ed_map<std::string, FullNode, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, FullNode> > >&) () from /usr/lib/x86_64-linux-gnu/libnvparsers.so.4.1.0

Does tensorflow models trained using tensorflow 1.13.1 will work with uff parser