Size mismatch for model

Andile_Zungu: <p>i trained the best model on this repo <a href="https://github.com/gastruc/osv5m" class="inline-onebox" rel="noopener nofollow ugc">GitHub - gastruc/osv5m</a> now i am trying to test the model after saving it and i am getting a size mismatch error<br>
This is the error<br>
This is the error<br>
/usr/local/lib/python3.10/dist-packages/torch/nn/init.py:511: UserWarning: Initializing zero-element tensors is a no-op<br>
warnings.warn(“Initializing zero-element tensors is a no-op”)<br>
/content/osv5m-main/models/losses.py:54: FutureWarning: You are using <code>torch.load</code> with <code>weights_only=False</code> (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See md#untrusted-models for more details). In a future release, the default value for <code>weights_only</code> will be flipped to <code>True</code>. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via <code>torch.serialization.add_safe_globals</code>. We recommend you start setting <code>weights_only=True</code> for any use case where you don’t have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.<br>
self.matrixes = torch.load(join(data_path, “quadtree_matrixes.pt”))<br>
/content/osv5m-main/models/losses.py:55: FutureWarning: You are using <code>torch.load</code> with <code>weights_only=False</code> (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See .md#untrusted-models for more details). In a future release, the default value for <code>weights_only</code> will be flipped to <code>True</code>. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via <code>torch.serialization.add_safe_globals</code>. We recommend you start setting <code>weights_only=True</code> for any use case where you don’t have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.<br>
self.dicts = torch.load(join(data_path, “quadtree_dicts.pt”))<br>
/content/osv5m-main/models/losses.py:56: FutureWarning: You are using <code>torch.load</code> with <code>weights_only=False</code> (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See .md#untrusted-models for more details). In a future release, the default value for <code>weights_only</code> will be flipped to <code>True</code>. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via <code>torch.serialization.add_safe_globals</code>. We recommend you start setting <code>weights_only=True</code> for any use case where you don’t have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.<br>
self.id_to_quad = torch.load(join(data_path, “id_to_quad_10_1000.pt”))<br>
Error executing job with overrides: [‘+pt_model_path=${hydra:runtime.config_sources}’]<br>
Traceback (most recent call last):<br>
File “/content/osv5m-main/test.py”, line 78, in main<br>
) = hydra_boilerplate(cfg)<br>
File “/content/osv5m-main/test.py”, line 36, in hydra_boilerplate<br>
trainer, model = load_model(cfg, dict_config, cfg.wandb_id)<br>
File “/content/osv5m-main/test.py”, line 29, in load_model<br>
model = Geolocalizer.load_from_checkpoint(cfg.checkpoint, cfg=cfg.model)<br>
File “/usr/local/lib/python3.10/dist-packages/pytorch_lightning/utilities/model_helpers.py”, line 125, in wrapper<br>
return self.method(cls, *args, **kwargs)<br>
File “/usr/local/lib/python3.10/dist-packages/pytorch_lightning/core/module.py”, line 1582, in load_from_checkpoint<br>
loaded = _load_from_checkpoint(<br>
File “/usr/local/lib/python3.10/dist-packages/pytorch_lightning/core/saving.py”, line 91, in _load_from_checkpoint<br>
model = _load_state(cls, checkpoint, strict=strict, **kwargs)<br>
File “/usr/local/lib/python3.10/dist-packages/pytorch_lightning/core/saving.py”, line 187, in _load_state<br>
keys = obj.load_state_dict(checkpoint[“state_dict”], strict=strict)<br>
File “/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py”, line 2584, in load_state_dict<br>
raise RuntimeError(<br>
RuntimeError: Error(s) in loading state_dict for Geolocalizer:<br>
size mismatch for model.mid.classif.7.weight: copying a param with shape torch.Size([1, 512]) from checkpoint, the shape in current model is torch.Size([0, 512]).<br>
size mismatch for model.mid.classif.7.bias: copying a param with shape torch.Size([1]) from checkpoint, the shape in current model is torch.Size([0]).<br>
size mismatch for model.mid.reg.7.weight: copying a param with shape torch.Size([2, 512]) from checkpoint, the shape in current model is torch.Size([0, 512]).<br>
size mismatch for model.mid.reg.7.bias: copying a param with shape torch.Size([2]) from checkpoint, the shape in current model is torch.Size([0]).</p>
<p>Set the environment variable HYDRA_FULL_ERROR=1 for a complete stack trace.</p>

ptrblck: <p>Based on the error message it seems your model contains empty parameters (i.e. with a shape of <code>0</code>) and you would need to narrow down why these parameters are empty and how they are initialized making sure they have the same shape as in the <code>state_dict</code>.</p>