Load a saved model on Pytorch AttributeError: 'dict' object has no attribute 'seek'
I trained a model, and I saved the best one, with:
# Store params at the best validation accuracy
if save_param and accuracy_star &gt; best_accuracy:
    torch.save({'vgg_a':nets[0].state_dict(),'classifier':nets[3].state_dict()}, f&quot;{model_name}_best_test.pth&quot;)

So, at the end of the training I downloaded this &quot;federated_mnist_best_test.pth&quot; on my local computer.
Now, I created a new notebook on google colab, and I tried din this way to upload the model:
from google.colab import files
uploaded = files.upload()

Inside uploaded I put my .pth file, and then:
state_dict = torch.load(uploaded)

gives me this error:
AttributeError: 'dict' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.


After having called uploaded = files.upload() (usage examples can be found on this notebook) and interacted with the file explorer, the file will be uploaded to google Colaboratory's temporary file system.
You can find it by looking at the side panel:

At this point, the file has been uploaded to the file system but hasn't yet been loaded on the notebook. You need to load the file using its name (e.g. if the name is best_test.pth):
state_dict = torch.load('best_test.pth')

