Exemplo n.º 1
0
def preprocess_data(X,y,nb_classes=10, binarize=False, noise_prop=0.49):
    X_new = X.reshape(-1, 784)
    X_new = X_new.astype('float32')
    print(X_new.shape[0], 'samples')
    if binarize:
        X_new = binaryze_dataset(X_new, threshold=0.5)
    if noise_prop != None:
        print("Adding salt and pepper ({})".format(noise_prop))
        X_new = add_salt_and_pepper(X_new,proportion=noise_prop)
    if nb_classes == 2:
        Y = numpy.in1d(y,[0,2,4,6,8]).astype('float64')
    else:
        Y = y
        print(Y.shape)
    return X_new,Y
Exemplo n.º 2
0
def preprocess_data(X,y,nb_classes=10, binarize=False, noise=False,
                    proportion=0.1):
    X_new = X.reshape(-1, 784)
    X_new = X_new.astype('float32')
    X_new /= 255.0
    print(X_new.shape[0], 'samples')
    if binarize:
        X_new = binaryze_dataset(X_new, threshold=0.5)
    if noise:
        X_new = add_salt_and_pepper(X_new,proportion=proportion)
    if nb_classes == 2:
        Y = np.in1d(y,[0,2,4,6,8]).astype('float64')
    else:
        Y = np_utils.to_categorical(y,nb_classes)
    return X_new,Y