'Tensor' object has no attribute '_trt'
,这个我在debug的时候也遇到了Traceback (most recent call last):
File "/home/jetsonnano/Desktop/Yolov3/4_torch2trt_detect_custom.py", line 149, in <module>
model_trt = torch2trt(model_backbone, [x], fp16_mode=True)
File "/usr/local/lib/python3.6/dist-packages/torch2trt/torch2trt.py", line 377, in torch2trt
outputs = module(*inputs)
File "/home/jetsonnano/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in __call__
result = self.forward(*input, **kwargs)
File "/home/jetsonnano/Desktop/Yolov3/models_for_trt.py", line 377, in forward
x = module(x)
File "/home/jetsonnano/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in __call__
result = self.forward(*input, **kwargs)
File "/home/jetsonnano/.local/lib/python3.6/site-packages/torch/nn/modules/container.py", line 100, in forward
input = module(input)
File "/home/jetsonnano/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 532, in __call__
result = self.forward(*input, **kwargs)
File "/home/jetsonnano/.local/lib/python3.6/site-packages/torch/nn/modules/activation.py", line 559, in forward
return F.leaky_relu(input, self.negative_slope, self.inplace)
File "/usr/local/lib/python3.6/dist-packages/torch2trt/torch2trt.py", line 202, in wrapper
converter['converter'](ctx)
File "/usr/local/lib/python3.6/dist-packages/torch2trt/converters/activation.py", line 22, in convert_leaky_relu
layer = ctx.network.add_activation(input_trt, trt.ActivationType.LEAKY_RELU)
AttributeError: type object 'tensorrt.tensorrt.ActivationType' has no attribute 'LEAKY_RELU'
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/jetsonnano/.vscode-server-insiders/extensions/ms-python.python-2020.2.63072/pythonFiles/lib/python/new_ptvsd/no_wheels/ptvsd/__main__.py", line 45, in <module>
cli.main()
File "/home/jetsonnano/.vscode-server-insiders/extensions/ms-python.python-2020.2.63072/pythonFiles/lib/python/new_ptvsd/no_wheels/ptvsd/../ptvsd/server/cli.py", line 361, in main
run()
File "/home/jetsonnano/.vscode-server-insiders/extensions/ms-python.python-2020.2.63072/pythonFiles/lib/python/new_ptvsd/no_wheels/ptvsd/../ptvsd/server/cli.py", line 203, in run_file
runpy.run_path(options.target, run_name="__main__")
File "/usr/lib/python3.6/runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "/usr/lib/python3.6/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/jetsonnano/Desktop/Yolov3/4_torch2trt_detect_custom.py", line 149, in <module>
model_trt = torch2trt(model_backbone, [x], fp16_mode=True)
File "/usr/local/lib/python3.6/dist-packages/torch2trt/torch2trt.py", line 381, in torch2trt
ctx.mark_outputs(outputs, output_names)
File "/usr/local/lib/python3.6/dist-packages/torch2trt/torch2trt.py", line 282, in mark_outputs
trt_tensor = torch_output._trt
AttributeError: 'Tensor' object has no attribute '_trt'
import torch2trt
print(torch2trt.CONVERTERS)
输出是个Json,格式化后可以看到当前torch2trt支持leaky_relu
那么也就是当前tensorRT不支持,最直接的验证方法是,直接打出来,看看有没有这个函数
还有一种更加直观的方法——去文档查看,以下是文档地址
这个是5.0.2.1的API文档,通过搜索ActivationTpye可以清楚看到它支持的函数只有三个
对比6.0版本的文档,可以发现6.0新增了许多激活函数,期中就包括了LEAKY_RELU
顺便查了查7版本的文档,发现激活函数部分没有更新,那暂时用6也就够了
因此我的解决思路是,将tensorRT升级到6.0 版本
于是,第一反应就是去官网下载,于是瞅到了这个
我发现,想要给我的Jetson Nano 更新TensorRT版本,就必须直接更新整体的Jetpack,目前最新Jetpack4.3是包含tensorRT6.0
而改变Jetpack版本,根据官网说法,有两种方法
另外,附上Jetpack 4.3的镜像(如果选择自己下,迅雷可能会快一些):
链接:https://pan.baidu.com/s/1qiXhP-6xFLyRwBIIWa0zCg
提取码:6brj
复制这段内容后打开百度网盘手机App,操作更方便哦