예제 #1
0
def train_student(
    student,
    teacher,
):
    student.evaluate(test_dataset_x[0], feature_test_data, verbose=2)
    student_history = student.fit(train_dataset_x[0],
                                  feature_train_data,
                                  batch_size=32,
                                  epochs=epochs,
                                  validation_data=(test_dataset_x[0],
                                                   feature_test_data),
                                  verbose=verbose,
                                  callbacks=[model_checkpoint_callback])
    print('{} train:'.format(student.name),
          student_history.history['mean_squared_error'])
    print('{} test:'.format(student.name),
          student_history.history['val_mean_squared_error'])
    dataset_update(student_history, student, parameters, name='sample_5')
    print(student.get_weights()[3][:4, :4])
    save_model(student, save_model_path, parameters, checkpoint=False)
    student.load_weights(checkpoint_filepath)
    save_model(student, save_model_path, parameters, checkpoint=True)
    student.evaluate(test_dataset_x[0], feature_test_data, verbose=2)
    student_predictions = student(test_dataset_x[0])
    train_predictions = student(train_dataset_x[0])
    return student_predictions, train_predictions
예제 #2
0
def train_student(
    student,
    teacher,
):
    student.evaluate(test_dataset_x[0], feature_test_data, verbose=2)
    student_history = student.fit(train_dataset_x[0],
                                  feature_train_data,
                                  batch_size=32,
                                  epochs=epochs,
                                  validation_data=(test_dataset_x[0],
                                                   feature_test_data),
                                  verbose=verbose,
                                  callbacks=[model_checkpoint_callback])
    print('{} train:'.format(student.name),
          student_history.history['mean_squared_error'])
    print('{} test:'.format(student.name),
          student_history.history['val_mean_squared_error'])
    print(student.get_weights()[3][:4, :4])
    save_model(student, save_model_path, parameters, checkpoint=False)
    student.load_weights(checkpoint_filepath)
    save_model(student, save_model_path, parameters, checkpoint=True)
    student.evaluate(test_dataset_x[0], feature_test_data, verbose=2)

    student_test_data = np.zeros([5000, 8, 8, num_feature])
    student_train_data = np.zeros([45000, 8, 8, num_feature])
    start = 0
    end = batch_size
    count = 0
    for batch in range(len(train_dataset_x[0]) // batch_size + 1):
        count += 1
        train_temp = student(train_dataset_x[0][start:end]).numpy()
        student_train_data[start:end, :, :, :] = train_temp[:, :, :, :]
        start += batch_size
        end += batch_size
    start = 0
    end = batch_size
    count = 0
    for batch in range(len(test_dataset_x[0]) // batch_size + 1):
        count += 1
        test_temp = student(test_dataset_x[0][start:end]).numpy()
        student_test_data[start:end, :, :, :] = test_temp[:, :, :, :]
        start += batch_size
        end += batch_size
    #Evaluate per feature
    var_list = []
    for feature_indx in range(num_feature):
        var = np.var(student_test_data[:, :, :, feature_indx] -
                     feature_test_data[:, :, :, feature_indx])
        var_list.append(var)
    parameters['student_var'] = var_list
    dataset_update(student_history,
                   student,
                   parameters,
                   name='multi_features_{}'.format(num_feature))
    return student_test_data, student_train_data
예제 #3
0
                                         train_teacher_data,
                                         batch_size=32,
                                         epochs=epochs,
                                         validation_data=(test_dataset_x[0],
                                                          test_teacher_data),
                                         verbose=verbose)
print('student3 net train:', student_history3.history['mean_squared_error'])
print('student3 net test:', student_history3.history['val_mean_squared_error'])
now = datetime.now()
print(now.strftime("%d/%m/%Y %H:%M:%S"))
student3_prediction, teacher_target = feature_learning3.get_predictions(
    [test_dataset_x[0][50:150], test_teacher_data[50:150]]) * 1
# write_to_file(student_history3, student_net3,parameters)
now = datetime.now()
print(now.strftime("%d/%m/%Y %H:%M:%S"))
dataset_update(student_history3, student_net3, parameters)
now = datetime.now()
print(now.strftime("%d/%m/%Y %H:%M:%S"))

teacher_mean, teacher_std = feature_learning3.get_teacher_std(
    test_teacher_data)
parameters['teacher_mean'] = teacher_mean
parameters['teacher_var'] = teacher_std**2
print('teacher feature mean =', teacher_mean, 'teacher feature var =',
      teacher_std**2)

print(np.std(target))
print(np.std(student3_prediction))

with open(
        prediction_data_path +