# coding: utf-8 import sys, os sys.path.append(os.pardir) # 부모 디렉터리의 파일을 가져올 수 있도록 설정 import numpy as np import matplotlib.pyplot as plt from ch08.deep_convnet import DeepConvNet from dataset.mnist import load_mnist (x_train, t_train), (x_test, t_test) = load_mnist(flatten=False) network = DeepConvNet() network.load_params("deep_convnet_params.pkl") sampled = 10000 # 고속화를 위한 표본추출 x_test = x_test[:sampled] t_test = t_test[:sampled] print("caluculate accuracy (float64) ... ") print(network.accuracy(x_test, t_test)) # float16(반정밀도)로 형변환 x_test = x_test.astype(np.float16) for param in network.params.values(): param[...] = param.astype(np.float16) print("caluculate accuracy (float16) ... ") print(network.accuracy(x_test, t_test))
# coding: utf-8 import os import sys sys.path.append(os.pardir) # 親ディレクトリのファイルをインポートするための設定 from dataset.mnist import load_mnist from ch08.deep_convnet import DeepConvNet from common.trainer import Trainer (x_train, t_train), (x_test, t_test) = load_mnist(flatten=False) network = DeepConvNet() trainer = Trainer(network, x_train, t_train, x_test, t_test, epochs=20, mini_batch_size=100, optimizer='Adam', optimizer_param={'lr': 0.001}, evaluate_sample_num_per_epoch=1000) trainer.train() # パラメータの保存 network.save_params("deep_convnet_params.pkl") print("Saved Network Parameters!")
# coding: utf-8 import sys, os sys.path.append(os.pardir) # 부모 디렉터리의 파일을 가져올 수 있도록 설정 import numpy as np import matplotlib.pyplot as plt from dataset.mnist import load_mnist from ch08.deep_convnet import DeepConvNet from trainer import Trainer batch_size = 500 (x_train, t_train), (x_test, t_test) = load_mnist(flatten=False) x_test, t_test = x_test[:batch_size], t_test[:batch_size] # print(x_test) # print(t_test) network = DeepConvNet() network.load_params("deep_convnet_params.pkl") x = network.predict(x_test, train_flag=False) x = np.argmax(x, axis=1) r = np.sum(t_test == x) / batch_size * 100 print(r)
# coding: utf-8 import os import sys sys.path.append(os.pardir) # 親ディレクトリのファイルをインポートするための設定 import numpy as np import matplotlib.pyplot as plt from ch08.deep_convnet import DeepConvNet from dataset.mnist import load_mnist (x_train, t_train), (x_test, t_test) = load_mnist(flatten=False) network = DeepConvNet() network.load_params("deep_convnet_params.pkl") print("calculating test accuracy ... ") # sampled = 1000 # x_test = x_test[:sampled] # t_test = t_test[:sampled] classified_ids = [] acc = 0.0 batch_size = 100 for i in range(int(x_test.shape[0] / batch_size)): tx = x_test[i * batch_size:(i + 1) * batch_size] tt = t_test[i * batch_size:(i + 1) * batch_size] y = network.predict(tx, train_flg=False) y = np.argmax(y, axis=1) classified_ids.append(y)
import sys, os sys.path.append(os.pardir) # 부모 디렉터리의 파일을 가져올 수 있도록 설정 from dataset.mnist import load_mnist from ch08.deep_convnet import DeepConvNet from common.trainer import Trainer import numpy as np import matplotlib.pyplot as plt (x_train, t_train), (x_test, t_test) = load_mnist(flatten=False) # 시간이 오래 걸릴 경우 데이터를 줄인다. x_train, t_train = x_train[:5000], t_train[:5000] x_test, t_test = x_test[:1000], t_test[:1000] network = DeepConvNet() trainer = Trainer(network, x_train, t_train, x_test, t_test, epochs=1, mini_batch_size=100, optimizer='Adam', optimizer_param={'lr': 0.001}, evaluate_sample_num_per_epoch=1000) trainer.train() # # 매개변수 보관 # network.save_params("deep_convnet_params.pkl") # print("Saved Network Parameters!")