The book was written with Python 2 code. Let's make all the changes needed for Python 3 compatibility at once.
We'll also need to update some parts of network3.py
for Theano 1.0.3.
Here's what you need to do:
The only modifications I've made in these files is updating them for Python 3 (specifically, I did the changes below).
Do the following replacements (Ctrl + H will usually work):
Python 2 | Python 3 | Files |
---|---|---|
xrange | range | conv.py, network.py, network2.py, network3.py |
print "whatever" | print("whatever") | mnist_average_darkness.py, mnist_svm.py, network.py, network2.py, network3.py |
cPickle | pickle | expand_mnist.py, mnist_loader.py, network3.py |
pickle.load(f) | pickle.load(f, encoding="latin1") | expand_mnist.py, mnist_loader.py, network3.py |
return -T.mean(T.log( | return T.mean(-T.log( | network3.py |
np.random.RandomState(0).randint(999999) | np.random.randint(999999) | network3.py |
iteritems() | items() | mnist_average_darkness.py |
zip(whatever) | list(zip(whatever)) | conv.py, mnist_loader.py |
from theano.tensor.signal import downsample | from theano.tensor.signal.pool import pool_2d | network3.py |
pooled_out = downsample.max_pool_2d( | pooled_out = pool_2d( | network3.py |
num_training_batches = size... num_validation_batches = size... num_test_batches = size... |
num_training_batches = int(size...) num_validation_batches = int(size...) num_test_batches = int(size...) |
network3.py |
ds= | ws= | network3.py |
from theano.tensor.nnet import conv | from theano.tensor.nnet import conv2d | network3.py |
conv_out = conv.conv2d( | conv_out = conv2d( | network3.py |
image_shape=self.image_shape | input_shape=self.image_shape | network3.py |