def go(): import time ######################### EPOCH BATCH SIZE EPOCH = 1 BATCH_SIZE = 256 ######################### Read Data # trainset, valset, testset = load_mnist() train_images, train_labels = load_mnist(kind='train') test_images, test_labels = load_mnist(kind='t10k') # ######################### Network # net = FCNet() # # # # ######################### Compile # net.compile(optimizer='sgd', loss='cross_entropy') # # # # ######################### Train FC # st = time.time() # net.fit(train_images, train_labels, batch_size=BATCH_SIZE, epochs=EPOCH, verbose=1) # et = time.time() # print('time cost: ', et - st) # print(u'当前进程的内存使用:%.4f GB' % (psutil.Process(os.getpid()).memory_info().rss / 1024 / 1024 / 1024)) # # ######################### Evaluate FC # train_acc, train_loss = net.evaluate(train_images, train_labels, batch_size=500) # # test_acc, test_loss = net.evaluate(test_images, test_labels, batch_size=500) # print('#' * 10, 'Fully Connected Network') # print(f'Train acc -> {train_acc}, Train loss -> {train_loss}') # print(f'Test acc -> {test_acc}, Test loss -> {test_loss}') print('Start Training ConvNet---') ######################### Network net = ConvNet() ######################### Compile net.compile(optimizer='sgd', loss='cross_entropy', lr=0.01) ######################### Train Conv st = time.time() net.fit(train_images, train_labels, batch_size=BATCH_SIZE, epochs=EPOCH, verbose=1) et = time.time() print('time cost: ', et - st) print(u'当前进程的内存使用:%.4f GB' % (psutil.Process(os.getpid()).memory_info().rss / 1024 / 1024 / 1024)) # ######################### Evaluate FC train_acc, train_loss = net.evaluate(train_images, train_labels, batch_size=500) test_acc, test_loss = net.evaluate(test_images, test_labels, batch_size=500) print('#' * 10, 'Convolutional Network') print(f'Train acc -> {train_acc}, Train loss -> {train_loss}') print(f'Test acc -> {test_acc}, Test loss -> {test_loss}')
from network import ConvNet import numpy as np from dataset import getDataset dataset = getDataset() print(dataset["balance_train"]) conv = ConvNet(dataset) conv.fit(dataset["one_hot_train"], dataset["one_hot_label_train"], dataset["one_hot_validation"], dataset["one_hot_label_validation"], graphics=True) print("Final accuracy:") print(" " + str( conv.computeAccuracy(dataset["one_hot_validation"], dataset["labels_validation"]))) print("Friends:") conv.classify(dataset["one_hot_friends"]) # # F = np.zeros((4, 2, 2)) # # print(F[:, :, 0]) # # print(F[:, :, 0].shape) # F[:, :, 0] = [[1, 2], [3, 4], [5, 6], [7, 8]] # F[:, :, 0] = [[1, 2], [3, 4], [5, 6], [7, 8]] # # print(F[:, :, 0]) # # print(F[:, :, 1]) # # print(F) #