TensortRT:sample.py:DeprecationWarning:

错误描述

sample.py:112: DeprecationWarning: Use set_memory_pool_limit instead.
config.max_workspace_size = common.GiB(1)
sample.py:75: DeprecationWarning: Use add_convolution_nd instead.
conv1 = network.add_convolution(
sample.py:78: DeprecationWarning: Use stride_nd instead.
conv1.stride = (1, 1)
sample.py:80: DeprecationWarning: Use add_pooling_nd instead.
pool1 = network.add_pooling(input=conv1.get_output(0), type=trt.PoolingType.MAX, window_size=(2, 2))
sample.py:81: DeprecationWarning: Use stride_nd instead.
pool1.stride = (2, 2)
sample.py:85: DeprecationWarning: Use add_convolution_nd instead.
conv2 = network.add_convolution(pool1.get_output(0), 50, (5, 5), conv2_w, conv2_b)
sample.py:86: DeprecationWarning: Use stride_nd instead.
conv2.stride = (1, 1)
sample.py:88: DeprecationWarning: Use add_pooling_nd instead.
pool2 = network.add_pooling(conv2.get_output(0), trt.PoolingType.MAX, (2, 2))
sample.py:89: DeprecationWarning: Use stride_nd instead.
pool2.stride = (2, 2)
在这里插入图片描述

原因:

这些警告信息是在运行Python代码时出现的,它们是关于TensorRT(一个用于深度学习推理的库)的API使用的。TensorRT的最新版本中对某些函数进行了更新,而代码中仍然使用了一些被弃用(deprecated)的函数。

解决方案:

config.max_workspace_size = common.GiB(1):

警告信息:DeprecationWarning: Use set_memory_pool_limit instead.
解决方案:使用 config.set_memory_pool_limit(trt.MemoryPoolType.WORKSPACE, common.GiB(1)) 来替代被弃用的 config.max_workspace_size。
在这里插入图片描述

config.set_memory_pool_limit(trt.MemoryPoolType.WORKSPACE, common.GiB(1))

network.add_convolution(…):

警告信息:DeprecationWarning: Use add_convolution_nd instead.
解决方案:使用 network.add_convolution_nd(…) 来替代 network.add_convolution(…)。
在这里插入图片描述

conv1.stride = (1, 1):

警告信息:DeprecationWarning: Use stride_nd instead.
解决方案:使用 conv1.stride_nd = (1, 1) 来替代 conv1.stride。
在这里插入图片描述

network.add_pooling(…):

警告信息:DeprecationWarning: Use add_pooling_nd instead.
解决方案:使用 network.add_pooling_nd(…) 来替代 network.add_pooling(…)。
在这里插入图片描述

pool1.stride = (2, 2)、pool2.stride = (2, 2):

扫描二维码关注公众号,回复: 17195280 查看本文章

警告信息:与 conv1.stride = (1, 1) 相同,同样需要使用 stride_nd。
在这里插入图片描述
再次运行python sample.py, 没有任何warning了。
在这里插入图片描述

感悟:

主要是我下载的TensorRT版本太新了,而sample.py里面有一些过时的TensorRT的语法,所以才导致今天的错误。

猜你喜欢

转载自blog.csdn.net/s1_0_2_4/article/details/135026800
py
今日推荐