def tongue_basic_gen_trainer(tongue_image_arrays, tongue_yaofangs, tongue_image_shape, nb_yao, gen_model_path=None, train_on_batch=False, use_data_augment=False): ''' @param use_tfidf_tensor: flag of use tfidf tensor or not with different tensorization function ''' total_tongue_x, total_y = tongue2text_gen.data_tensorization( tongue_image_arrays, tongue_yaofangs, tongue_image_shape, nb_yao) # train_x = total_tongue_x[500:] # train_y = total_y[500:] # train_x = np.concatenate((total_tongue_x[: 2000], total_tongue_x[2500 :]), axis=0) # train_y = np.concatenate((total_y[: 2000], total_y[2500 :]), axis=0) # train_x = np.concatenate((total_tongue_x[: 4000], total_tongue_x[4500 :]), axis=0) # train_y = np.concatenate((total_y[: 4000], total_y[4500 :]), axis=0) # train_x = np.concatenate((total_tongue_x[: 6000], total_tongue_x[6500 :]), axis=0) # train_y = np.concatenate((total_y[: 6000], total_y[6500 :]), axis=0) train_x = total_tongue_x[: len(total_tongue_x) - 500] train_y = total_y[: len(total_y) - 500] del(total_tongue_x) del(total_y) if use_data_augment == True: # just can be use on service 225 with big memory datagen = image_augment.image_augment_gen() train_x, train_y = image_augment.data_tensoration_augment( datagen, train_x, train_y) scaling_act_type = 'binary' print('training 2 * cnn + mlp tongue2text gen model------on_batch: %d------scaling_activation: %s...' % (train_on_batch, scaling_act_type)) tongue_gen_model = tongue2text_gen.k_cnns_mlp( yao_indices_dim=nb_yao, tongue_image_shape=tongue_image_shape, with_compile=True) if train_on_batch == True: trained_tongue_gen_model, history = tongue2text_gen.trainer_on_batch( tongue_gen_model, train_x, train_y) else: record_path = None if gen_model_path != None: record_path = gen_model_path.replace('json', 'h5') trained_tongue_gen_model, history = tongue2text_gen.trainer( tongue_gen_model, train_x, train_y, best_record_path=record_path) if gen_model_path != None: tongue2text_gen.storageModel(model=trained_tongue_gen_model, frame_path=gen_model_path, replace_record=False) print('history: {0}'.format(history)) return trained_tongue_gen_model
def tongue_gen_deeper_1pipeline_trainer(tongue_image_arrays, tongue_yaofangs, tongue_image_shape, base_model_name, nb_yao, gen_model_path=None, train_on_batch=False, use_tfidf_tensor=False, use_data_augment=True): ''' @param base_model: the name of base model in {'vgg16', 'vgg19', 'resnet50'} ''' total_tongue_x, total_y = tongue2text_gen.data_tensorization( tongue_image_arrays, tongue_yaofangs, tongue_image_shape, nb_yao) # train_x = total_tongue_x[500:] # train_y = total_y[500:] # train_x = np.concatenate((total_tongue_x[: 2000], total_tongue_x[2500 :]), axis=0) # train_y = np.concatenate((total_y[: 2000], total_y[2500 :]), axis=0) # train_x = np.concatenate((total_tongue_x[: 4000], total_tongue_x[4500 :]), axis=0) # train_y = np.concatenate((total_y[: 4000], total_y[4500 :]), axis=0) # train_x = np.concatenate((total_tongue_x[: 6000], total_tongue_x[6500 :]), axis=0) # train_y = np.concatenate((total_y[: 6000], total_y[6500 :]), axis=0) train_x = total_tongue_x[:len(total_tongue_x) - 500] train_y = total_y[:len(total_y) - 500] del (total_tongue_x) del (total_y) if use_data_augment == True: # just can be use on service 225 with big memory datagen = image_augment.image_augment_gen() train_x, train_y = image_augment.data_tensoration_augment( datagen, train_x, train_y) scaling_act_type = 'tfidf' if use_tfidf_tensor else 'binary' print( 'training 1pipeline + mlp tongue2text gen model------on_batch: %d------scaling_activation: %s...' % (train_on_batch, scaling_act_type)) print('use base_model: ' + base_model_name) image_input, base_model = tongue2text_deeper_gen.k_base_model( tongue_image_shape=tongue_image_shape, model_name=base_model_name) tongue_gen_model = tongue2text_deeper_gen.k_1pipeline_mlp( yao_indices_dim=nb_yao, image_input=image_input, base_model=base_model, with_compile=True) if train_on_batch == True: trained_tongue_gen_model, history = tongue2text_gen.trainer_on_batch( tongue_gen_model, train_x, train_y) else: record_path = None if gen_model_path != None: record_path = gen_model_path.replace('json', 'h5') trained_tongue_gen_model, history = tongue2text_gen.trainer( tongue_gen_model, train_x, train_y, batch_size=16, epochs=_new_training_epochs, best_record_path=record_path) if gen_model_path != None: tongue2text_gen.storageModel(model=trained_tongue_gen_model, frame_path=gen_model_path, replace_record=False) print('history: {0}'.format(history)) return trained_tongue_gen_model