torch.jit(2)—— 使用时的注意事项及常见报错原因

注意事项

  1. 函数的默认参数如果不是tensor的话,需要指定类型

  2. list中元素默认为tensor,如果不是,也要指定类型

常见报错

ValueError: substring not found

forward函数中不允许出现中文注释

Module is not iterable(大概是这样的错误)

不支持模型遍历及对模型取下标的操作

torch.jit.frontend.UnsupportedNodeError: Dict aren’t supported

forward 函数里初始化字典,由 a={} 改成 a=dict(),不过dict类型尽量不要在forward中使用,容易出错

torch.jit.frontend.UnsupportedNodeError: continue statements aren’t supported

不支持continue

torch.jit.frontend.UnsupportedNodeError: try blocks aren’t supported

不支持try-except

Unknown builtin op: aten::Tensor

不能使用torch.Tensor(),如果是把python中的int,float等类型转成tensor可以使用torch.tensor()
如果是张量拼接尽量使用torch.cat

你可能感兴趣的:(torch.jit(2)—— 使用时的注意事项及常见报错原因)