How to inference on image using .pth model file

Do you know how the .pth file was created?
I.e. is it containing

  • a state_dict? In that case you would need to get the source code of the model definition, create a model instance and load the state_dict. Once this is done, you can pass the input tensor to the model to get the output.
  • a directly stored model? In that case, you would still need to get the source files and make sure they are in the same locations as described in the serialization docs. Note that this approach is not recommended, as it may break in various ways.
  • a scripted model? In that case you could load the model via torch.jit.load and pass the input tensor to the model to get the output.
1 Like