test.py
805 Bytes
from simple_convnet4 import *
from dataset.cifar10 import load_cifar10
def batch_(data, lbl, pre, size = 100):
return data[pre: pre+size], lbl[pre: pre+size]
network = SimpleConvNet(input_dim=(3,32,32),
conv_param = {'filter_num': (32, 32, 64), 'filter_size': 3, 'pad': 1, 'stride': 1},
hidden_size=512, output_size=10, weight_init_std=0.01, pretrained=True)
(x_train, t_train), (x_test, t_test) = load_cifar10(flatten=False)
print("Length of test data: ",len(x_test))
batch_size = 100
epoch = int(len(x_test) / batch_size)
acc = 0
for i in range(epoch):
t_img, t_lbl = batch_(x_test, t_test, i*batch_size, batch_size)
t = network.accuracy(t_img, t_lbl, batch_size)
acc += t * batch_size
print("Accuracy : ",str(acc / len(x_test)*100),'%')