wvsharber / BeatMapSynthesizer

Automatic Beat Saber mapper for custom songs
MIT License
70 stars 15 forks source link

KeyError when using segmented_HMM #41

Closed nbanyan closed 4 years ago

nbanyan commented 4 years ago

I don't know if this is related to the FileNotFoundError I get when using other models.

(base) D:\Downloads\Utilities\BeatMapSynthesizer-master>python beatmapsynth.py "Music/Ehrling - Sthlm-Sunset.wav" "Sthlm Sunset by Ehrling" Hard segmented_HMM E:\anaconda3\lib\site-packages\pydub\utils.py:170: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning) Loading Song... Song loaded successfully! Mapping with segmented Hidden Markov Model... Traceback (most recent call last): File "beatmapsynth.py", line 719, in beat_map_synthesizer(args.song_path, args.song_name, args.difficulty, args.model, args.k, args.version) File "beatmapsynth.py", line 48, in beat_map_synthesizer segmented_HMM_mapper(song_path, song_name, difficulty, k = k, version = version) File "beatmapsynth.py", line 330, in segmented_HMM_mapper notes_list = segmented_HMM_notes_writer(y, sr, k, difficulty, version) File "beatmapsynth.py", line 468, in segmented_HMM_notes_writer preds = segment_predictions(segments_df, MC) File "beatmapsynth.py", line 434, in segment_predictions pred = HMM_model.walk(init_state = tuple(preds.iloc[-5:, 0])) File "E:\anaconda3\lib\site-packages\markovify\chain.py", line 137, in walk return list(self.gen(init_state)) File "E:\anaconda3\lib\site-packages\markovify\chain.py", line 126, in gen next_word = self.move(state) File "E:\anaconda3\lib\site-packages\markovify\chain.py", line 112, in move choices, weights = zip(*self.model[state].items()) KeyError: ('0,2,0,7,1,3,0,7,999,999,999,999', '0,0,0,6,999,999,999,999,999,999,999,999', '0,1,2,5,1,2,0,6,999,999,999,999', '0,2,0,7,999,999,999,999,999,999,999,999', '999,999,999,999,1,3,1,3,999,999,999,999')

wvsharber commented 4 years ago

Hi!

This is a known error that pops up occasionally. I made a hot fix for it, but I haven't pushed that change to GitHub yet. The easiest thing to do is try running it again, that usually fixes the problem. If you're finding that it keeps happening, you might try changing the value for K.

Basically what is happening is the song segmentation is looking to use the last five "moves" to produce a new sequence for the next song segment. If the model hasn't seen the previous five moves before, then it doesn't know what to do and gives this error. Since there is some randomness to the mapping, usually rerunning will produce a new map that doesn't cause the error.

Hope that helps and I'll try to push those changes soon.

nbanyan commented 4 years ago

Running on an ogg seems consistent, but it annoyingly deletes the ogg file. This error seems to be most common with the 'segmented_HMM' model when using wav or mp3 while using ogg seems reliable regardless of the model. Using a non-'5' value for -k also seems reliable. Thank you!

wvsharber commented 4 years ago

An update on this original issue: I added some code that should keep BeatMapSynth from failing if the KeyError occurs. It might cause some weird mappings, but I don't see another way around it right now.