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

Output as *.mid file parameters for a generations of a chorale of length 100 #9

Closed
shyamalschandra opened this issue Jan 13, 2017 · 4 comments

Comments

@shyamalschandra
Copy link

shyamalschandra commented Jan 13, 2017

Hi,

I tried the following command after installing all the dependencies and the DeepBach code:

python3 deepBach.py -l 100 -o deepBach.mid

Here is the error I get:

Traceback (most recent call last):
  File "deepBach.py", line 847, in <module>
    main()
  File "deepBach.py", line 775, in main
    voice_ids=[0, 1, 2, 3])
  File "/Users/shyamalsuhanachandra/DeepBach/data_utils.py", line 582, in initialization
    metadatas=metadatas)
  File "/Users/shyamalsuhanachandra/DeepBach/data_utils.py", line 247, in make_dataset
    pickle.dump(dataset, open(dataset_name, 'wb'), pickle.HIGHEST_PROTOCOL)
FileNotFoundError: [Errno 2] No such file or directory: 'datasets/raw_dataset/bach_dataset.pickle'
I see the following code inside deepBach.py:

It seems that the dataset/raw_dataset/back_dataset.pickle is missing. Will you be providing that file in the future? If there is no file, it uses the constant BACH_DATASET instead and fails.

    if output_file:
        mf = midi.translate.music21ObjectToMidiFile(score)
        mf.open(output_file, 'wb')
        mf.write()
        mf.close()
        print("File " + output_file + " written")

I checked out the indexed_chorale_to_score function from data_utils library before this snippet of code above. The code for that function is the following:

def indexed_chorale_to_score(seq, pickled_dataset):
    _, _, _, index2notes, note2indexes, _ = pickle.load(open(pickled_dataset, 'rb'))
    num_pitches = list(map(len, index2notes))
    slur_indexes = list(map(lambda d: d[SLUR_SYMBOL], note2indexes))

    score = stream.Score()
    for voice_index, v in enumerate(seq):
        part = stream.Part(id='part' + str(voice_index))
        dur = 0
        f = note.Rest()
        for k, n in enumerate(v):
            # if it is a played note
            if not n == slur_indexes[voice_index]:
                # add previous note
                if dur > 0:
                    f.duration = duration.Duration(dur / SUBDIVISION)
                    part.append(f)

                dur = 1
                f = standard_note(index2notes[voice_index][n])
            else:
                dur += 1
        # add last note
        f.duration = duration.Duration(dur / SUBDIVISION)
        part.append(f)
        score.insert(part)
    return score

There is also a function that converts the score into midi that uses the output of the previous function for the score variable on line 55 of deepBach.py. Do I need to make any mods?

def music21ObjectToMidiFile(music21Object):
    '''
    Either calls streamToMidiFile on the music21Object or
    puts a copy of that object into a Stream (so as
    not to change activeSites, etc.) and calls streamToMidiFile on
    that object.
    '''
    classes = music21Object.classes
    if 'Stream' in classes:
        return streamToMidiFile(music21Object)
    else:
        m21ObjectCopy = copy.deepcopy(music21Object)
        s = stream.Stream()
        s.insert(0, m21ObjectCopy)
        return streamToMidiFile(s) 

What should I do? Can you provide the pretrained dataset or a dataset of MIDIs?

@Ghadjeres
Copy link
Owner

Default dataset is the Bach Chorales dataset obtained from music21 by corpus.getBachChorales function.

For the moment, create the 'datasets/raw_dataset' folders in DeepBach folder. Calling the program should preprocess, pickle and save the Bach Chorales dataset at location BACH_DATASET

Pickled datasets as well as pretrained models will be available soon

@shyamalschandra
Copy link
Author

I couldn't find the Bach Chorales dataset from music21. Do you have the links?

@Ghadjeres
Copy link
Owner

Please see function music21.corpus.getBachChorales(fileExtensions='xml')
http://web.mit.edu/music21/doc/moduleReference/moduleCorpus.html

@bzamecnik
Copy link
Contributor

Note that the pre-trained model and pre-processed dataset is already available for download:

See the README. Get it from Dropbox manually or have it downloaded/extracted by a script:

./download_pretrained_data.sh

Since pre-processing all the chorales from music21 takes about an hour this might be good for a quick start.

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

3 participants