I trained my model in google colab with GPU and export it to my google drive:
learn.export(‘/content/gdrive/My Drive/md’)
And later it can be loaded in google colab:
learn2 = load_learner(‘/content/gdrive/My Drive/’,‘md’)
But when I tried to do the same in my PC with CPU only after downloaded the model file, it failed:
learn2 = load_learner(‘./analyics’,‘md’)
File "F:\mydoc\git\test.py", line 165, in <module>
load_learner('F:/mydoc/git/analyics','md'),
File "E:\program\anaconda3\lib\site-packages\fastai\basic_train.py", line 621, in load_learner
state = torch.load(source, map_location='cpu') if defaults.device == torch.device('cpu') else torch.load(source)
File "E:\program\anaconda3\lib\site-packages\torch\serialization.py", line 586, in load
with _open_zipfile_reader(f) as opened_zipfile:
File "E:\program\anaconda3\lib\site-packages\torch\serialization.py", line 246, in __init__
super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer))
AttributeError: 'WindowsPath' object has no attribute 'tell'
If I load another model Iexported several months ago (In March), it succeeded
learn3 = load_learner(‘./analyics’,‘old_md’)
E:\program\anaconda3\lib\site-packages\torch\serialization.py:657: SourceChangeWarning: source code of class 'torch.nn.modules.loss.MSELoss' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
E:\program\anaconda3\lib\site-packages\torch\serialization.py:657: SourceChangeWarning: source code of class 'torch.nn.modules.container.ModuleList' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
E:\program\anaconda3\lib\site-packages\torch\serialization.py:657: SourceChangeWarning: source code of class 'torch.nn.modules.linear.Linear' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
E:\program\anaconda3\lib\site-packages\torch\serialization.py:657: SourceChangeWarning: source code of class 'torch.nn.modules.activation.ReLU' has changed. you can retrieve the original source code by accessing the object's source attribute or set `torch.nn.Module.dump_patches = True` and use the patch tool to revert the changes.
warnings.warn(msg, SourceChangeWarning)
I can see the different behavior is the new version uses zipfile while the old one doesn’t:
with _open_file_like(f, 'rb') as opened_file:
if _is_zipfile(opened_file):
with _open_zipfile_reader(f) as opened_zipfile:
if _is_torchscript_zip(opened_zipfile):
warnings.warn("'torch.load' received a zip file that looks like a TorchScript archive"
" dispatching to 'torch.jit.load' (call 'torch.jit.load' directly to"
" silence this warning)", UserWarning)
return torch.jit.load(f)
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
How to fix it? Or can we export with the legacy format?