import sys sys.path.append('..') import numpy as np import minst as Minst import newtowlayernet as Newtwolayernet import preprocessing as Preprocessing import random import matplotlib.pylab as plt #读入数据 train_images = Preprocessing.normalize(Minst.get_train_images()) train_lables = Preprocessing.one_hot(Minst.get_train_lables()) test_images = Preprocessing.normalize(Minst.get_test_images()) test_lables = Preprocessing.one_hot(Minst.get_test_lables()) #超参数 iters_num = 1000 train_size = train_images.shape[0] test_size = test_images.shape[0] batch_size = 10 learning_rate = 0.002 train_loss_list = [] train_acc_list = [] test_acc_list = [] #存放梯度 监控 w1_list = [] b1_list = [] w2_list = [] b2_list = [] '''
import sandwich as sw import theano theano.config.exception_verbosity = 'high' l1 = sw.layers.InputLayer(shape=(1, 28, 28)) l2 = sw.layers.Flatten(l1) l3 = sw.layers.FullConn(l2, n_out=500, activation=sw.activations.sigmoid) l4 = sw.layers.FullConn(l3, n_out=10, activation=sw.activations.sigmoid) layers = [l1, l2, l3, l4] nnet = sw.NNet(layers) # Load the train data train_images = np.asarray(minst.get_train_images(), dtype='float32').reshape(60000, 1, 28, 28) train_images[train_images<=128] = 0 train_images[train_images>128] = 1 img = train_images[0, 0] for i in xrange(28): print "".join(map(str, map(int, img[i]))) train_labels = minst.get_train_labels() target = np.zeros(shape=train_labels.shape + (10, ), dtype='float32') print target.shape for i, label in enumerate(train_labels): target[i, label] = 1