-
Notifications
You must be signed in to change notification settings - Fork 13
/
train.py
89 lines (72 loc) · 2.93 KB
/
train.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import sys
import os
import tensorflow as tf
# import mlflow
sys.path.insert(0, os.path.abspath(os.path.join(
os.path.dirname(__file__), '../scripts')))
# sys.path.append(os.path.abspath(os.path.join('../scripts')))
from scripts.data_generator import make_audio_gen
from scripts.train import train
from scripts.models import model_2
from scripts.char_map import char_map, index_map
from scripts.plot import plot_hist
# model_name = "rnn"
# plot_hist(model_name)
# gpus = tf.config.list_physical_devices('GPU')
# if gpus:
# # Restrict TensorFlow to only allocate 1GB of memory on the first GPU
# try:
# tf.config.set_logical_device_configuration(
# gpus[0],
# [tf.config.LogicalDeviceConfiguration(memory_limit=20000)])
# logical_gpus = tf.config.list_logical_devices('GPU')
# print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
# except RuntimeError as e:
# # Virtual devices must be set before GPUs have been initialized
# print(e)
if __name__ == '__main__':
TRAIN_CORPUS = "./notebooks/valid2_corpus.json"
VALID_CORPUS = "./notebooks/valid2_corpus.json"
# VALID_CORPUS = "data_stbbl/valid_corpus.json"
MFCC_DIM = 13
SPECTOGRAM = False
MODEL_NAME = "rnn1"
################ Reminder MINI_BATCH_SIZE=250 in previous notebooks
MINI_BATCH_SIZE = 7
SORT_BY_DURATION=False
MAX_DURATION = 10.0
audio_gen = make_audio_gen(TRAIN_CORPUS, VALID_CORPUS, spectrogram=False, mfcc_dim=MFCC_DIM,
minibatch_size=MINI_BATCH_SIZE, sort_by_duration=SORT_BY_DURATION,
max_duration=MAX_DURATION)
# add the training data to the generator
audio_gen.load_train_data()
audio_gen.load_validation_data()
EPOCHS = 5
MODEL_NAME = "rnn2"
params = {'input_dim':13,
'filters':200,
'kernel_size':11,
'conv_stride':2,
'conv_border_mode':'valid',
'units':250,
'activation':'relu',
'dropout_rate':0.4,}
model = model_2(input_dim=13,
filters=200,
kernel_size=11,
conv_stride=2,
conv_border_mode='valid',
units=250,
activation='relu',
dropout_rate=0.4,
number_of_layers=5,
output_dim=len(char_map)+1)
train(audio_gen, input_to_softmax=model, model_name=MODEL_NAME, epochs=EPOCHS, minibatch_size=MINI_BATCH_SIZE)
plot_hist('rnn2')
# with open("metrics.txt", 'w') as outfile:
# outfile.write("model losses: %2.1f%%\n" % hist.losses[EPOCHS-1])
# mlflow.log_param('model_parameters', params)
# mlflow.log_param('input_shape', 13)
# mlflow.log_param('input_rows', 13)
# mlflow.log_param('mini batch size', MINI_BATCH_SIZE)
# mlflow.sklearn.save_model(model, "model")