100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 【onnx】——since it‘s not constant please try to make things (e.g. kernel size) static if possible

【onnx】——since it‘s not constant please try to make things (e.g. kernel size) static if possible

时间:2022-03-06 20:07:45

相关推荐

【onnx】——since it‘s not constant  please try to make things (e.g.  kernel size) static if possible

onnx,pytorch

pytorch转onnx时的时候报错:

since it's not constant, please try to make things (e.g., kernel size) static if possible

主要是一些tensor的尺寸没有固定,可以通过pycharm在symbolic_helper.py文件中的如下位置打断点。

elif value.node().kind() == 'prim::ListConstruct':if desc == 'is':for v in value.node().inputs():if v.node().kind() != 'onnx::Constant':raise RuntimeError("Failed to export an ONNX attribute '" + v.node().kind() +"', since it's not constant, please try to make ""things (e.g., kernel size) static if possible")

然后可以通过看变量v就可以看到错误的位置:

782 defined in (%782 : Long(device=cpu) = onnx::Gather[axis=0](%779, %781) # /home/darknet/CM/8_instance_segmentation/AttaNet/AttaNet.py:82:0)

可以看到是在AttaNet.py文件的第82行出错的。

对pytorch代码的修改

AttaNet.py文件的第82行:

batchsize, c_middle, h, w = q.size()q = F.avg_pool2d(q, [h, 1])

可以看到这里的avg_pool2d操作采用的h作为参数,这里因为h不是固定值引起的。修改方式:

用整数值代替单个变量采用:torch.tensor(feats.size(1)).item()多个变量采用:torch.tensor(probs.shape[:2]).tolist()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。