def __init__(self): super().__init__() warnings.simplefilter(action='ignore', category=FutureWarning) warnings.simplefilter(action='ignore', category=RuntimeWarning) warnings.filterwarnings(action="ignore", category=DeprecationWarning) # Deep Learning Models Configuration K.set_image_dim_ordering('th') print(K.image_data_format()) config = tf.ConfigProto(gpu_options=tf.GPUOptions(allow_growth=True)) session = tf.Session(config=config) tensorflow_backend.set_session(session) input_shape = (3, 10, 39) self.cnn_model_path = ('../CNN/best_model_all_cnnBass.h5') self.cnn_model = sequentialCNN(input_shape) self.cnn_model.load_weights(self.cnn_model_path) input_shape = (None, 98) n_hidden = 60 self.rnn_model_path = ('../RNN/best_model_all_rnnBass.h5') self.rnn_model = sequentialRNN(input_shape, 2, n_hidden) self.rnn_model.load_weights(self.rnn_model_path) self.batch_size = 512
listDB = [sys.argv[2]] else: listDB = ['Train', 'Validation'] for trainVal in listDB: for mode in listItems: print('Analizando mode {}'.format(mode)) midi_files = glob.glob('../MIDI/' + trainVal+'/'+mode+'/*.mid') num_files = len(midi_files) cnn_model_path = ('../CNN/best_model_' + mode+'_cnnBass.h5') cnn_model = sequentialCNN(input_shape) cnn_model.load_weights(cnn_model_path) input_shape = (None, 98) rnn_model_path = ('../RNN/best_model_' + mode+'_rnnBass.h5') rnn_model = sequentialRNN(input_shape,num_classes,n_hidden) rnn_model.load_weights(rnn_model_path) BM = BassManager() #for midi_path in midi_files: for i in range(num_files): if i > len(midi_files)-1: break midi_path = midi_files[i]
tensorflow_backend.set_session(session) # prepare callbacks callbacks = defineCallBacks(best_model) # load patches if only_test == 1: X_test, Y_test, classes = loadTestPatches(patches_file) else: X_train, Y_train, X_test, Y_test, classes = loadPatches(patches_file) num_classes = len(classes) input_shape = (1, X_test.shape[2], X_test.shape[3]) # CNN architecture defintion model = sequentialCNN(input_shape, droprate, num_classes, p, d, f) # training if do_train == 1 and only_test == 0: deleteWeights(best_model, last_model) history = model.fit(X_train, Y_train, batch_size=batch_size, epochs=epochs, verbose=1, validation_data=(X_test, Y_test), shuffle=True, callbacks=callbacks) model.save_weights(last_model) if plot_curves == 1: plotCurves(history)