Skip to content

Commit be6f19a

Browse files
committedJan 9, 2017
edit tf init
1 parent cadd69d commit be6f19a

29 files changed

+155
-43
lines changed
 

‎tensorflowTUT/tensorflow11_build_network.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ def add_layer(inputs, in_size, out_size, activation_function=None):
4242
# important step
4343
# tf.initialize_all_variables() no long valid from
4444
# 2017-03-02 if using tensorflow >= 0.12
45-
init = tf.global_variables_initializer()
45+
if int((tf.__version__).split('.')[1]) < 12:
46+
init = tf.initialize_all_variables()
47+
else:
48+
init = tf.global_variables_initializer()
4649
sess = tf.Session()
4750
sess.run(init)
4851

‎tensorflowTUT/tensorflow12_plut_result.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ def add_layer(inputs, in_size, out_size, activation_function=None):
4343
# important step
4444
# tf.initialize_all_variables() no long valid from
4545
# 2017-03-02 if using tensorflow >= 0.12
46-
init = tf.global_variables_initializer()
46+
if int((tf.__version__).split('.')[1]) < 12:
47+
init = tf.initialize_all_variables()
48+
else:
49+
init = tf.global_variables_initializer()
4750
sess = tf.Session()
4851
sess.run(init)
4952

‎tensorflowTUT/tensorflow7_variable.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919
# tf.initialize_all_variables() no long valid from
2020
# 2017-03-02 if using tensorflow >= 0.12
21-
init = tf.global_variables_initializer() # must have if define variable
21+
if int((tf.__version__).split('.')[1]) < 12:
22+
init = tf.initialize_all_variables()
23+
else:
24+
init = tf.global_variables_initializer()
2225

2326
with tf.Session() as sess:
2427
sess.run(init)

‎tensorflowTUT/tf11_build_network/full_code.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ def add_layer(inputs, in_size, out_size, activation_function=None):
4444
sess = tf.Session()
4545
# tf.initialize_all_variables() no long valid from
4646
# 2017-03-02 if using tensorflow >= 0.12
47-
sess.run(tf.global_variables_initializer())
47+
if int((tf.__version__).split('.')[1]) < 12:
48+
init = tf.initialize_all_variables()
49+
else:
50+
init = tf.global_variables_initializer()
51+
sess.run(init)
4852

4953
for i in range(1000):
5054
# training

‎tensorflowTUT/tf12_plot_result/for_you_to_practice.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ def add_layer(inputs, in_size, out_size, activation_function=None):
4444
sess= tf.Session()
4545
# tf.initialize_all_variables() no long valid from
4646
# 2017-03-02 if using tensorflow >= 0.12
47-
sess.run(tf.global_variables_initializer())
47+
if int((tf.__version__).split('.')[1]) < 12:
48+
init = tf.initialize_all_variables()
49+
else:
50+
init = tf.global_variables_initializer()
51+
sess.run(init)
4852

4953
for i in range(1000):
5054
# training

‎tensorflowTUT/tf12_plot_result/full_code.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ def add_layer(inputs, in_size, out_size, activation_function=None):
4444
sess = tf.Session()
4545
# tf.initialize_all_variables() no long valid from
4646
# 2017-03-02 if using tensorflow >= 0.12
47-
sess.run(tf.global_variables_initializer())
47+
if int((tf.__version__).split('.')[1]) < 12:
48+
init = tf.initialize_all_variables()
49+
else:
50+
init = tf.global_variables_initializer()
51+
sess.run(init)
4852

4953
# plot the real data
5054
fig = plt.figure()

‎tensorflowTUT/tf14_tensorboard/for_you_to_practice.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ def add_layer(inputs, in_size, out_size, activation_function=None):
4040

4141
# tf.initialize_all_variables() no long valid from
4242
# 2017-03-02 if using tensorflow >= 0.12
43-
sess.run(tf.global_variables_initializer())
43+
if int((tf.__version__).split('.')[1]) < 12:
44+
init = tf.initialize_all_variables()
45+
else:
46+
init = tf.global_variables_initializer()
47+
sess.run(init)
4448

4549
# direct to the local dir and run this in terminal:
4650
# $ tensorboard --logdir=logs

‎tensorflowTUT/tf14_tensorboard/full_code.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ def add_layer(inputs, in_size, out_size, activation_function=None):
5151

5252
# tf.initialize_all_variables() no long valid from
5353
# 2017-03-02 if using tensorflow >= 0.12
54-
sess.run(tf.global_variables_initializer())
54+
if int((tf.__version__).split('.')[1]) < 12:
55+
init = tf.initialize_all_variables()
56+
else:
57+
init = tf.global_variables_initializer()
58+
sess.run(init)
5559

