source + '.pt' utl_model = torch.load(modelfile, map_location=device) utl_param = utl_model['model'].model torch.save(utl_param.state_dict(), args.source + '.pth') own_state = utl_param.state_dict() print(len(own_state)) numpy_param = OrderedDict() for name in own_state: ...
通过以上步骤,你应该能够成功地将PyTorch的.pth文件转换为.pt文件,并确保转换后的模型文件可以在不同的环境中正常使用。