Ejemplo n.º 1
0
def get_data():
    # loadin data at first time will take several minutes
    (x_train, t_train), (x_test, t_test) = load_mnist(flatten=True, normalize=True, one_hot_label=False)
    return x_test, t_test
Ejemplo n.º 2
0
import sys, os
sys.path.append(os.pardir)
import numpy as np
from master.dataset.mnist import load_mnist
from twolayernet5 import TwoLayerNet

# data load
(x_train, t_train), (x_test, t_test) = load_mnist(normalize=True,
                                                  one_hot_label=True)

network = TwoLayerNet(input_size=784, hidden_size=50, output_size=10)

iters_num = 10000
train_size = x_train.shape[0]
batch_size = 100
learning_rate = 0.1

train_loss_list = []
train_acc_list = []
test_acc_list = []

iter_per_epoch = max(train_size / batch_size, 1)

for i in range(iters_num):
    batch_mask = np.random.choice(train_size, batch_size)
    x_batch = x_train[batch_mask]
    t_batch = t_train[batch_mask]

    # get gradients by back propagation
    grad = network.gradient(x_batch, t_batch)
Ejemplo n.º 3
0
from PIL import Image
import numpy as np
from master.dataset.mnist import load_mnist
import sys
import os
sys.path.append(os.pardir)


def img_show(img):
    pil_img = Image.fromarray(np.uint8(img))
    pil_img.show()


# loadin data at first time will take several minutes
(x_train, t_train), (x_test, t_test) = load_mnist(flatten=True,
                                                  normalize=False)
img = x_train[0]
label = t_train[0]
print(label)  # 5
print(img.shape)  # (784, )
img = img.reshape(28, 28)  # retransform the shape of the image
print(img.shape)  # (28, 28)
img_show(img)

# output the shapes of each data
print(x_train.shape)  # (60000, 784)
print(t_train.shape)  # (60000, )
print(x_test.shape)  # (10000, 784)
print(t_test.shape)  # (10000, )