Exemple #1
0
def main():
    (x_train, t_train), (x_test, t_test) = load_mnist(normalize=True,
                                                      flatten=True,
                                                      one_hot_label=True)
    # print(batch_verify(x_test, t_test, init_network()))
    # print(verify(x_test, t_test, init_network()))
    print(test_cross_entropy_error(x_test, t_test, init_network()))
Exemple #2
0
    def __init__(self):
        (self.x_train, self.t_train), (x_test, t_test) = load_mnist(
            normalize=True, one_hot_label=True)
        self.iter_num = 10000  # 学习次数
        self.learn_rate = 0.3  # 学习率
        self.batch_size = 100  # 批处理数量
        self.train_size = self.x_train.shape[0]  # 总训练数量

        self.network = TwoLayerNet_Pro(  # 初始化2层网络
            input_size=784, hidden_size=50, output_size=10)

        # self.network = TwoLayerNet_Pro2(  # 初始化3层网络
        #     input_size=784, hidden_size1=100, hidden_size2=50, output_size=10)

        # self.network = TwoLayerNet_Pro2(  # 初始化4层网络
        #     input_size=784, hidden_size1=200, hidden_size2=100, hidden_size3=50, output_size=10)

        self.train_loss = list()
        self.acc_list = list()
Exemple #3
0
import numpy as np

from source.ch_05.layer_net import TwoLayerNet
from source.dataset.mnist import load_mnist

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

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)

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

for i in range(iters_num):
    # print("Loop number: " + str(i))
    batch_mask = np.random.choice(train_size, batch_size)
    x_batch = x_train[batch_mask]
    t_batch = t_train[batch_mask]

    grads = network.gradient(x_batch, t_batch)

    for key in ("W1", "W2", "b1", "b2"):
        network.params[key] -= learning_rate * grads[key]
Exemple #4
0
# coding: utf-8
import os
import sys

sys.path.append(os.pardir)  # 親ディレクトリのファイルをインポートするための設定
import numpy as np
from source.dataset.mnist import load_mnist
from PIL import Image


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


(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)  # 形状を元の画像サイズに変形
print(img.shape)  # (28, 28)

img_show(img)