java调用pytorch模型问题:PytorchStreamReader failed locating file constants.pkl: file not found
原因:需要使用 TorchScript 类型模型
将原来保存模型方法修改为:
serialized_model = torch.jit.script(model)
serialized_model.save('model.pt')
调用时又出现:
def forward(self, *inputs: Any, **kwargs: Any) -> Any:
~~~~~~~ <--- HERE
with torch.autograd.profiler.record_function("DataParallel.forward"):
原因:使用了 model = nn.DataParallel(model)
原因未知,暂时把这个去掉。