如何解决类型错误:需要一个类似字节的对象,而不是 TensorRT 中的“Tensor”
我正在尝试使用 tensorrt 来加速我的模型推理。
现在,我得到了我的模型的 onnx 文件,我也得到了我的模型的引擎。
这是我的模型在 onnx 文件中的输入。
a = torch.ones(64,30,25,3).cuda()
x=torch.onnx.export(model,# 待转换的网络模型和参数
(a,a,a),# 虚拟的输入,用于确定输入尺寸和推理计算图每个节点的尺寸
'ConVNet.onnx',# 输出文件的名称
verbose=False,# 是否以字符串的形式显示计算图
input_names=input_name,# 输入节点的名称,这里也可以给一个list,list中名称分别对应每一层可学习的参数,便于后续查询
output_names=["output"],# 输出节点的名称
opset_version=10,# onnx 支持采用的operator set,应该和pytorch版本相关,目前我这里最高支持10
do_constant_folding=True,# 是否压缩常量
dynamic_axes={"input":{0: "batch_size",1: "30个骨架",2:"维度为3",3:"骨架"},"output":{0: "batch_size"},} #设置动态维度,此处指明input节点的第0维度可变,命名为batch_size
)
当我尝试将 onnx 转换为 tensorrt 时出现此错误。
Reading engine from file: ./ConVNet.engine
the bindding's name: frame_1
bingding shape: (64,3)
the bindding's name: frame_2
bingding shape: (64,3)
the bindding's name: d_1
bingding shape: (64,3)
the bindding's name: d_2
bingding shape: (64,3)
the bindding's name: 140
bingding shape: (64,4096)
the bindding's name: output
bingding shape: (64,60)
Traceback (most recent call last):
File "onnx2rt.py",line 196,in <module>
trt_outputs = do_inference(context,bindings=bindings,inputs=inputs,outputs=outputs,stream=stream) # numpy data
File "onnx2rt.py",line 159,in do_inference
[cuda.memcpy_htod_async(inp.device,inp.host,stream) for inp in inputs]
File "onnx2rt.py",in <listcomp>
[cuda.memcpy_htod_async(inp.device,stream) for inp in inputs]
TypeError: a bytes-like object is required,not 'tuple'
这就是我如何尝试进行推理。
a = torch.ones(64,3).cuda()
inputs[0].host = (a,a)
trt_outputs = do_inference(context,stream=stream)
如果有人能帮助我,我将不胜感激!
================================================
我已经重新回答了这个问题。就这样使用:
a = np.ones((64,3),dtype=np.float32)
inputs[0].host = (a.reshape(-1))
inputs[1].host = (a.reshape(-1))
inputs[2].host = (a.reshape(-1))
inputs[3].host = (a.reshape(-1))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。