-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from wingedsheep/feature/tidying_up
Feature/tidying up
- Loading branch information
Showing
22 changed files
with
806 additions
and
885 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,25 @@ | ||
from mgt.datamanagers.time_shift_data_manager import TimeShiftDataManager | ||
from mgt.datamanagers.remi_data_manager import RemiDataManager | ||
from mgt.models.transformer_model import TransformerModel | ||
|
||
import os | ||
import glob | ||
|
||
# Collect the midi paths | ||
midi_path = 'YOUR MIDI PATH' | ||
midi_path = os.path.join(os.path.dirname(__file__), midi_path) | ||
midis = glob.glob(midi_path + '*.mid') | ||
|
||
def run(): | ||
""" | ||
Example showing how to train a new model and generate new music with it. | ||
""" | ||
# Create the datamanager and prepare the data | ||
datamanager = RemiDataManager() | ||
dataset = datamanager.prepare_data(midis) | ||
|
||
midi_path = '../data/pop/' | ||
midi_path = os.path.join(os.path.dirname(__file__), midi_path) | ||
midis = glob.glob(midi_path + '*.mid') | ||
# Create and train the model | ||
model = TransformerModel(dataset.dictionary) | ||
model.train(x_train=dataset.data, epochs=50, stop_loss=0.1) | ||
|
||
time_shift_data_manager = TimeShiftDataManager() | ||
dataset = time_shift_data_manager.prepare_data(midis) | ||
# Generate music | ||
output = model.generate(1000) | ||
|
||
model = TransformerModel(dataset.dictionary) | ||
|
||
print("Created model. Starting training for 50 epochs.") | ||
model.train(x_train=dataset.data, epochs=50, stop_loss=0.1) | ||
|
||
# Generate music | ||
print("Generating music.") | ||
output = model.generate(1000) | ||
|
||
# Restore events from input data | ||
midi = time_shift_data_manager.to_midi(output) | ||
midi.save("result.midi") | ||
|
||
|
||
run() | ||
# Restore events from input data | ||
midi = datamanager.to_midi(output) | ||
midi.save("result.midi") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import numpy as np | ||
|
||
DRUM_INSTRUMENT = 128 | ||
|
||
DEFAULT_VELOCITY_BINS = np.linspace(0, 128, 32 + 1, dtype=np.int) | ||
DEFAULT_FRACTION = 16 | ||
DEFAULT_DURATION_BINS = np.arange(60, 3841, 60, dtype=int) | ||
DEFAULT_TEMPO_INTERVALS = [range(30, 90), range(90, 150), range(150, 210)] | ||
|
||
# parameters for outputItem | ||
DEFAULT_RESOLUTION = 480 |
Oops, something went wrong.