5660
# direct to the local dir and run this in terminal:
5761
# $ tensorboard --logdir=logs

‎tensorflowTUT/tf15_tensorboard/for_you_to_practice.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ def add_layer(inputs, in_size, out_size, activation_function=None):
5454
# important step
5555
# tf.initialize_all_variables() no long valid from
5656
# 2017-03-02 if using tensorflow >= 0.12
57-
sess.run(tf.global_variables_initializer())
57+
if int((tf.__version__).split('.')[1]) < 12:
58+
init = tf.initialize_all_variables()
59+
else:
60+
init = tf.global_variables_initializer()
61+
sess.run(init)
5862
# direct to the local dir and run this in terminal:
5963
# $ tensorboard --logdir=logs

‎tensorflowTUT/tf15_tensorboard/full_code.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ def add_layer(inputs, in_size, out_size, n_layer, activation_function=None):
6363

6464
# tf.initialize_all_variables() no long valid from
6565
# 2017-03-02 if using tensorflow >= 0.12
66-
sess.run(tf.global_variables_initializer())
66+
if int((tf.__version__).split('.')[1]) < 12:
67+
init = tf.initialize_all_variables()
68+
else:
69+
init = tf.global_variables_initializer()
70+
sess.run(init)
6771

6872
for i in range(1000):
6973
sess.run(train_step, feed_dict={xs: x_data, ys: y_data})

‎tensorflowTUT/tf16_classification/for_you_to_practice.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ def add_layer(inputs, in_size, out_size, activation_function=None, ):
3535
# important step
3636
# tf.initialize_all_variables() no long valid from
3737
# 2017-03-02 if using tensorflow >= 0.12
38-
sess.run(tf.global_variables_initializer())
38+
if int((tf.__version__).split('.')[1]) < 12:
39+
init = tf.initialize_all_variables()
40+
else:
41+
init = tf.global_variables_initializer()
42+
sess.run(init)
3943

4044
for i in range(1000):
4145
pass

‎tensorflowTUT/tf16_classification/full_code.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ def compute_accuracy(v_xs, v_ys):
4747
# important step
4848
# tf.initialize_all_variables() no long valid from
4949
# 2017-03-02 if using tensorflow >= 0.12
50-
sess.run(tf.global_variables_initializer())
50+
if int((tf.__version__).split('.')[1]) < 12:
51+
init = tf.initialize_all_variables()
52+
else:
53+
init = tf.global_variables_initializer()
54+
sess.run(init)
5155

5256
for i in range(1000):
5357
batch_xs, batch_ys = mnist.train.next_batch(100)

‎tensorflowTUT/tf17_dropout/for_you_to_practice.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ def add_layer(inputs, in_size, out_size, layer_name, activation_function=None, )
5454

5555
# tf.initialize_all_variables() no long valid from
5656
# 2017-03-02 if using tensorflow >= 0.12
57-
sess.run(tf.global_variables_initializer())
57+
if int((tf.__version__).split('.')[1]) < 12:
58+
init = tf.initialize_all_variables()
59+
else:
60+
init = tf.global_variables_initializer()
61+
sess.run(init)
5862

5963
for i in range(500):
6064
sess.run(train_step, feed_dict={xs: X_train, ys: y_train})

‎tensorflowTUT/tf17_dropout/full_code.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ def add_layer(inputs, in_size, out_size, layer_name, activation_function=None, )
5858

5959
# tf.initialize_all_variables() no long valid from
6060
# 2017-03-02 if using tensorflow >= 0.12
61-
sess.run(tf.global_variables_initializer())
61+
if int((tf.__version__).split('.')[1]) < 12:
62+
init = tf.initialize_all_variables()
63+
else:
64+
init = tf.global_variables_initializer()
65+
sess.run(init)
6266

6367
for i in range(500):
6468
# here to determine the keeping probability

‎tensorflowTUT/tf18_CNN2/for_you_to_practice.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ def max_pool_2x2(x):
5151
# important step
5252
# tf.initialize_all_variables() no long valid from
5353
# 2017-03-02 if using tensorflow >= 0.12
54-
sess.run(tf.global_variables_initializer())
54+
if int((tf.__version__).split('.')[1]) < 12:
55+
init = tf.initialize_all_variables()
56+
else:
57+
init = tf.global_variables_initializer()
58+
sess.run(init)
5559

5660
for i in range(1000):
5761
batch_xs, batch_ys = mnist.train.next_batch(100)

‎tensorflowTUT/tf18_CNN2/full_code.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ def max_pool_2x2(x):
6060
# important step
6161
# tf.initialize_all_variables() no long valid from
6262
# 2017-03-02 if using tensorflow >= 0.12
63-
sess.run(tf.global_variables_initializer())
63+
if int((tf.__version__).split('.')[1]) < 12:
64+
init = tf.initialize_all_variables()
65+
else:
66+
init = tf.global_variables_initializer()
67+
sess.run(init)
6468

