Beispiel #1
0
def data_import():
    X_train, y_train = mnist_reader.load_mnist('../../data/mnist', kind='train')
    X_test, y_test = mnist_reader.load_mnist('../../data/mnist', kind='t10k')
    X_valid = X_test[0:5000]
    y_valid = y_test[0:5000]
    X_test = X_test[5000:10000]
    y_test = y_test[5000:10000]
    print(y_test.shape)

    # convert the targets to one hot
    y_valid = convertTarget(y_valid)
    y_test = convertTarget(y_test)
    y_train = convertTarget(y_train)

    return X_train, y_train, X_valid, y_valid, X_test, y_test
Beispiel #2
0
def _read_data_test(data_path):
    """Reads CIFAR-10 format data. Always returns NHWC format.

  Returns:
    images: np tensor of size [N, H, W, C]
    labels: np tensor of size [N]
  """
    images, labels = [], []
    X_test, y_test = mnist_reader.load_mnist(data_path, kind='t10k')
    #X_test, y_test = mnist_reader.load_mnist('data/fashion', kind='t10k')
    #data = pickle.load(finp,encoding='bytes')
    print(X_test)
    batch_images = X_test.astype(np.float32) / 255.0
    batch_labels = np.array(y_test, dtype=np.int32)
    images.append(batch_images)
    labels.append(batch_labels)
    images = np.concatenate(images, axis=0)
    labels = np.concatenate(labels, axis=0)
    images = np.reshape(images, [-1, 1, 28, 28])
    images = np.transpose(images, [0, 2, 3, 1])

    return images, labels