diff --git a/network3.py b/network3.py index ff8afa8..dc9133f 100644 --- a/network3.py +++ b/network3.py @@ -224,9 +224,9 @@ def __init__(self, filter_shape, image_shape, poolsize=(2, 2), def set_inpt(self, inpt, inpt_dropout, mini_batch_size): self.inpt = inpt.reshape(self.image_shape) - conv_out = conv.conv2d( + conv_out = theano.tensor.nnet.conv2d( input=self.inpt, filters=self.w, filter_shape=self.filter_shape, - image_shape=self.image_shape) + input_shape=self.image_shape) pooled_out = pool_2d( input=conv_out, ws=self.poolsize, ignore_border=True) self.output = self.activation_fn( diff --git a/test.py b/test.py index d1f4996..ea4864f 100644 --- a/test.py +++ b/test.py @@ -15,16 +15,28 @@ dobrzanski.michal.daniel@gmail.com """ +from PIL import Image + + +def show_img(char_np_array): + char_np_array = char_np_array.reshape(28, 28) + char_img = Image.fromarray((char_np_array * 255)) + char_img.show() + + # ---------------------- # - read the input data: -''' import mnist_loader + training_data, validation_data, test_data = mnist_loader.load_data_wrapper() training_data = list(training_data) -''' + +show_img(training_data[0][0]) + + # --------------------- # - network.py example: -#import network +# import network ''' net = network.Network([784, 30, 10]) @@ -33,7 +45,7 @@ # ---------------------- # - network2.py example: -#import network2 +# import network2 ''' net = network2.Network([784, 30, 10], cost=network2.CrossEntropyCost) @@ -86,7 +98,6 @@ monitor_evaluation_accuracy=True) ''' - # ---------------------- # Theano and CUDA # ---------------------- @@ -124,18 +135,19 @@ """ + + def testTheano(): - from theano import function, config, shared, sandbox - import theano.tensor as T + from theano import function, config, shared, tensor import numpy import time - print("Testing Theano library...") + vlen = 10 * 30 * 768 # 10 x #cores x # threads per core iters = 1000 rng = numpy.random.RandomState(22) x = shared(numpy.asarray(rng.rand(vlen), config.floatX)) - f = function([], T.exp(x)) + f = function([], tensor.exp(x)) print(f.maker.fgraph.toposort()) t0 = time.time() for i in range(iters): @@ -143,23 +155,29 @@ def testTheano(): t1 = time.time() print("Looping %d times took %f seconds" % (iters, t1 - t0)) print("Result is %s" % (r,)) - if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]): + if numpy.any([isinstance(x.op, tensor.Elemwise) and + ('Gpu' not in type(x.op).__name__) + for x in f.maker.fgraph.toposort()]): print('Used the cpu') else: print('Used the gpu') -# Perform check: -#testTheano() +# Perform check: +testTheano() + # ---------------------- # - network3.py example: import network3 -from network3 import Network, ConvPoolLayer, FullyConnectedLayer, SoftmaxLayer # softmax plus log-likelihood cost is more common in modern image classification networks. +from network3 import Network, ConvPoolLayer, FullyConnectedLayer, \ + SoftmaxLayer # softmax plus log-likelihood cost is more common in modern image classification networks. # read data: +''' training_data, validation_data, test_data = network3.load_data_shared() # mini-batch size: mini_batch_size = 10 +''' # chapter 6 - shallow architecture using just a single hidden layer, containing 100 hidden neurons. ''' @@ -195,6 +213,7 @@ def testTheano(): ''' # chapter 6 - rectified linear units and some l2 regularization (lmbda=0.1) => even better accuracy +''' from network3 import ReLU net = Network([ ConvPoolLayer(image_shape=(mini_batch_size, 1, 28, 28), @@ -208,3 +227,4 @@ def testTheano(): FullyConnectedLayer(n_in=40*4*4, n_out=100, activation_fn=ReLU), SoftmaxLayer(n_in=100, n_out=10)], mini_batch_size) net.SGD(training_data, 60, mini_batch_size, 0.03, validation_data, test_data, lmbda=0.1) +'''