import numpy as np import matplotlib.pyplot as plt from keras import backend as K from random import shuffle from pnslib import utils from pnslib import ml # Load T-shirt/top and Trouser classes from Fashion MNIST # complete label description is at # https://github.com/zalandoresearch/fashion-mnist#labels (train_x, train_y, test_x, test_y) = utils.binary_fashion_mnist_load(class_list=[0, 1], flatten=True) print("[MESSAGE] Dataset is loaded.") # preprocessing for training and testing images train_x = train_x.astype("float32") / 255. # rescale image mean_train_x = np.mean(train_x, axis=0) # compute the mean across pixels train_x -= mean_train_x # remove the mean pixel value from image test_x = test_x.astype("float32") / 255. test_x -= mean_train_x print("[MESSAGE] Dataset is preporcessed.") # Use PCA to reduce the dimension of the dataset, # so that the training will be less expensive # perform PCA on training dataset
"""Demonstrate the usage of Fashion-MNIST. Author: Yuhuang Hu Email : [email protected] """ from __future__ import print_function, absolute_import import matplotlib.pyplot as plt import pnslib.utils as utils (train_x, train_y, test_x, test_y) = utils.binary_fashion_mnist_load() print(train_x.shape) print(train_y.shape) print(test_x.shape) print(test_y.shape) plt.figure() for idx in range(100): plt.imshow(test_x[idx, ..., 0], cmap="gray") plt.show()
"""Perform PCA on Fashion-MNIST. Author: Yuhuang Hu Email : [email protected] """ from __future__ import print_function, absolute_import import numpy as np from pnslib import utils from pnslib import ml # load data (train_x, train_y, test_x, test_y) = utils.binary_fashion_mnist_load(flatten=True) train_x = train_x.astype("float32") / 255. mean_train_x = np.mean(train_x, axis=0) train_x -= mean_train_x test_x = train_x.astype("float32") / 255. test_x -= mean_train_x print(train_x.dtype) print(test_x.dtype) # perform PCA on training dataset train_x, R, n_retained = ml.pca(train_x) # perform PCA on testing dataset test_x = ml.pca_fit(test_x, R, n_retained)