使用torch.jit.trace导出模型时出现:
RuntimeError: Encountering a dict at the output of the tracer might cause the trace to be incorrect, this is only valid if the container structure does not change based on the module's inputs. Consider using a constant container instead (e.g. for `list`, use a `tuple` instead. for `dict`, use a `NamedTuple` instead). If you absolutely need this and know the side effects, pass strict=False to trace() to allow this behavior
按照提示的意思进行修改:
before:
script_module = torch.jit.trace(model,x)
修改后:
script_module = torch.jit.trace(model,x,strict=False)
究其原因是因为输出结果中出现了list或者dic
本文介绍在使用PyTorch的torch.jit.trace进行模型导出时遇到的RuntimeError错误及其解决方法。错误源于模型输出包含list或dict等容器结构,在不同输入下可能变化。文中提供了解决方案,通过设置strict参数为False来规避此问题。

408

被折叠的 条评论
为什么被折叠?



