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

分手后的思念是犯贱 2022-11-10 05:25 279阅读 0赞

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

  1. script_module = torch.jit.trace(model,x)

修改后:

  1. script_module = torch.jit.trace(model,x,strict=False)

究其原因是因为输出结果中出现了list或者dic

发表评论

表情:
评论列表 (有 0 条评论,279人围观)

还没有评论,来说两句吧...

相关阅读