Ejemplo n.º 1
0
import numpy as np
from utils.preprocessing import *
from functools import partial
from utils.research_preprocessing import add_occlusions

dataset.apply(clean_repeat_points)

NUM_SAMPLES = 50
ANGLES_TO_ROTATE = [5, 10, 15, 45, -5, -10, -15, -45]

DROPOUTS_TO_TRY = np.linspace(0.0, 0.99, 20)

scores = []

for drop in DROPOUTS_TO_TRY:
    curr = dataset.copy()
    curr.apply(partial(add_occlusions, dropout_percentage=drop))
    curr.apply(apply_mean_centering)
    curr.apply(apply_unit_distance_normalization)
    curr.apply(
        partial(spline_interpolate_and_resample, num_samples=NUM_SAMPLES))
    curr.expand_many(partial(rotate_digit, degrees=ANGLES_TO_ROTATE))
    curr.expand(reverse_digit_sequence)
    X_train = np.array(curr.train_data)
    # Convert labels to numpy array and OneHot encode them
    encoder, Y_train, _, _ = curr.onehot_encode_labels()
    # evaluate
    score = model.evaluate(X_train, Y_train)[1]
    print("occlusion percentage: %.2f%%,   acc: %.3f%%" %
          (drop * 100.0, score * 100.0))
    scores.append(score)