Anto Setiawan
Anto Setiawan

Reputation: 13

how to use pretrained model .pth in pytorch?

I have one question, how to use the saved pre-trained model. For example, I have a model and I train it with the dataset I have and then I save it with the .pth extension. how to use file .pth to test new image. thanks

Upvotes: 1

Views: 7953

Answers (1)

Theodor Peifer
Theodor Peifer

Reputation: 3496

You can load the parameters inside from a.pt/h into a model like this:

# 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"))

Upvotes: 3

Related Questions