如何在pytorch中使用预训练模型.pth?

how to use pretrained model .pth in pytorch?

我有一个问题,如何使用保存的预训练模型。例如,我有一个模型,我用我拥有的数据集训练它,然后用 .pth 扩展名保存它。如何使用文件 .pth 测试新图像。谢谢

你可以将a.pt/h里面的参数加载到这样的模型中:

# initialize a model with the same architecture as the model which parameters you saved into the .pt/h file
model = Model()

# load the parameters into the model
model.load_state_dict(torch.load("parameters.pth"))