Ghadjeres/DeepBach

KeyError: File foobar.mid skipped

Opened this issue · 4 comments

Some correct MIDI files get skipped while making the pickle dataset.

We'll have to figure out in which case it happens.

Example failing file: bach_kunst_der_fuge_1_(c)onclassical.mid

What's the error?

KeyError is thrown in the inner look of make_dataset():

for semi_tone in range(min_transposition, max_transposition + 1):
                    try:
                        # necessary, won't transpose correctly otherwise
                        interval_type, interval_nature = interval.convertSemitoneToSpecifierGeneric(semi_tone)
                        transposition_interval = interval.Interval(str(interval_nature) + interval_type)
                        chorale_tranposed = chorale.transpose(transposition_interval)
                        inputs = chorale_to_inputs(chorale_tranposed, voice_ids=voice_ids, index2notes=index2notes,
                                                   note2indexes=note2indexes
                                                   )
                        md = []
                        if metadatas:
                            for metadata in metadatas:
                                # todo add this
                                if metadata.is_global:
                                    pass
                                else:
                                    md.append(metadata.evaluate(chorale_tranposed))
                        X.append(inputs)
                        X_metadatas.append(md)
                    except KeyError:
                        print('KeyError: File ' + chorale_file + ' skipped')
                    except FloatingKeyException:
                        print('FloatingKeyException: File ' + chorale_file + ' skipped')

So far I haven't debugged it, so I'm note sure from exactly where it raises. In the error handling the file is just skipped. This leaves a significant percentage of files in my dataset unusable from training.

I'll to to investigate it later.

This is caused by the music21 key analyzer (in KeyMetadata).
Maybe you need to only consider the TickMetadata (and the Fermata Metadata if your files contain some, which is not possible but I'm not sure if your files are in MIDI format). See #32.
Otherwise, knowing why the key analyzer doesn't work on your file might be more tricky...

Aah... OK. TickMetadata should be enough, possibly KeyMetadata. No fermatas. These are just some transcribed or recorded MIDI files, not MusicXML. Actually from http://kunstderfuge.com. Just selecting extraction of less metadata might be a quickfix, then I can try to debug the root cause. Thanks!