Pytorch转ONNX采坑记:Converting a tensor to a Python boolean might cause the trace to be incorrect. We...
生活随笔
收集整理的这篇文章主要介绍了
Pytorch转ONNX采坑记:Converting a tensor to a Python boolean might cause the trace to be incorrect. We...
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
如果你用Pytorch定义的网络结构太过于灵活,那么转成ONNX的时候很有可能出错。这个报错通常情况下是你的网络结构中出现if else 语句。比如
if cfg.CUDA:eps = torch.cuda.FloatTensor(std.size()).normal_()else:eps = torch.FloatTensor(std.size()).normal_()最好不要这样写,能避免的话尽量避免。不要写if else判断语句。
比如写成这样:
如果避免不了的话,(⊙o⊙)…,可能转出来的网络就有问题。
参考资料
Pytorch 1.0 Tracer Warning: Converting a tensor to a Python index might cause the trace to be incorrect
总结
以上是生活随笔为你收集整理的Pytorch转ONNX采坑记:Converting a tensor to a Python boolean might cause the trace to be incorrect. We...的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 如何将Pytorch生成的模型进行CPU
- 下一篇: 使用栈结构实现中缀转后缀算法(pytho