2019-05-29 10:37:29 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2019-05-28 12:40:26 +02:00
|
|
|
import tensorflow as tf
|
|
|
|
import settings
|
|
|
|
from tensorflow.keras import layers
|
2019-05-30 11:23:34 +02:00
|
|
|
from keras.layers import Input, Dense, Conv2D, Flatten, LSTM, Dropout, TimeDistributed, RepeatVector, Activation, Bidirectional, Reshape
|
2019-05-28 12:40:26 +02:00
|
|
|
from keras.models import Model, Sequential
|
|
|
|
import numpy as np
|
2019-05-30 11:23:34 +02:00
|
|
|
import sys
|
2019-05-28 12:40:26 +02:00
|
|
|
import pickle
|
|
|
|
|
2019-05-30 12:36:59 +02:00
|
|
|
train_data_path = sys.argv[1]
|
|
|
|
save_model_path = sys.argv[2]
|
|
|
|
epochs = int(sys.argv[3])
|
2019-05-30 11:23:34 +02:00
|
|
|
|
|
|
|
model = Sequential()
|
|
|
|
model.add(LSTM(128,input_shape=(96, 128),return_sequences=True))
|
|
|
|
model.add(Dropout(0.3))
|
|
|
|
model.add(LSTM(512, return_sequences=True))
|
|
|
|
model.add(Dropout(0.3))
|
2019-05-30 12:36:59 +02:00
|
|
|
model.add(LSTM(128))
|
|
|
|
model.add(Dense(128))
|
|
|
|
model.add(Dropout(0.3))
|
|
|
|
model.add(Dense(128*96))
|
2019-05-30 11:23:34 +02:00
|
|
|
model.add(Activation('softmax'))
|
2019-05-30 12:36:59 +02:00
|
|
|
model.add(Reshape((96, 128)))
|
2019-05-30 11:23:34 +02:00
|
|
|
model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
|
|
|
|
|
|
|
|
# load training data
|
2019-05-30 12:36:59 +02:00
|
|
|
print('Traing Samples: {}'.format(train_data_path))
|
|
|
|
train_X = np.load(train_data_path)['arr_0']
|
2019-05-30 11:23:34 +02:00
|
|
|
|
|
|
|
# model training
|
2019-05-30 12:36:59 +02:00
|
|
|
model.fit(train_X, train_X, epochs=epochs, batch_size=32)
|
2019-05-30 11:23:34 +02:00
|
|
|
|
|
|
|
# save trained model
|
|
|
|
pickle_path = '{}.pickle'.format(save_model_path)
|
|
|
|
pickle.dump(model, open(pickle_path,'wb'))
|
|
|
|
print("Model save to {}".format(pickle_path))
|