def make_cmp(self): # File lists for the final cmp files (these are re-generated below to fit a precise numpy data array) self.nn_cmp_file_list = data_utils.prepare_file_path_list( self.file_id_list, self.out_feat_dir, self.cmp_ext) # self.nn_cmp_norm_file_list = data_utils.prepare_file_path_list(self.file_id_list, self.out_feat_dir_norm, # self.cmp_ext) # TODO: Get the delta and acceleration windows from the recipe file. acoustic_worker = AcousticComposition(delta_win=[-0.5, 0.0, 0.5], acc_win=[1.0, -2.0, 1.0]) # TODO: Lets try this at some point # if 'dur' in list(cfg.in_dir_dict.keys()) and cfg.AcousticModel: # acoustic_worker.make_equal_frames(dur_file_list, lf0_file_list, cfg.in_dimension_dict) acoustic_worker.prepare_nn_data(self.in_file_list_dict, self.nn_cmp_file_list, cfg.in_dimension_dict, cfg.out_dimension_dict) remover = SilenceRemover(n_cmp=cfg.cmp_dim, silence_pattern=cfg.silence_pattern, label_type=cfg.label_type, remove_frame_features=cfg.add_frame_features, subphone_feats=cfg.subphone_feats) remover.remove_silence( self.nn_cmp_file_list[0:cfg.train_file_number + cfg.valid_file_number], self.inp_feat_file_list[0:cfg.train_file_number + cfg.valid_file_number], self.nn_cmp_file_list[0:cfg.train_file_number + cfg.valid_file_number]) # save to itself
def main(cfg): ################################################### ########## User configurable variables ############ ################################################### work_dir = cfg.work_dir data_dir = cfg.data_dir inp_feat_dir = cfg.inp_feat_dir out_feat_dir = cfg.out_feat_dir model_dir = cfg.model_dir stats_dir = cfg.stats_dir gen_dir = cfg.gen_dir ### Input-Output ### inp_dim = cfg.inp_dim out_dim = cfg.out_dim inp_file_ext = cfg.inp_file_ext out_file_ext = cfg.out_file_ext inp_norm = cfg.inp_norm out_norm = cfg.out_norm ### define train, valid, test ### train_file_number = cfg.train_file_number valid_file_number = cfg.valid_file_number test_file_number = cfg.test_file_number #### Train, valid and test file lists #### file_id_list = data_utils.read_file_list(cfg.file_id_scp) train_id_list = file_id_list[0:train_file_number] valid_id_list = file_id_list[train_file_number:train_file_number+valid_file_number] test_id_list = file_id_list[train_file_number+valid_file_number:train_file_number+valid_file_number+test_file_number] inp_train_file_list = data_utils.prepare_file_path_list(train_id_list, inp_feat_dir, inp_file_ext) out_train_file_list = data_utils.prepare_file_path_list(train_id_list, out_feat_dir, out_file_ext) inp_test_file_list = data_utils.prepare_file_path_list(test_id_list, inp_feat_dir, inp_file_ext) out_test_file_list = data_utils.prepare_file_path_list(test_id_list, out_feat_dir, out_file_ext) gen_test_file_list = data_utils.prepare_file_path_list(test_id_list, cfg.pred_feat_dir, out_file_ext) #### define model params #### inp_scaler = None out_scaler = None hidden_layer_type = cfg.hidden_layer_type hidden_layer_size = cfg.hidden_layer_size batch_size = cfg.batch_size training_algo = cfg.training_algo output_layer_type = cfg.output_layer_type loss_function = cfg.loss_function optimizer = cfg.optimizer num_of_epochs = cfg.num_of_epochs dropout_rate = cfg.dropout_rate json_model_file = cfg.json_model_file h5_model_file = cfg.h5_model_file ################################################### ########## End of user-defined variables ########## ################################################### #### Define keras models class #### keras_models = TrainKerasModels(inp_dim, hidden_layer_size, out_dim, hidden_layer_type, output_layer_type, dropout_rate, loss_function, optimizer) if cfg.NORMDATA: ### normalize train data ### if os.path.isfile(cfg.inp_stats_file) and os.path.isfile(cfg.out_stats_file): inp_scaler = data_utils.load_norm_stats(cfg.inp_stats_file, inp_dim, method=inp_norm) out_scaler = data_utils.load_norm_stats(cfg.out_stats_file, out_dim, method=out_norm) else: print('preparing train_x, train_y from input and output feature files...') train_x, train_y, train_flen = data_utils.read_data_from_file_list(inp_train_file_list, out_train_file_list, inp_dim, out_dim, sequential_training=cfg.sequential_training) print('computing norm stats for train_x...') inp_scaler = data_utils.compute_norm_stats(train_x, cfg.inp_stats_file, method=inp_norm) print('computing norm stats for train_y...') out_scaler = data_utils.compute_norm_stats(train_y, cfg.out_stats_file, method=out_norm) if cfg.TRAINMODEL: #### define the model #### if not cfg.sequential_training: keras_models.define_feedforward_model() elif cfg.stateful: keras_models.define_stateful_model(batch_size=batch_size) else: keras_models.define_sequence_model() #### load the data #### print('preparing train_x, train_y from input and output feature files...') train_x, train_y, train_flen = data_utils.read_data_from_file_list(inp_train_file_list, out_train_file_list, inp_dim, out_dim, sequential_training=cfg.sequential_training) #### norm the data #### data_utils.norm_data(train_x, inp_scaler, sequential_training=cfg.sequential_training) data_utils.norm_data(train_y, out_scaler, sequential_training=cfg.sequential_training) #### train the model #### print('training...') if not cfg.sequential_training: ### Train feedforward model ### keras_models.train_feedforward_model(train_x, train_y, batch_size=batch_size, num_of_epochs=num_of_epochs, shuffle_data=cfg.shuffle_data) else: ### Train recurrent model ### keras_models.train_sequence_model(train_x, train_y, train_flen, batch_size=batch_size, num_of_epochs=num_of_epochs, shuffle_data=cfg.shuffle_data, training_algo=training_algo) #### store the model #### keras_models.save_model(json_model_file, h5_model_file) if cfg.TESTMODEL: #### load the model #### keras_models.load_model(json_model_file, h5_model_file) #### load the data #### print('preparing test_x from input feature files...') test_x, test_flen = data_utils.read_test_data_from_file_list(inp_test_file_list, inp_dim) #### norm the data #### data_utils.norm_data(test_x, inp_scaler) #### compute predictions #### keras_models.predict(test_x, out_scaler, gen_test_file_list, cfg.sequential_training)
def main(): start_time = time.time() ################################################### ########## User configurable variables ############ ################################################### merlin_dir = "/group/project/cstr1/srikanth/test/merlin" exp_dir = os.path.join( merlin_dir, "egs/slt_arctic/s1/experiments/slt_arctic_demo/acoustic_model/") inp_dim = 425 out_dim = 187 data_dir = os.path.join(exp_dir, "data") inp_feat_dir = os.path.join(data_dir, 'nn_no_silence_lab_norm_' + str(inp_dim)) out_feat_dir = os.path.join(data_dir, 'nn_norm_mgc_lf0_vuv_bap_' + str(out_dim)) inp_file_ext = '.lab' out_file_ext = '.cmp' model_dir = os.path.join(exp_dir, 'keras_models') if not os.path.exists(model_dir): os.makedirs(model_dir) inp_norm = "MINMAX" out_norm = "MINMAX" stats_dir = os.path.join(exp_dir, 'keras_stats') if not os.path.exists(stats_dir): os.makedirs(stats_dir) #### Main switch variables #### NormData = False TrainModel = True TestModel = True demo_mode = True if demo_mode: train_file_number = 50 valid_file_number = 5 test_file_number = 5 else: train_file_number = 1000 valid_file_number = 66 test_file_number = 66 #### Train, valid and test file lists #### file_id_scp = os.path.join(data_dir, 'file_id_list_demo.scp') file_id_list = data_utils.read_file_list(file_id_scp) train_id_list = file_id_list[0:train_file_number] valid_id_list = file_id_list[train_file_number:train_file_number + valid_file_number] test_id_list = file_id_list[train_file_number + valid_file_number:train_file_number + valid_file_number + test_file_number] inp_train_file_list = data_utils.prepare_file_path_list( train_id_list, inp_feat_dir, inp_file_ext) out_train_file_list = data_utils.prepare_file_path_list( train_id_list, out_feat_dir, out_file_ext) inp_test_file_list = data_utils.prepare_file_path_list( test_id_list, inp_feat_dir, inp_file_ext) out_test_file_list = data_utils.prepare_file_path_list( test_id_list, out_feat_dir, out_file_ext) ### set to True if training recurrent models ### sequential_training = False stateful = False ### set to True if data to be shuffled ### shuffle_data = True #### define Model, train and evaluate #### if sequential_training: if demo_mode: hidden_layer_type = ['tanh', 'lstm'] hidden_layer_size = [512, 512] else: hidden_layer_type = [ 'tanh', 'tanh', 'tanh', 'tanh', 'lstm', 'lstm' ] hidden_layer_size = [1024, 1024, 1024, 1024, 512, 512] ### batch size: sentences batch_size = 25 training_algo = 1 else: hidden_layer_type = ['tanh', 'tanh', 'tanh', 'tanh', 'tanh', 'tanh'] hidden_layer_size = [1024, 1024, 1024, 1024, 1024, 1024] ### batch size: frames batch_size = 256 optimizer = 'adam' output_type = 'linear' loss_function = 'mse' num_of_epochs = 25 dropout_rate = 0.0 if sequential_training: combined_model_arch = 'RNN' + str(training_algo) else: combined_model_arch = 'DNN' combined_model_arch += '_' + str(len(hidden_layer_size)) combined_model_arch += '_' + '_'.join(map(str, hidden_layer_size)) combined_model_arch += '_' + '_'.join(map(str, hidden_layer_type)) nnets_file_name = '%s_%d_train_%d_%d_%d_%d_%d_model' \ %(combined_model_arch, int(shuffle_data), inp_dim, out_dim, train_file_number, batch_size, num_of_epochs) print 'model file : ' + nnets_file_name json_model_file = os.path.join(model_dir, nnets_file_name + '.json') h5_model_file = os.path.join(model_dir, nnets_file_name + '.h5') inp_stats_file = os.path.join( stats_dir, "input_%d_%s_%d.norm" % (int(train_file_number), inp_norm, inp_dim)) out_stats_file = os.path.join( stats_dir, "output_%d_%s_%d.norm" % (int(train_file_number), out_norm, out_dim)) inp_scaler = None out_scaler = None gen_dir = os.path.join(exp_dir, 'gen') pred_feat_dir = os.path.join(gen_dir, nnets_file_name) if not os.path.exists(pred_feat_dir): os.makedirs(pred_feat_dir) gen_test_file_list = data_utils.prepare_file_path_list( test_id_list, pred_feat_dir, out_file_ext) gen_wav_file_list = data_utils.prepare_file_path_list( test_id_list, pred_feat_dir, '.wav') ################################################### ########## End of user-defined variables ########## ################################################### #### Define keras models class #### keras_models = TrainKerasModels(inp_dim, hidden_layer_size, out_dim, hidden_layer_type, output_type, dropout_rate, loss_function, optimizer) if NormData: ### normalize train data ### if os.path.isfile(inp_stats_file): inp_scaler = data_utils.load_norm_stats(inp_stats_file, inp_dim, method=inp_norm) else: print 'preparing train_x from input feature files...' train_x, train_flen_x = data_utils.read_data_from_file_list( inp_train_file_list, inp_dim, False) print 'computing norm stats for train_x...' inp_scaler = data_utils.compute_norm_stats(train_x, inp_stats_file, method=inp_norm) if os.path.isfile(out_stats_file): out_scaler = data_utils.load_norm_stats(out_stats_file, out_dim, method=out_norm) else: print 'preparing train_y from output feature files...' train_y, train_flen_y = data_utils.read_data_from_file_list( out_train_file_list, out_dim, False) print 'computing norm stats for train_y...' out_scaler = data_utils.compute_norm_stats(train_y, out_stats_file, method=out_norm) if TrainModel: #### define the model #### if not sequential_training: keras_models.define_feedforward_model() elif stateful: keras_models.define_stateful_model() else: keras_models.define_sequence_model() #### load the data #### print( 'preparing train_x, train_y from input and output feature files...' ) train_x, train_y, train_flen = data_utils.read_data_from_file_list( inp_train_file_list, out_train_file_list, inp_dim, out_dim, sequential_training=sequential_training) #### norm the data #### print('normalising the data...') data_utils.norm_data(train_x, inp_scaler, sequential_training=sequential_training) data_utils.norm_data(train_y, out_scaler, sequential_training=sequential_training) #### train the model #### if not sequential_training: ### Train feedforward model ### keras_models.train_feedforward_model(train_x, train_y, batch_size=batch_size, num_of_epochs=num_of_epochs, shuffle_data=shuffle_data) else: ### Train recurrent model ### keras_models.train_sequence_model(train_x, train_y, train_flen, batch_size=batch_size, num_of_epochs=num_of_epochs, shuffle_data=shuffle_data, training_algo=training_algo) #### store the model #### keras_models.save_model(json_model_file, h5_model_file) if TestModel: #### load the model #### keras_models.load_model(json_model_file, h5_model_file) #### load the data #### print 'preparing test_x from input feature files...' test_x, test_flen = data_utils.read_test_data_from_file_list( inp_test_file_list, inp_dim) #### norm the data #### data_utils.norm_data(test_x, inp_scaler) #### compute predictions #### keras_models.predict(test_x, out_scaler, gen_test_file_list, sequential_training) (m, s) = divmod(int(time.time() - start_time), 60) print("--- Job completion time: %d min. %d sec ---" % (m, s))
def __init__(self, cfg): ################################################### ########## User configurable variables ############ ################################################### inp_feat_dir = cfg.inp_feat_dir out_feat_dir = cfg.out_feat_dir pred_feat_dir = cfg.pred_feat_dir inp_file_ext = cfg.inp_file_ext out_file_ext = cfg.out_file_ext ### Input-Output ### self.inp_dim = cfg.inp_dim self.out_dim = cfg.out_dim self.inp_norm = cfg.inp_norm self.out_norm = cfg.out_norm self.inp_stats_file = cfg.inp_stats_file self.out_stats_file = cfg.out_stats_file self.inp_scaler = None self.out_scaler = None #### define model params #### self.hidden_layer_type = cfg.hidden_layer_type self.hidden_layer_size = cfg.hidden_layer_size self.sequential_training = cfg.sequential_training self.stateful = cfg.stateful self.batch_size = cfg.batch_size self.seq_length = cfg.seq_length self.training_algo = cfg.training_algo self.shuffle_data = cfg.shuffle_data self.output_layer_type = cfg.output_layer_type self.loss_function = cfg.loss_function self.optimizer = cfg.optimizer self.rnn_params = cfg.rnn_params self.dropout_rate = cfg.dropout_rate self.num_of_epochs = cfg.num_of_epochs self.json_model_file = cfg.json_model_file self.h5_model_file = cfg.h5_model_file ### define train, valid, test ### train_file_number = cfg.train_file_number valid_file_number = cfg.valid_file_number test_file_number = cfg.test_file_number file_id_scp = cfg.file_id_scp test_id_scp = cfg.test_id_scp #### main processess #### self.NORMDATA = cfg.NORMDATA self.TRAINMODEL = cfg.TRAINMODEL self.TESTMODEL = cfg.TESTMODEL #### Generate only test list #### self.GenTestList = cfg.GenTestList ################################################### ####### End of user-defined conf variables ######## ################################################### #### Create train, valid and test file lists #### file_id_list = data_utils.read_file_list(file_id_scp) train_id_list = file_id_list[0: train_file_number] valid_id_list = file_id_list[train_file_number: train_file_number + valid_file_number + test_file_number] test_id_list = file_id_list[train_file_number + valid_file_number: train_file_number + valid_file_number + test_file_number] self.inp_train_file_list = data_utils.prepare_file_path_list(train_id_list, inp_feat_dir, inp_file_ext) self.out_train_file_list = data_utils.prepare_file_path_list(train_id_list, out_feat_dir, out_file_ext) self.inp_test_file_list = data_utils.prepare_file_path_list(valid_id_list, inp_feat_dir, inp_file_ext) self.out_test_file_list = data_utils.prepare_file_path_list(valid_id_list, out_feat_dir, out_file_ext) self.gen_test_file_list = data_utils.prepare_file_path_list(valid_id_list, pred_feat_dir, out_file_ext) if self.GenTestList: test_id_list = data_utils.read_file_list(test_id_scp) self.inp_test_file_list = data_utils.prepare_file_path_list(test_id_list, inp_feat_dir, inp_file_ext) self.gen_test_file_list = data_utils.prepare_file_path_list(test_id_list, pred_feat_dir, out_file_ext) #### Define keras models class #### self.keras_models = TrainKerasModels(self.inp_dim, self.hidden_layer_size, self.out_dim, self.hidden_layer_type, output_type=self.output_layer_type, dropout_rate=self.dropout_rate, loss_function=self.loss_function, optimizer=self.optimizer, rnn_params=self.rnn_params)
def __init__(self, cfg): # model type (duration or acoustic) self.model_output_type = cfg.model_output_type # ---------------------------------------------------- # ------------------- Input-Output ------------------- # ---------------------------------------------------- self.label_type = cfg.label_type self.cmp_ext = cfg.cmp_ext inp_file_ext = cfg.inp_file_ext out_file_ext = cfg.out_file_ext self.label_normaliser = HTSLabelNormalisation( question_file_name=cfg.question_file_name, add_frame_features=cfg.add_frame_features == 'True', # must be bool subphone_feats=cfg.subphone_feats) # Create streams files (they store data from dimension dictionaries for synthesis) in_streams = sorted(cfg.in_dimension_dict.keys()) indims = [str(cfg.in_dimension_dict[s]) for s in in_streams] self.out_streams = sorted(cfg.out_dimension_dict.keys()) self.outdims = [ str(cfg.out_dimension_dict[s]) for s in self.out_streams ] with open(os.path.join(cfg.model_dir, 'stream_info.txt'), 'w') as f: f.write(' '.join(in_streams) + '\n') f.write(' '.join(indims) + '\n') f.write(' '.join(self.out_streams) + '\n') f.write(' '.join(self.outdims) + '\n') # Input output dimensions self.inp_dim = cfg.inp_dim if self.model_output_type == 'duration': self.out_dim = cfg.dur_dim elif self.model_output_type == 'acoustic': self.out_dim = cfg.cmp_dim # Data normalization method self.inp_norm = cfg.inp_norm self.out_norm = cfg.out_norm # Norm stats files self.inp_stats_file = cfg.inp_stats_file self.out_stats_file_list = cfg.out_stats_file_list self.speaker_id = cfg.speaker_id self.shared_layer_flag = cfg.shared_layer_flag self.inp_scaler = None self.out_scaler = None # --------------------------------------------------- # ------------------- Directories ------------------- # --------------------------------------------------- self.plot_dir = os.path.join(cfg.plot_dir, cfg.nnets_file_name) # Select data directories based on model input-output type if self.model_output_type == 'duration': # Input self.inp_feat_dir = cfg.inp_feat_dir_dur self.bin_lab_dir = cfg.bin_lab_dir_dur self.bin_lab_dir_nosilence = cfg.bin_lab_dir_dur_nosilence self.bin_lab_dir_nosilence_norm = cfg.bin_lab_dir_dur_nosilence_norm # Output self.out_feat_dir = cfg.out_feat_dir_dur self.out_feat_dir_norm = cfg.out_feat_dir_dur_norm elif self.model_output_type == 'acoustic': # Input self.inp_feat_dir = cfg.inp_feat_dir_cmp self.bin_lab_dir = cfg.bin_lab_dir_cmp self.bin_lab_dir_nosilence = cfg.bin_lab_dir_cmp_nosilence self.bin_lab_dir_nosilence_norm = cfg.bin_lab_dir_cmp_nosilence_norm # Output self.out_feat_dir = cfg.nn_cmp_dir self.out_feat_dir_norm = cfg.nn_cmp_norm_dir else: print("invalid model output type") raise # -------------------------------------------------------- # ------------------- Model Parameters ------------------- # -------------------------------------------------------- self.sequential_training = cfg.sequential_training self.stateful = cfg.stateful self.json_model_file = cfg.json_model_file self.h5_model_file = cfg.h5_model_file self.model_params_file = cfg.model_params_file # ----------------------------------------------------------- # ------------------- Generate file lists ------------------- # ----------------------------------------------------------- train_file_number = cfg.train_file_number valid_file_number = cfg.valid_file_number test_file_number = cfg.test_file_number # List of file ids self.file_id_scp = cfg.file_id_scp # Create train, valid and test file lists self.file_id_list = data_utils.read_file_list(self.file_id_scp) if cfg.shuffle_data: random.seed(1) random.shuffle(self.file_id_list ) # Shuffle to get random valid and test utterances self.train_id_list = self.file_id_list[0:train_file_number] self.valid_id_list = self.file_id_list[ train_file_number:train_file_number + valid_file_number] self.test_id_list = self.file_id_list[ train_file_number + valid_file_number:train_file_number + valid_file_number + test_file_number] # Intermediate file lists self.inp_feat_file_list = data_utils.prepare_file_path_list( self.file_id_list, self.inp_feat_dir, inp_file_ext) self.bin_lab_file_list = data_utils.prepare_file_path_list( self.file_id_list, self.bin_lab_dir, inp_file_ext) self.bin_lab_nosilence_file_list = data_utils.prepare_file_path_list( self.file_id_list, self.bin_lab_dir_nosilence, inp_file_ext) # Train, test, validation file lists self.inp_train_file_list = data_utils.prepare_file_path_list( self.train_id_list, self.bin_lab_dir_nosilence, inp_file_ext) self.out_train_file_list = data_utils.prepare_file_path_list( self.train_id_list, self.out_feat_dir, out_file_ext) self.inp_valid_file_list = data_utils.prepare_file_path_list( self.valid_id_list, self.bin_lab_dir_nosilence, inp_file_ext) self.out_valid_file_list = data_utils.prepare_file_path_list( self.valid_id_list, self.out_feat_dir, out_file_ext) self.inp_test_file_list = data_utils.prepare_file_path_list( self.test_id_list, self.bin_lab_dir_nosilence, inp_file_ext) self.out_test_file_list = data_utils.prepare_file_path_list( self.test_id_list, self.out_feat_dir, out_file_ext) # For cmp files generated as targets (applies to acoustic model only) self.nn_cmp_file_list = [] self.nn_cmp_norm_file_list = [] self.in_file_list_dict = {} for feature_name in list(cfg.in_dir_dict.keys()): self.in_file_list_dict[ feature_name] = data_utils.prepare_file_path_list( self.file_id_list, cfg.in_dir_dict[feature_name], cfg.file_extension_dict[feature_name], False) # self.gen_test_file_list = data_utils.prepare_file_path_list(self.test_id_list, pred_feat_dir, out_file_ext) # if self.GenTestList: # test_id_list = data_utils.read_file_list(test_id_scp) # self.inp_test_file_list = data_utils.prepare_file_path_list(test_id_list, inp_feat_dir, inp_file_ext) # self.gen_test_file_list = data_utils.prepare_file_path_list(test_id_list, pred_feat_dir, out_file_ext) # ------------------------------------------------------ # ------------------- Main Processes ------------------- # ------------------------------------------------------ self.MAKELAB = cfg.MAKELAB # make binary labels (required step before normalization and training) self.MAKECMP = cfg.MAKECMP self.NORMDATA = cfg.NORMDATA # normalizes input and output data, creates data scaling objects self.TRAINDNN = cfg.TRAINDNN # train the Keras model self.TESTDNN = cfg.TESTDNN # test the Keras model # ---------------------------------------------------------- # ------------------- Define Keras Model ------------------- # ---------------------------------------------------------- self.batch_size = cfg.batch_size model_params = { 'inp_dim': self.inp_dim, 'hidden_layer_size': cfg.hidden_layer_size, 'shared_layer_flag': cfg.shared_layer_flag, 'speaker_id': cfg.speaker_id, 'out_dim': self.out_dim, 'hidden_layer_type': cfg.hidden_layer_type, 'output_layer_type': cfg.output_layer_type, 'dropout_rate': cfg.dropout_rate, 'loss_function': cfg.loss_function, 'optimizer': cfg.optimizer, 'l1': cfg.l1_reg, 'l2': cfg.l2_reg, 'gpu_num': cfg.gpu_num } rnn_params = { 'merge_size': cfg.merge_size, 'seq_length': cfg.seq_length, 'bucket_range': cfg.bucket_range, 'stateful': cfg.stateful, 'training_algo': cfg.training_algo } training_params = { 'batch_size': cfg.batch_size, 'num_of_epochs': cfg.num_of_epochs, 'shuffle_data': cfg.shuffle_data, 'tensorboard_dir': os.path.join(cfg.plot_dir, cfg.nnets_file_name), 'stopping_patience': cfg.stopping_patience, 'restore_best_weights': cfg.restore_best_weights } self.keras_models = TrainKerasModels(model_params=model_params, rnn_params=rnn_params, training_params=training_params)
def __init__(self, cfg): ################################################### ########## User configurable variables ############ ################################################### inp_feat_dir = cfg.inp_feat_dir out_feat_dir = cfg.out_feat_dir pred_feat_dir = cfg.pred_feat_dir inp_file_ext = cfg.inp_file_ext out_file_ext = cfg.out_file_ext ### Input-Output ### self.inp_dim = cfg.inp_dim self.out_dim = cfg.out_dim self.inp_norm = cfg.inp_norm self.out_norm = cfg.out_norm self.inp_stats_file = cfg.inp_stats_file self.out_stats_file = cfg.out_stats_file self.inp_scaler = None self.out_scaler = None #### define model params #### self.hidden_layer_type = cfg.hidden_layer_type self.hidden_layer_size = cfg.hidden_layer_size self.sequential_training = cfg.sequential_training self.stateful = cfg.stateful self.batch_size = cfg.batch_size self.seq_length = cfg.seq_length self.training_algo = cfg.training_algo self.shuffle_data = cfg.shuffle_data self.output_layer_type = cfg.output_layer_type self.loss_function = cfg.loss_function self.optimizer = cfg.optimizer self.rnn_params = cfg.rnn_params self.dropout_rate = cfg.dropout_rate self.num_of_epochs = cfg.num_of_epochs self.json_model_file = cfg.json_model_file self.h5_model_file = cfg.h5_model_file ### define train, valid, test ### train_file_number = cfg.train_file_number valid_file_number = cfg.valid_file_number test_file_number = cfg.test_file_number file_id_scp = cfg.file_id_scp test_id_scp = cfg.test_id_scp #### main processess #### self.NORMDATA = cfg.NORMDATA self.TRAINMODEL = cfg.TRAINMODEL self.TESTMODEL = cfg.TESTMODEL #### Generate only test list #### self.GenTestList = cfg.GenTestList ################################################### ####### End of user-defined conf variables ######## ################################################### #### Create train, valid and test file lists #### file_id_list = data_utils.read_file_list(file_id_scp) train_id_list = file_id_list[0: train_file_number] valid_id_list = file_id_list[train_file_number: train_file_number + valid_file_number] test_id_list = file_id_list[train_file_number + valid_file_number: train_file_number + valid_file_number + test_file_number] valid_test_id_list = file_id_list[train_file_number: train_file_number + valid_file_number + test_file_number] self.inp_train_file_list = data_utils.prepare_file_path_list(train_id_list, inp_feat_dir, inp_file_ext) self.out_train_file_list = data_utils.prepare_file_path_list(train_id_list, out_feat_dir, out_file_ext) self.inp_valid_file_list = data_utils.prepare_file_path_list(valid_id_list, inp_feat_dir, inp_file_ext) self.out_valid_file_list = data_utils.prepare_file_path_list(valid_id_list, out_feat_dir, out_file_ext) self.inp_test_file_list = data_utils.prepare_file_path_list(valid_test_id_list, inp_feat_dir, inp_file_ext) self.out_test_file_list = data_utils.prepare_file_path_list(valid_test_id_list, out_feat_dir, out_file_ext) self.gen_test_file_list = data_utils.prepare_file_path_list(valid_test_id_list, pred_feat_dir, out_file_ext) if self.GenTestList: test_id_list = data_utils.read_file_list(test_id_scp) self.inp_test_file_list = data_utils.prepare_file_path_list(test_id_list, inp_feat_dir, inp_file_ext) self.gen_test_file_list = data_utils.prepare_file_path_list(test_id_list, pred_feat_dir, out_file_ext) #### Define keras models class #### self.keras_models = TrainKerasModels(self.inp_dim, self.hidden_layer_size, self.out_dim, self.hidden_layer_type, output_type=self.output_layer_type, dropout_rate=self.dropout_rate, loss_function=self.loss_function, optimizer=self.optimizer, rnn_params=self.rnn_params)