Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: Missing key(s) in state_dict occurred #1

Open
kj4483 opened this issue Oct 31, 2024 · 0 comments
Open

RuntimeError: Missing key(s) in state_dict occurred #1

kj4483 opened this issue Oct 31, 2024 · 0 comments

Comments

@kj4483
Copy link

kj4483 commented Oct 31, 2024

Hi, I am using the phasefinder package and while fetching model weights, I am getting an error that state_dict is missing a key, leaving me with an issue.

I tried removing the weights_only=True argument and got the same error.

Environment


OS: Ubuntu 20.04
Python: 3.10.0

dependencies
phasefinder=0.0.3
torch=2.5.0
torchaudio=2.6.0

Code


from phasefinder import Phasefinder

pf = Phasefinder()

# audio_path = "../utils/test.mp3"

# beat_times, bpm = pf.predict(audio_path, include_bpm=True)

# print(beat_times, bpm)

Log


Model weights already exist.

RuntimeError Traceback (most recent call last)
Cell In[8], line 3
1 from phasefinder import Phasefinder
----> 3 pf = Phasefinder()
5 # audio_path = "../utils/test.mp3"
6
7 # beat_times, bpm = pf.predict(audio_path, include_bpm=True)
8
9 # print(beat_times, bpm)

File /home/oem/anaconda3/envs/oncon/lib/python3.10/site-packages/phasefinder/predictor.py:33, in Phasefinder.init(self, modelname, device, quiet, attention)
31 else:
32 self.device = torch.device(device)
---> 33 self.load_model()

File /home/oem/anaconda3/envs/oncon/lib/python3.10/site-packages/phasefinder/predictor.py:41, in Phasefinder.load_model(self)
38 else:
39 self.model = PhasefinderModelNoattn()
---> 41 self.model.load_state_dict(torch.load(self.model_path, map_location=torch.device(self.device), weights_only=True))
42 self.model = self.model.to(self.device)
43 self.model.eval()

File /home/oem/anaconda3/envs/oncon/lib/python3.10/site-packages/torch/nn/modules/module.py:2584, in Module.load_state_dict(self, state_dict, strict, assign)
2576 error_msgs.insert(
2577 0,
2578 "Missing key(s) in state_dict: {}. ".format(
2579 ", ".join(f'"{k}"' for k in missing_keys)
2580 ),
2581 )
2583 if len(error_msgs) > 0:
-> 2584 raise RuntimeError(
2585 "Error(s) in loading state_dict for {}:\n\t{}".format(
2586 self.class.name, "\n\t".join(error_msgs)
2587 )
2588 )
2589 return _IncompatibleKeys(missing_keys, unexpected_keys)

RuntimeError: Error(s) in loading state_dict for PhasefinderModelNoattn:
Missing key(s) in state_dict: "tcn_beat.network.0.conv1.buffer", "tcn_beat.network.0.conv2.buffer", "tcn_beat.network.1.conv1.buffer", "tcn_beat.network.1.conv2.buffer", "tcn_beat.network.2.conv1.buffer", "tcn_beat.network.2.conv2.buffer", "tcn_beat.network.3.conv1.buffer", "tcn_beat.network.3.conv2.buffer", "tcn_beat.network.4.conv1.buffer", "tcn_beat.network.4.conv2.buffer", "tcn_beat.network.5.conv1.buffer", "tcn_beat.network.5.conv2.buffer", "tcn_beat.network.6.conv1.buffer", "tcn_beat.network.6.conv2.buffer", "tcn_beat.network.7.conv1.buffer", "tcn_beat.network.7.conv2.buffer", "tcn_beat.network.8.conv1.buffer", "tcn_beat.network.8.conv2.buffer", "tcn_beat.network.9.conv1.buffer", "tcn_beat.network.9.conv2.buffer", "tcn_beat.network.10.conv1.buffer", "tcn_beat.network.10.conv2.buffer", "tcn_beat.network.11.conv1.buffer", "tcn_beat.network.11.conv2.buffer", "tcn_beat.network.12.conv1.buffer", "tcn_beat.network.12.conv2.buffer", "tcn_beat.network.13.conv1.buffer", "tcn_beat.network.13.conv2.buffer", "tcn_beat.network.14.conv1.buffer", "tcn_beat.network.14.conv2.buffer", "tcn_beat.network.15.conv1.buffer", "tcn_beat.network.15.conv2.buffer".

@kj4483 kj4483 changed the title Error for loading model RuntimeError: Missing key(s) in state_dict occurred Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant