torch.jit.trace TracerWarning mute技巧
在使用torch.jit.trace时,经常会碰到如下warning:
TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can’t record the data flow of Python values,so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
当然这些warning,可能并不会在c++调用时产生错误,权作洁癖吧。
此博客汇总了个人尝试过的一些warning的破解方式:
1.慎用tensor.shape/torch.size()
1.1 生成新的tensor
如下:
y=x.new(x.size())
产生如下错误: