I have received a running time in C++ on libtorch about torch::jit as:
terminate called after throwing an instance of ‘c10::Error’
what(): torch::jit::load() received a file from torch.save(), but torch::jit::load() can only load files produced by torch.jit.save()
Exception raised from load at /pytorch/torch/csrc/jit/serialization/import.cpp:347 (most recent call first):
but in the C++ code, I have only used torch::load and torch::save. I didnot use torch::jit::load()
Any suggestions on how to fix the issue please ?
terminate called after throwing an instance of ‘c10::Error’
what(): torch::jit::load() received a file from torch.save(), but torch::jit::load() can only load files produced by torch.jit.save()
Exception raised from load at /pytorch/torch/csrc/jit/serialization/import.cpp:347 (most recent call first):
Thank you very much ptrblck for the working example.
I double checked it and find that it is because I try to load the python “.pkl” file. It seems to me that in C++, only “.pt” file can be loaded and saved.
Did you get the error just by changing the file extension? I.e. is my code snippet also failing, if you use .pkl? pickle files are serialized Python objects, but I’m unsure if PyTorch checks the file extension or not.