Example for using function load_data and printing dataset¶
In [335]:
from hw3_utils import load_data
#downsample the training and validation dataset if needed, ds_rate should be larger than 1.
ds_rate=None
datasets = load_data(ds_rate=ds_rate,theano_shared=False)
train_set_x, train_set_y = datasets[0]
valid_set_x, valid_set_y = datasets[1]
test_set_x, test_set_y = datasets[2]
print(‘Current training data size is %i’%train_set_x.shape[0])
print(‘Current validation data size is %i’%valid_set_x.shape[0])
print(‘Current test data size is %i’%test_set_x.shape[0])
Current training data size is 40000
Current validation data size is 10000
Current test data size is 10000
In [243]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
class_=[‘airplane’,’automobile’,’bird’,’cat’,’deer’,’dog’,’frog’,’horse’,’ship’,’truck’]
#Choose an image index
i=15
plt.imshow(np.reshape(valid_set_x[i],(3,32,32)).transpose(1,2,0))
plt.xticks([])
plt.yticks([])
plt.title(‘Original picture’)
plt.xlabel(‘%s’%class_[valid_set_y[i]])
Out[243]:

In [ ]:
In [330]:
def t_up(x,N):
x_temp=np.reshape(x, (3,32*32))
n = []
for k in x_temp:
n += list(k[32*N:]) + list(k[:32*N])
return np.array(n)
def t_down(x,N):
x_temp=np.reshape(x, (3,32*32))
size = 32*32
n = []
for k in x_temp:
n += list(k[size-32*N:size]) + list(k[:size-32*N])
return np.array(n)
# problematic
def t_left(x,N):
x_temp=np.reshape(x, (3,32*32))
n = []
for k in x_temp:
k = np.reshape(k,(32,32),order=’F’).transpose().flatten()
n += list(k[32*N:]) + list(k[:32*N])
return np.array(n)
In [ ]:
In [ ]:
ECBM E6040 Homework 3 – Programming Problem¶
Problem 1: Implement the convolutional neural network depicted in this problem¶
In [1]:
from hw3 import *
C:\Users\jiang\Anaconda2\lib\site-packages\theano\tensor\signal\downsample.py:6: UserWarning: downsample module has been moved to the theano.tensor.signal.pool module.
“downsample module has been moved to the theano.tensor.signal.pool module.”)
In [2]:
test_lenet()
… building the model
—————————————————————————
NameError Traceback (most recent call last)
—-> 1 test_lenet()
C:\Users\jiang\Desktop\NN\e4040_hw3_bj2344\src\hw3.py in test_lenet(batch_size)
89 givens={
90 x: test_set_x[index * batch_size: (index + 1) * batch_size],
—> 91 y: test_set_y[index * batch_size: (index + 1) * batch_size]
92 }
93 )
C:\Users\jiang\Anaconda2\lib\site-packages\theano\compile\function.pyc in function(inputs, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input)
318 on_unused_input=on_unused_input,
319 profile=profile,
–> 320 output_keys=output_keys)
321 # We need to add the flag check_aliased inputs if we have any mutable or
322 # borrowed used defined inputs
C:\Users\jiang\Anaconda2\lib\site-packages\theano\compile\pfunc.pyc in pfunc(params, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input, output_keys)
477 accept_inplace=accept_inplace, name=name,
478 profile=profile, on_unused_input=on_unused_input,
–> 479 output_keys=output_keys)
480
481
C:\Users\jiang\Anaconda2\lib\site-packages\theano\compile\function_module.pyc in orig_function(inputs, outputs, mode, accept_inplace, name, profile, on_unused_input, output_keys)
1775 on_unused_input=on_unused_input,
1776 output_keys=output_keys).create(
-> 1777 defaults)
1778
1779 t2 = time.time()
C:\Users\jiang\Anaconda2\lib\site-packages\theano\compile\function_module.pyc in create(self, input_storage, trustme, storage_map)
1639 theano.config.traceback.limit = 0
1640 _fn, _i, _o = self.linker.make_thunk(
-> 1641 input_storage=input_storage_lists, storage_map=storage_map)
1642 finally:
1643 theano.config.traceback.limit = limit_orig
C:\Users\jiang\Anaconda2\lib\site-packages\theano\gof\link.pyc in make_thunk(self, input_storage, output_storage, storage_map)
688 return self.make_all(input_storage=input_storage,
689 output_storage=output_storage,
–> 690 storage_map=storage_map)[:3]
691
692 def make_all(self, input_storage, output_storage):
C:\Users\jiang\Anaconda2\lib\site-packages\theano\gof\vm.pyc in make_all(self, profiler, input_storage, output_storage, storage_map)
1045 computed,
1046 compute_map,
-> 1047 self.updated_vars,
1048 )
1049
C:\Users\jiang\Anaconda2\lib\site-packages\theano\gof\vm.pyc in make_vm(self, nodes, thunks, input_storage, output_storage, storage_map, post_thunk_clear, computed, compute_map, updated_vars)
911
912 c0 = sys.getrefcount(node_n_inputs)
–> 913 vm = CVM(
914 nodes,
915 thunks,
NameError: global name ‘CVM’ is not defined
In [ ]:
Problem 2: Bullet 1: Augmentation by translation¶
Show a 4*4 figure of 16 input images with this augmentation
In [ ]:
from hw3_utils import load_data
from hw3 import translate_image
Implement the neural network with this augmentation, show the improvement
In [ ]:
from hw3 import test_lenet_translation
Problem 2: Bullet 2: Augmentation by rotation¶
Show a 4*4 figure of 16 input images with this augmentation
In [ ]:
from hw3_utils import load_data
from hw3 import rotate_image
Implement the neural network with this augmentation, show the improvement
In [ ]:
from hw3 import test_lenet_rotation
Problem 2: Bullet 3: Augmentation by flipping¶
Show a 4*4 figure of 16 input images with this augmentation
In [ ]:
from hw3_utils import load_data
from hw3 import flip_image
Implement the neural network with this augmentation, show the improvement
In [ ]:
from hw3 import test_lenet_flip
Problem 2: Bullet 4: Augmentation by injecting noise into input¶
Show a 4*4 figure of 16 input images with this augmentation
In [ ]:
from hw3_utils import load_data
from hw3 import noise_injection
Implement the neural network with this augmentation, show the improvement
In [ ]:
from hw3 import test_lenet_inject_noise_input
Problem 3: Implement your own achritecture to achieve at least 80% testing accuracy on CIFAR-10 test set¶
In [ ]:
from hw3 import MY_lenet
Problem 4: Implement the convolutional neural network depicted in this problem¶
In [ ]:
from hw3 import MY_CNN