Add default folder and add history storing feature

This commit is contained in:
CezaryPukownik 2020-06-16 10:17:50 +02:00
parent a6fb2e6e73
commit 8d611ac140
5 changed files with 10 additions and 2 deletions

View File

@ -0,0 +1 @@
In this folder generated music will be stored

View File

@ -0,0 +1,2 @@
Place in this directory folders with midi.
Each folder represent a source for making trainig sets

1
project/models/readme.md Normal file
View File

@ -0,0 +1 @@
In this directory trained models will be stored

View File

@ -4,6 +4,7 @@ import pickle
import keras import keras
import argparse import argparse
import warnings import warnings
import pandas as pd
from model import Seq2SeqModel from model import Seq2SeqModel
from extract import make_folder_if_not_exist from extract import make_folder_if_not_exist
@ -42,6 +43,7 @@ def train_models(model_workflow):
if not INSTRUMENT or INSTRUMENT == instrument: if not INSTRUMENT or INSTRUMENT == instrument:
data_path = os.path.join('training_sets', EXPERIMENT_NAME, instrument.lower() + '_data.pkl') data_path = os.path.join('training_sets', EXPERIMENT_NAME, instrument.lower() + '_data.pkl')
model_path = os.path.join('models', EXPERIMENT_NAME, f'{instrument.lower()}_model.h5') model_path = os.path.join('models', EXPERIMENT_NAME, f'{instrument.lower()}_model.h5')
history_path = os.path.join('models', EXPERIMENT_NAME, f'{instrument.lower()}_history.csv')
x_train, y_train, _, bars_in_seq = pickle.load(open(data_path,'rb')) x_train, y_train, _, bars_in_seq = pickle.load(open(data_path,'rb'))
@ -52,8 +54,9 @@ def train_models(model_workflow):
model = Seq2SeqModel(x_train, y_train, LATENT_DIM, ENCODER_DROPOUT, DECODER_DROPOUT, bars_in_seq) model = Seq2SeqModel(x_train, y_train, LATENT_DIM, ENCODER_DROPOUT, DECODER_DROPOUT, bars_in_seq)
print(f'Training: {instrument}') print(f'Training: {instrument}')
model.fit(BATCH_SIZE, EPOCHS, callbacks=[]) history = model.fit(BATCH_SIZE, EPOCHS, callbacks=[])
make_folder_if_not_exist(os.path.join('models', EXPERIMENT_NAME)) make_folder_if_not_exist(os.path.join('models', EXPERIMENT_NAME))
pd.DataFrame(history.history).to_csv(history_path, mode='a', header=False)
model.save(model_path) model.save(model_path)
found = True found = True

View File

@ -0,0 +1 @@
In this directory generated training sets will be stored