@cleardusk
2015-11-20T11:14:54.000000Z
字数 6763
阅读 1622
GjzCVCode
功能:一层网络(无隐藏层网络),调整 epochs, mini_batch_size, eta,输出 log info
"""Try creating a network with just two layers - an input and an output layer,no hidden layer - with 784 and 10 neurons, respectively. Train the networkusing stochastic gradient descent. What classification accuracy can you achieve?"""import networkimport mnist_loaderimport timeimport itertools# def train():# net = network.Network([784, 10])# training_data, validation_data, test_data = \# mnist_loader.load_data_wrapper()## epochs, mini_batch_size, eta = 30, 10, 1.0# return net.SGD(training_data, epochs, mini_batch_size,# eta, test_data=test_data)def profile():# Load datasettraining_data, validation_data, test_data = \mnist_loader.load_data_wrapper()# parameterssizes = [784, 10]epochs_ = (30, 60)mini_batch_size_ = (5, 10, 15, 20)eta_ = (0.1, 0.5, 1, 2, 3)# epochs, mini_batch_size, eta = 30, 10, 1.0comninations = []for epochs in epochs_:for mini_batch_size in mini_batch_size_:for eta in eta_:comninations.append([epochs, mini_batch_size, eta])for epochs, mini_batch_size, eta in comninations:# time the trainingtime_begin = time.clock()average_times = 3accuracy = []for i in xrange(average_times):net = network.Network(sizes)accuracy.append(net.SGD(training_data, epochs, mini_batch_size,eta, test_data=test_data))# awesome use of itertoolsaccuracy = [sum(sublist) / float(average_times)for sublist in itertools.izip(*accuracy)]time_end = time.clock()# print network informationprint "Network size: %s" % str(sizes)print "Epochs: %d" % epochsprint "Mini batch size: %d" % mini_batch_sizeprint "Eta: %f " % etaprint "The max accuracy is %.4f" % max(accuracy)print "The final accuracy is %.4f" % accuracy[-1]print 'Spent time: %.1f seconds\n' % \((time_end - time_begin) / float(average_times))if __name__ == '__main__':# train()profile()
Network size: [784, 10]Epochs: 60Mini batch size: 10Eta: 0.500000The max accuracy is 0.8671The final accuracy is 0.8671Spent time: 261.6 seconds
Network size: [784, 10]Epochs: 30Mini batch size: 5Eta: 0.100000The max accuracy is 0.7402The final accuracy is 0.7402Spent time: 135.9 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 5Eta: 0.500000The max accuracy is 0.6970The final accuracy is 0.6970Spent time: 135.8 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 5Eta: 1.000000The max accuracy is 0.0981The final accuracy is 0.0981Spent time: 136.4 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 5Eta: 2.000000The max accuracy is 0.1057The final accuracy is 0.1057Spent time: 135.7 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 5Eta: 3.000000The max accuracy is 0.0869The final accuracy is 0.0869Spent time: 135.8 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 10Eta: 0.100000The max accuracy is 0.7220The final accuracy is 0.7220Spent time: 131.2 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 10Eta: 0.500000The max accuracy is 0.7260The final accuracy is 0.7260Spent time: 131.2 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 10Eta: 1.000000The max accuracy is 0.0922The final accuracy is 0.0922Spent time: 131.3 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 10Eta: 2.000000The max accuracy is 0.1036The final accuracy is 0.1036Spent time: 131.1 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 10Eta: 3.000000The max accuracy is 0.1154The final accuracy is 0.1154Spent time: 131.2 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 15Eta: 0.100000The max accuracy is 0.5725The final accuracy is 0.5725Spent time: 129.5 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 15Eta: 0.500000The max accuracy is 0.6534The final accuracy is 0.6534Spent time: 129.5 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 15Eta: 1.000000The max accuracy is 0.0822The final accuracy is 0.0822Spent time: 129.7 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 15Eta: 2.000000The max accuracy is 0.0878The final accuracy is 0.0878Spent time: 129.5 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 15Eta: 3.000000The max accuracy is 0.1065The final accuracy is 0.1065Spent time: 129.9 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 20Eta: 0.100000The max accuracy is 0.5407The final accuracy is 0.5407Spent time: 128.8 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 20Eta: 0.500000The max accuracy is 0.7420The final accuracy is 0.7420Spent time: 128.6 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 20Eta: 1.000000The max accuracy is 0.1097The final accuracy is 0.1097Spent time: 128.8 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 20Eta: 2.000000The max accuracy is 0.0910The final accuracy is 0.0910Spent time: 128.9 secondsNetwork size: [784, 10]Epochs: 30Mini batch size: 20Eta: 3.000000The max accuracy is 0.1179The final accuracy is 0.1179Spent time: 128.8 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 5Eta: 0.100000The max accuracy is 0.7121The final accuracy is 0.7121Spent time: 270.7 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 5Eta: 0.500000The max accuracy is 0.7471The final accuracy is 0.7471Spent time: 270.5 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 5Eta: 1.000000The max accuracy is 0.1062The final accuracy is 0.1062Spent time: 271.4 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 5Eta: 2.000000The max accuracy is 0.0773The final accuracy is 0.0773Spent time: 271.2 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 5Eta: 3.000000The max accuracy is 0.1032The final accuracy is 0.1032Spent time: 271.3 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 10Eta: 0.100000The max accuracy is 0.7646The final accuracy is 0.7646Spent time: 261.7 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 10Eta: 0.500000The max accuracy is 0.8671The final accuracy is 0.8671Spent time: 261.6 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 10Eta: 1.000000The max accuracy is 0.1141The final accuracy is 0.1141Spent time: 262.2 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 10Eta: 2.000000The max accuracy is 0.1238The final accuracy is 0.1238Spent time: 262.2 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 10Eta: 3.000000The max accuracy is 0.1029The final accuracy is 0.1029Spent time: 262.2 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 15Eta: 0.100000The max accuracy is 0.6377The final accuracy is 0.6377Spent time: 259.7 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 15Eta: 0.500000The max accuracy is 0.8092The final accuracy is 0.8092Spent time: 259.5 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 15Eta: 1.000000The max accuracy is 0.0773The final accuracy is 0.0773Spent time: 259.5 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 15Eta: 2.000000The max accuracy is 0.0828The final accuracy is 0.0828Spent time: 259.2 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 15Eta: 3.000000The max accuracy is 0.1151The final accuracy is 0.1151Spent time: 259.3 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 20Eta: 0.100000The max accuracy is 0.7079The final accuracy is 0.7079Spent time: 257.7 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 20Eta: 0.500000The max accuracy is 0.8629The final accuracy is 0.8629Spent time: 257.5 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 20Eta: 1.000000The max accuracy is 0.1052The final accuracy is 0.1052Spent time: 257.5 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 20Eta: 2.000000The max accuracy is 0.1023The final accuracy is 0.1023Spent time: 257.6 secondsNetwork size: [784, 10]Epochs: 60Mini batch size: 20Eta: 3.000000The max accuracy is 0.1153The final accuracy is 0.1153Spent time: 258.1 seconds