问题报错如下:
AttributeError Traceback (most recent call last)
Cell In[10], line 1
----> 1 model = torch.load('fruit30_pytorch_light.pth')
2 model = model.eval().to(device)
File E:\Anaconda\envs\pytorch\lib\site-packages\torch\serialization.py:712, in load(f, map_location, pickle_module, **pickle_load_args)
710 opened_file.seek(orig_position)
711 return torch.jit.load(opened_file)
--> 712 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
713 return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File E:\Anaconda\envs\pytorch\lib\site-packages\torch\serialization.py:1049, in _load(zip_file, map_location, pickle_module, pickle_file, **pickle_load_args)
1047 unpickler = UnpicklerWrapper(data_file, **pickle_load_args)
1048 unpickler.persistent_load = persistent_load
-> 1049 result = unpickler.load()
1051 torch._utils._validate_loaded_sparse_
pytorch中出现AttributeError: Can‘t get attribute ‘Net‘ on <module ‘__main__‘>错误
最新推荐文章于 2024-07-18 10:25:43 发布
本文解决了一个关于PyTorch模型加载时遇到的AttributeError问题。问题源于新环境中未能找到自定义的Net类,通过将Net类的定义包含在加载脚本中解决了该问题。

最低0.47元/天 解锁文章
894

被折叠的 条评论
为什么被折叠?



