UnpicklingError: invalid load key, '\x0a'

Viewed 3722
model_save_name = 'classifier.pt'
path = F"/content/gdrive/My Drive/Others/{model_save_name}"

model.load_state_dict(torch.load(path), strict = False)

trying to load into model state_dict from path. Later the same model state_dict will be used for saving the checkpoint like torch.save(model.state_dict(), path)

Error Traceback:

UnpicklingError                           Traceback (most recent call last)
<ipython-input-69-7cb7940c24e3> in <module>()
----> 1 model.load_state_dict(torch.load(path), strict = False)

/usr/local/lib/python3.6/dist-packages/torch/serialization.py in load(f, map_location, pickle_module)
    356         f = open(f, 'rb')
    357     try:
--> 358         return _load(f, map_location, pickle_module)
    359     finally:
    360         if new_fd:

/usr/local/lib/python3.6/dist-packages/torch/serialization.py in _load(f, map_location, pickle_module)
    530             f.seek(0)
    531 
--> 532     magic_number = pickle_module.load(f)
    533     if magic_number != MAGIC_NUMBER:
    534         raise RuntimeError("Invalid magic number; corrupt file?")

UnpicklingError: invalid load key, '\x0a'.
1 Answers

Is the model saved using the same python version as the one trying to load. If not there have been some changes in pickle across versions. Also if this is not the case can you also post the torch.save() call you are making.

Related