TensorRT开发问题合集(持续更新)

问题1:

错误信息:

While parsing node number 645 [GlobalAveragePool]:
ERROR: builtin_op_importers.cpp:1087 In function importGlobalAveragePool:
[8] Assertion failed: !isDynamic(kernelSize) && "Cannot run global average pool on an input with dynamic spatial dimensions!"

导致原因:
模型input shape为动态值,需要设置为固定值,如下图输入的tensor尺寸float32[batch_size,3,h,w]
TensorRT开发问题合集(持续更新)_第1张图片

问题2

TensorRT 8.2
错误信息:

Internal Error (Network has dynamic or shape inputs, but no optimization profile has been defined.

相关文档:work_dynamic_shapes
解决方法:

auto builder = SampleUniquePtr<nvinfer1::IBuilder>(nvinfer1::createInferBuilder(sample::gLogger.getTRTLogger()));
    if (!builder)
    {
        return false;
    }

    //按照官方要求,网络定义不得具有隐式批处理维度
    auto network = SampleUniquePtr<nvinfer1::INetworkDefinition>(builder->createNetworkV2(1U <<static_cast<int>(NetworkDefinitionCreationFlag::kEXPLICIT_BATCH)));
    if (!network)
    {
        return false;
    }

    auto config = SampleUniquePtr<nvinfer1::IBuilderConfig>(builder->createBuilderConfig());
    if (!config)
    {
        return false;
    }
    //添加IOptimization Profile,指定维度范围
    IOptimizationProfile* profile = builder->createOptimizationProfile();
    profile->setDimensions("inputs", OptProfileSelector::kMIN, Dims4(1, 3, 512, 512));
    profile->setDimensions("inputs", OptProfileSelector::kOPT, Dims4(1, 3, 512, 512));
    profile->setDimensions("inputs", OptProfileSelector::kMAX, Dims4(1, 3, 512, 512));

    config->addOptimizationProfile(profile);

你可能感兴趣的:(TensorRT,深度学习,TensorRT)