# coding: utf-8
import sys, os
import time

sys.path.append(os.pardir)  # 为了导入父目录而进行的设定
import numpy as np
from 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) ... ")
start_time = time.time()
print(network.accuracy(x_test, t_test))
print("--- %s seconds ---" % (time.time() - start_time))

# 转换为float16型
x_test = x_test.astype(np.float16)
for param in network.params.values():
    param[...] = param.astype(np.float16)

print("caluculate accuracy (float16) ... ")
start_time2 = time.time()
print(network.accuracy(x_test, t_test))
print("--- %s seconds ---" % (time.time() - start_time2))