From fbd527871fe26a140c71d548c219be805a2eada1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20L=C3=A9onardon?= Date: Tue, 25 Jun 2019 14:25:18 +0200 Subject: [PATCH 1/4] Fix deprecated warnings from theano 1.0.4. --- network3.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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( From 506f261ff60074c82466875dbfc729da86ab5c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20L=C3=A9onardon?= Date: Tue, 25 Jun 2019 14:25:33 +0200 Subject: [PATCH 2/4] Cosmetics. --- test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test.py b/test.py index d1f4996..568f902 100644 --- a/test.py +++ b/test.py @@ -126,7 +126,7 @@ """ def testTheano(): from theano import function, config, shared, sandbox - import theano.tensor as T + import theano.tensor import numpy import time print("Testing Theano library...") @@ -135,7 +135,7 @@ def testTheano(): rng = numpy.random.RandomState(22) x = shared(numpy.asarray(rng.rand(vlen), config.floatX)) - f = function([], T.exp(x)) + f = function([], theano.tensor.exp(x)) print(f.maker.fgraph.toposort()) t0 = time.time() for i in range(iters): @@ -143,7 +143,7 @@ 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, theano.tensor.Elemwise) for x in f.maker.fgraph.toposort()]): print('Used the cpu') else: print('Used the gpu') From 328d709b8bcbb246969ed2a3aa3a0c6982b5c5e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20L=C3=A9onardon?= Date: Wed, 26 Jun 2019 10:10:30 +0200 Subject: [PATCH 3/4] Update theano test from http://deeplearning.net/software/theano/tutorial/using_gpu.html#testing-theano-with-gpu. --- test.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test.py b/test.py index 568f902..9a525e3 100644 --- a/test.py +++ b/test.py @@ -17,11 +17,9 @@ # ---------------------- # - read the input data: -''' import mnist_loader training_data, validation_data, test_data = mnist_loader.load_data_wrapper() training_data = list(training_data) -''' # --------------------- # - network.py example: #import network @@ -125,17 +123,16 @@ """ def testTheano(): - from theano import function, config, shared, sandbox - import theano.tensor + 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([], theano.tensor.exp(x)) + f = function([], tensor.exp(x)) print(f.maker.fgraph.toposort()) t0 = time.time() for i in range(iters): @@ -143,12 +140,14 @@ 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, theano.tensor.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() +testTheano() # ---------------------- @@ -157,9 +156,11 @@ def testTheano(): 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. ''' @@ -196,6 +197,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), filter_shape=(20, 1, 5, 5), @@ -208,3 +210,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) +''' From 4f93337cd9b986e61d6c2771e0c022bb9782a614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20L=C3=A9onardon?= Date: Wed, 26 Jun 2019 10:45:04 +0200 Subject: [PATCH 4/4] Add show_img function. --- test.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/test.py b/test.py index 9a525e3..ea4864f 100644 --- a/test.py +++ b/test.py @@ -15,14 +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]) @@ -31,7 +45,7 @@ # ---------------------- # - network2.py example: -#import network2 +# import network2 ''' net = network2.Network([784, 30, 10], cost=network2.CrossEntropyCost) @@ -84,7 +98,6 @@ monitor_evaluation_accuracy=True) ''' - # ---------------------- # Theano and CUDA # ---------------------- @@ -122,6 +135,8 @@ """ + + def testTheano(): from theano import function, config, shared, tensor import numpy @@ -146,14 +161,16 @@ def testTheano(): print('Used the cpu') else: print('Used the gpu') + + # 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: ''' @@ -196,8 +213,8 @@ def testTheano(): ''' # chapter 6 - rectified linear units and some l2 regularization (lmbda=0.1) => even better accuracy -from network3 import ReLU ''' +from network3 import ReLU net = Network([ ConvPoolLayer(image_shape=(mini_batch_size, 1, 28, 28), filter_shape=(20, 1, 5, 5),