Skip to content

Commit 746e415

Browse files
committed
Upgrade code to be compatible with TensorFlow 1.0.0 (which introduced breaking API changes)
1 parent 4bd101c commit 746e415

12 files changed

Lines changed: 21 additions & 21 deletions

python/01_basics.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
# We'll use our values from [-3, 3] to create a Gaussian Distribution
3737
sigma = 1.0
3838
mean = 0.0
39-
z = (tf.exp(tf.neg(tf.pow(x - mean, 2.0) /
39+
z = (tf.exp(tf.negative(tf.pow(x - mean, 2.0) /
4040
(2.0 * tf.pow(sigma, 2.0)))) *
4141
(1.0 / (sigma * tf.sqrt(2.0 * 3.1415))))
4242

@@ -60,7 +60,7 @@
6060
print(tf.shape(z).eval())
6161

6262
# %% We can combine tensors like so:
63-
print(tf.pack([tf.shape(z), tf.shape(z), [3], [4]]).eval())
63+
print(tf.stack([tf.shape(z), tf.shape(z), [3], [4]]).eval())
6464

6565
# %% Let's multiply the two to get a 2d gaussian
6666
z_2d = tf.matmul(tf.reshape(z, [n_values, 1]), tf.reshape(z, [1, n_values]))
@@ -71,7 +71,7 @@
7171
# %% For fun let's create a gabor patch:
7272
x = tf.reshape(tf.sin(tf.linspace(-3.0, 3.0, n_values)), [n_values, 1])
7373
y = tf.reshape(tf.ones_like(x), [1, n_values])
74-
z = tf.mul(tf.matmul(x, y), z_2d)
74+
z = tf.multiply(tf.matmul(x, y), z_2d)
7575
plt.imshow(z.eval())
7676

7777
# %% We can also list all the operations of a graph:
@@ -81,14 +81,14 @@
8181
# %% Lets try creating a generic function for computing the same thing:
8282
def gabor(n_values=32, sigma=1.0, mean=0.0):
8383
x = tf.linspace(-3.0, 3.0, n_values)
84-
z = (tf.exp(tf.neg(tf.pow(x - mean, 2.0) /
84+
z = (tf.exp(tf.negative(tf.pow(x - mean, 2.0) /
8585
(2.0 * tf.pow(sigma, 2.0)))) *
8686
(1.0 / (sigma * tf.sqrt(2.0 * 3.1415))))
8787
gauss_kernel = tf.matmul(
8888
tf.reshape(z, [n_values, 1]), tf.reshape(z, [1, n_values]))
8989
x = tf.reshape(tf.sin(tf.linspace(-3.0, 3.0, n_values)), [n_values, 1])
9090
y = tf.reshape(tf.ones_like(x), [1, n_values])
91-
gabor_kernel = tf.mul(tf.matmul(x, y), gauss_kernel)
91+
gabor_kernel = tf.multiply(tf.matmul(x, y), gauss_kernel)
9292
return gabor_kernel
9393

9494
# %% Confirm this does something:
@@ -112,7 +112,7 @@ def convolve(img, W):
112112
img = tf.reshape(img, dims)
113113
# if the image is 3 channels, then our convolution
114114
# kernel needs to be repeated for each input channel
115-
W = tf.concat(2, [W, W, W])
115+
W = tf.concat(axis=2, values=[W, W, W])
116116

117117
# Stride is how many values to skip for the dimensions of
118118
# num, height, width, channels

python/02_linear_regression.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# methods.
3131
W = tf.Variable(tf.random_normal([1]), name='weight')
3232
b = tf.Variable(tf.random_normal([1]), name='bias')
33-
Y_pred = tf.add(tf.mul(X, W), b)
33+
Y_pred = tf.add(tf.multiply(X, W), b)
3434

3535
# %% Loss function will measure the distance between our observations
3636
# and predictions and average over them.
@@ -52,7 +52,7 @@
5252
with tf.Session() as sess:
5353
# Here we tell tensorflow that we want to initialize all
5454
# the variables in the graph so we can use them
55-
sess.run(tf.initialize_all_variables())
55+
sess.run(tf.global_variables_initializer())
5656

5757
# Fit all training data
5858
prev_training_cost = 0.0

python/03_polynomial_regression.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
Y_pred = tf.Variable(tf.random_normal([1]), name='bias')
2929
for pow_i in range(1, 5):
3030
W = tf.Variable(tf.random_normal([1]), name='weight_%d' % pow_i)
31-
Y_pred = tf.add(tf.mul(tf.pow(X, pow_i), W), Y_pred)
31+
Y_pred = tf.add(tf.multiply(tf.pow(X, pow_i), W), Y_pred)
3232

3333
# %% Loss function will measure the distance between our observations
3434
# and predictions and average over them.
@@ -50,7 +50,7 @@
5050
with tf.Session() as sess:
5151
# Here we tell tensorflow that we want to initialize all
5252
# the variables in the graph so we can use them
53-
sess.run(tf.initialize_all_variables())
53+
sess.run(tf.global_variables_initializer())
5454

5555
# Fit all training data
5656
prev_training_cost = 0.0

python/04_logistic_regression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
# %% We now create a new session to actually perform the initialization the
7676
# variables:
7777
sess = tf.Session()
78-
sess.run(tf.initialize_all_variables())
78+
sess.run(tf.global_variables_initializer())
7979

8080
# %% Now actually do some training:
8181
batch_size = 100

python/05_basic_convnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
# %% We now create a new session to actually perform the initialization the
8484
# variables:
8585
sess = tf.Session()
86-
sess.run(tf.initialize_all_variables())
86+
sess.run(tf.global_variables_initializer())
8787

8888
# %% We'll train in minibatches and report accuracy:
8989
batch_size = 100

python/06_modern_convnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
# %% We now create a new session to actually perform the initialization the
5252
# variables:
5353
sess = tf.Session()
54-
sess.run(tf.initialize_all_variables())
54+
sess.run(tf.global_variables_initializer())
5555

5656
# %% We'll train in minibatches and report accuracy:
5757
n_epochs = 10

python/07_autoencoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_mnist():
8484
# %%
8585
# We create a session to use the graph
8686
sess = tf.Session()
87-
sess.run(tf.initialize_all_variables())
87+
sess.run(tf.global_variables_initializer())
8888

8989
# %%
9090
# Fit all training data

python/08_denoising_autoencoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_mnist():
9595
# %%
9696
# We create a session to use the graph
9797
sess = tf.Session()
98-
sess.run(tf.initialize_all_variables())
98+
sess.run(tf.global_variables_initializer())
9999

100100
# %%
101101
# Fit all training data

python/09_convolutional_autoencoder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def autoencoder(input_shape=[None, 784],
102102
output = lrelu(tf.add(
103103
tf.nn.conv2d_transpose(
104104
current_input, W,
105-
tf.pack([tf.shape(x)[0], shape[1], shape[2], shape[3]]),
105+
tf.stack([tf.shape(x)[0], shape[1], shape[2], shape[3]]),
106106
strides=[1, 2, 2, 1], padding='SAME'), b))
107107
current_input = output
108108

@@ -137,7 +137,7 @@ def test_mnist():
137137
# %%
138138
# We create a session to use the graph
139139
sess = tf.Session()
140-
sess.run(tf.initialize_all_variables())
140+
sess.run(tf.global_variables_initializer())
141141

142142
# %%
143143
# Fit all training data

python/10_residual_network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def test_mnist():
134134
# %% We now create a new session to actually perform the initialization the
135135
# variables:
136136
sess = tf.Session()
137-
sess.run(tf.initialize_all_variables())
137+
sess.run(tf.global_variables_initializer())
138138

139139
# %% We'll train in minibatches and report accuracy:
140140
batch_size = 50

0 commit comments

Comments
 (0)