Not able to load pre trained weights of yolov7 which is best.pt

username: Kuchchi
cooked: <p>Python version = 3.8.10<br>
torch version = 2.2.0+cu118<br>
ModuleNotFoundError Traceback (most recent call last) Cell In[4], <a>line 1</a> ----&gt; <a>1</a> mm = torch.load(‘best.pt’) File [c:\Users\xyz\Projects\UIDAI\py\lib\site-packages\torch\serialization.py:1026](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1026), in load(f, map_location, pickle_module, weights_only, mmap, **pickle_load_args) [1024](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1024) except RuntimeError as e: [1025](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1025) raise pickle.UnpicklingError(UNSAFE_MESSAGE + str(e)) from None → [1026](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1026) return _load(opened_zipfile, [1027](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1027) map_location, [1028](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1028) pickle_module, [1029](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1029) overall_storage=overall_storage, [1030](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1030) **pickle_load_args) [1031](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1031) if mmap: [1032](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1032) raise RuntimeError("mmap can only be used with files saved with " [1033](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1033) "`torch.save(_use_new_zipfile_serialization=True), " [1034](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1034) “please torch.save your checkpoint with this option in order to use mmap.”) File [c:\Users\xyz\Projects\UIDAI\py\lib\site-packages\torch\serialization.py:1438](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1438), in _load(zip_file, map_location, pickle_module, pickle_file, overall_storage, **pickle_load_args) [1436](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1436) unpickler = UnpicklerWrapper(data_file, **pickle_load_args) [1437](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1437) unpickler.persistent_load = persistent_load → [1438](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1438) result = unpickler.load() [1440](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1440) torch._utils._validate_loaded_sparse_tensors() [1441](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1441) torch._C._log_api_usage_metadata( [1442](file:///C:/Users/xyz/Projects/UIDAI/py/lib/site-packages/torch/serialization.py:1442) “torch.load.metadata”, {“serialization_id”: zip_file.serialization_id()}</p>
<p>…</p>
<p>—&gt; [21](file:///C:/Users/xyz/Desktop/VS/age/models/base.py:21) from backends.base import BaseStorage [24](file:///C:/Users/xyz/Desktop/VS/age/models/base.py:24) <strong>all</strong> = [‘Model’] [27](file:///C:/Users/xyz/Desktop/VS/age/models/base.py:27) DEFAULT_OPTIONS = (‘must_have’,) ModuleNotFoundError: No module named ‘backends’</p>

username: ptrblck
cooked: <p>Based on the stacktrace it seems you’ve saved the entire model via <code>torch.save(model, PATH)</code> instead of its <code>state_dict</code>.<br>
To restore the full model you would need to recreate the file structure and in particular the missing file containing the <code>backends</code>:</p>
<pre data-code-wrap="python"><code class="lang-python">—&gt; [21](file:///C:/Users/xyz/Desktop/VS/age/models/base.py:21) from backends.base import BaseStorage [24](file:///C:/Users/xyz/Desktop/VS/age/models/base.py:24) all = [‘Model’] [27](file:///C:/Users/xyz/Desktop/VS/age/models/base.py:27) DEFAULT_OPTIONS = (‘must_have’,) ModuleNotFoundError: No module named ‘backends’
</code></pre>

username: Kuchchi
cooked: <p>Thank You ! I got it <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>