Beispiel #1
0
def view_tongue_data_augment():

    patient_tongue_dir = config['root_path'] + \
        config['original_path'] + 'tongue_9585'
    tongue_zhiliao_path = config['root_path'] + \
        config['original_path'] + 'tongue_zhiliao.list'
    yaopin_path = config['root_path'] + \
        config['original_path'] + 'yaopin.vocab'

    tongue_ids, tongue_image_arrays, tongue_yaofangs, tongue_image_shape = patient_tongue_generator.loadDatafromFile(
        patient_tongue_dir, tongue_zhiliao_path, image_normal_size=(224, 224))

    # fetch max(id) in yaopin.vocab as nb_yao
    with open(yaopin_path, 'r') as yaopin_file:
        nb_yao = max(
            int(line.split(' ')[0]) for line in yaopin_file.readlines())

    total_tongue_x, total_y = tongue2text_gen.data_tensorization(
        tongue_image_arrays, tongue_yaofangs, tongue_image_shape, nb_yao)

    datagen = image_augment.image_augment_gen()
    augmented_x, augmented_y = image_augment.data_tensoration_augment(
        datagen, total_tongue_x, total_y)

    print(np.shape(augmented_x))
    print(np.shape(augmented_y))
Beispiel #2
0
def gen_deeper_pipeline_predictor_test(tongue_image_arrays,
                                       tongue_yaofangs,
                                       tongue_image_shape,
                                       nb_yao,
                                       trained_gen_model,
                                       use_tfidf_tensor=False):
    '''
    @param use_tfidf_tensor: flag of use tfidf tensor or not with different tensorization function
    '''
    ''' load test_x & test_y '''
    if use_tfidf_tensor == True:
        total_x, total_y = tongue2text_gen.data_tensorization_tfidf(
            tongue_image_arrays, tongue_yaofangs, tongue_image_shape, nb_yao)
    else:
        total_x, total_y = tongue2text_gen.data_tensorization(
            tongue_image_arrays, tongue_yaofangs, tongue_image_shape, nb_yao)

#     test_x = total_x[: 500]
#     test_x = total_x[2000 : 2500]
#     test_x = total_x[4000 : 4500]
#     test_x = total_x[6000 : 6500]
    test_x = total_x[len(total_x) - 500:]

    gen_output = tongue2text_gen.predictor(trained_gen_model, test_x)

    return gen_output
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
Beispiel #4
0
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