6569
for i in range(1000):
6670
batch_xs, batch_ys = mnist.train.next_batch(100)

‎tensorflowTUT/tf18_CNN3/for_you_to_practice.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ def max_pool_2x2(x):
6060
# important step
6161
# tf.initialize_all_variables() no long valid from
6262
# 2017-03-02 if using tensorflow >= 0.12
63-
sess.run(tf.global_variables_initializer())
63+
if int((tf.__version__).split('.')[1]) < 12:
64+
init = tf.initialize_all_variables()
65+
else:
66+
init = tf.global_variables_initializer()
67+
sess.run(init)
6468

6569
for i in range(1000):
6670
batch_xs, batch_ys = mnist.train.next_batch(100)

‎tensorflowTUT/tf18_CNN3/full_code.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ def max_pool_2x2(x):
7979
# important step
8080
# tf.initialize_all_variables() no long valid from
8181
# 2017-03-02 if using tensorflow >= 0.12
82-
sess.run(tf.global_variables_initializer())
82+
if int((tf.__version__).split('.')[1]) < 12:
83+
init = tf.initialize_all_variables()
84+
else:
85+
init = tf.global_variables_initializer()
86+
sess.run(init)
8387

8488
for i in range(1000):
8589
batch_xs, batch_ys = mnist.train.next_batch(100)

‎tensorflowTUT/tf19_saver.py

+18-15
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,25 @@
1010
import tensorflow as tf
1111
import numpy as np
1212

13-
## Save to file
13+
# Save to file
1414
# remember to define the same dtype and shape when restore
15-
##W = tf.Variable([[1,2,3],[3,4,5]], dtype=tf.float32, name='weights')
16-
##b = tf.Variable([[1,2,3]], dtype=tf.float32, name='biases')
17-
##
18-
## tf.initialize_all_variables() no long valid from
19-
## 2017-03-02 if using tensorflow >= 0.12
20-
##init = tf.global_variables_initializer()
21-
##
22-
##saver = tf.train.Saver()
23-
##
24-
##with tf.Session() as sess:
25-
## sess.run(init)
26-
## save_path = saver.save(sess, "my_net/save_net.ckpt")
27-
## print("Save to path: ", save_path)
28-
##
15+
# W = tf.Variable([[1,2,3],[3,4,5]], dtype=tf.float32, name='weights')
16+
# b = tf.Variable([[1,2,3]], dtype=tf.float32, name='biases')
17+
18+
# tf.initialize_all_variables() no long valid from
19+
# 2017-03-02 if using tensorflow >= 0.12
20+
# if int((tf.__version__).split('.')[1]) < 12:
21+
# init = tf.initialize_all_variables()
22+
# else:
23+
# init = tf.global_variables_initializer()
24+
#
25+
# saver = tf.train.Saver()
26+
#
27+
# with tf.Session() as sess:
28+
# sess.run(init)
29+
# save_path = saver.save(sess, "my_net/save_net.ckpt")
30+
# print("Save to path: ", save_path)
31+
2932

3033
################################################
3134
# restore variables

‎tensorflowTUT/tf20_RNN2.2/for_practicing.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ def _bias_variable(self, shape, name='biases'):
103103

104104
# tf.initialize_all_variables() no long valid from
105105
# 2017-03-02 if using tensorflow >= 0.12
106-
sess.run(tf.global_variables_initializer())
106+
if int((tf.__version__).split('.')[1]) < 12:
107+
init = tf.initialize_all_variables()
108+
else:
109+
init = tf.global_variables_initializer()
110+
sess.run(init)
107111
plt.ion()
108112
plt.show()
109113
for i in range(200):

‎tensorflowTUT/tf20_RNN2.2/full_code.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ def _bias_variable(self, shape, name='biases'):
119119
writer = tf.train.SummaryWriter("logs", sess.graph)
120120
# tf.initialize_all_variables() no long valid from
121121
# 2017-03-02 if using tensorflow >= 0.12
122-
sess.run(tf.global_variables_initializer())
122+
if int((tf.__version__).split('.')[1]) < 12:
123+
init = tf.initialize_all_variables()
124+
else:
125+
init = tf.global_variables_initializer()
126+
sess.run(init)
123127
# relocate to the local dir and run this line to view it on Chrome (http://0.0.0.0:6006/):
124128
# $ tensorboard --logdir='logs'
125129

