The difference of. Pt,. PTH,. Pkl and the way to save the model

we often see pytorch model files with the suffixes.pt,.pth,.pkl. Is there any format difference between these model files?It’s not really a difference in format, it’s just a difference in suffix (that’s all), some people prefer the.pt suffix to the.pth or.pkl suffix when using the torch. Save () function to save model files. There is no difference in the model files saved with the same torch.save () statement.

in pytorch’s official documentation/code, useful. Pt, useful. PTH. The general practice is to use.pth, but there seems to be more.pt in the official documentation, and officials don’t care much about using one.

save:

torch. Save (model.state_dict(), mymodel.pth)# only saves model weight parameters, not model structure

call:

model = My_model(*args, **kwargs) # My_model
model.load_state_dict(torch. Load (mymodel. PTH))#
model.eval()

)

save:

torch. Save (model, mymodel.pth)# save the entire model state

call:

model=torch. Load (mymodel.pth)# there is no need to reconstruct the model structure, just load
model.eval()

Read More: