使用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

 

更多推荐

Consider using a constant container instead (e.g. for `list`, use a `tuple` inst