‎tensorflowTUT/tf20_RNN2/for_you_to_practice.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ def RNN(X, weights, biases):
7171
with tf.Session() as sess:
7272
# tf.initialize_all_variables() no long valid from
7373
# 2017-03-02 if using tensorflow >= 0.12
74-
sess.run(tf.global_variables_initializer())
74+
if int((tf.__version__).split('.')[1]) < 12:
75+
init = tf.initialize_all_variables()
76+
else:
77+
init = tf.global_variables_initializer()
78+
sess.run(init)
7579
step = 0
7680
while step * batch_size < training_iters:
7781
batch_xs, batch_ys = mnist.train.next_batch(batch_size)

‎tensorflowTUT/tf20_RNN2/full_code.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ def RNN(X, weights, biases):
101101
with tf.Session() as sess:
102102
# tf.initialize_all_variables() no long valid from
103103
# 2017-03-02 if using tensorflow >= 0.12
104-
sess.run(tf.global_variables_initializer())
104+
if int((tf.__version__).split('.')[1]) < 12:
105+
init = tf.initialize_all_variables()
106+
else:
107+
init = tf.global_variables_initializer()
108+
sess.run(init)
105109
step = 0
106110
while step * batch_size < training_iters:
107111
batch_xs, batch_ys = mnist.train.next_batch(batch_size)

‎tensorflowTUT/tf21_autoencoder/for_practicing.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ def decoder(x):
7474
with tf.Session() as sess:
7575
# tf.initialize_all_variables() no long valid from
7676
# 2017-03-02 if using tensorflow >= 0.12
77-
sess.run(tf.global_variables_initializer())
77+
if int((tf.__version__).split('.')[1]) < 12:
78+
init = tf.initialize_all_variables()
79+
else:
80+
init = tf.global_variables_initializer()
81+
sess.run(init)
7882
total_batch = int(mnist.train.num_examples/batch_size)
7983
# Training cycle
8084
for epoch in range(training_epochs):

‎tensorflowTUT/tf21_autoencoder/full_code.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ def decoder(x):
152152
with tf.Session() as sess:
153153
# tf.initialize_all_variables() no long valid from
154154
# 2017-03-02 if using tensorflow >= 0.12
155-
sess.run(tf.global_variables_initializer())
155+
if int((tf.__version__).split('.')[1]) < 12:
156+
init = tf.initialize_all_variables()
157+
else:
158+
init = tf.global_variables_initializer()
159+
sess.run(init)
156160
total_batch = int(mnist.train.num_examples/batch_size)
157161
# Training cycle
158162
for epoch in range(training_epochs):

‎tensorflowTUT/tf22_scope/tf22_RNN_scope.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,8 @@ def _bias_variable(shape, name='biases'):
113113
test_rnn2 = RNN(test_config)
114114
# tf.initialize_all_variables() no long valid from
115115
# 2017-03-02 if using tensorflow >= 0.12
116-
sess.run(tf.global_variables_initializer())
116+
if int((tf.__version__).split('.')[1]) < 12:
117+
init = tf.initialize_all_variables()
118+
else:
119+
init = tf.global_variables_initializer()
120+
sess.run(init)

‎tensorflowTUT/tf22_scope/tf22_scope.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
with tf.Session() as sess:
3737
# tf.initialize_all_variables() no long valid from
3838
# 2017-03-02 if using tensorflow >= 0.12
39-
sess.run(tf.global_variables_initializer())
39+
if int((tf.__version__).split('.')[1]) < 12:
40+
init = tf.initialize_all_variables()
41+
else:
42+
init = tf.global_variables_initializer()
43+
sess.run(init)
4044
print(var3.name) # a_variable_scope/var3:0
4145
print(sess.run(var3)) # [ 3.]
4246
print(var4.name) # a_variable_scope/var4:0

‎tensorflowTUT/tf23_BN/tf23_BN.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ def mean_var_with_update():
154154
train_op_norm, cost_norm, layers_inputs_norm = built_net(xs, ys, norm=True) # with BN
155155

156156
sess = tf.Session()
157-
sess.run(tf.global_variables_initializer())
157+
if int((tf.__version__).split('.')[1]) < 12:
158+
init = tf.initialize_all_variables()
159+
else:
160+
init = tf.global_variables_initializer()
161+
sess.run(init)
158162

159163
# record cost
160164
cost_his = []

‎tensorflowTUT/tf5_example2/full_code.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030
sess = tf.Session()
3131
# tf.initialize_all_variables() no long valid from
3232
# 2017-03-02 if using tensorflow >= 0.12
33-
sess.run(tf.global_variables_initializer())
33+
if int((tf.__version__).split('.')[1]) < 12:
34+
init = tf.initialize_all_variables()
35+
else:
36+
init = tf.global_variables_initializer()
37+
sess.run(init)
3438

3539
for step in range(201):
3640
sess.run(train)

0 commit comments

Comments
 (0)
Please sign in to comment.