Skip to content

Commit 7839ba2

Browse files
Refactor logistic_regression for TF1.0
Signed-off-by: Norman Heckscher <norman.heckscher@gmail.com>
1 parent b557533 commit 7839ba2

File tree

2 files changed

+39
-40
lines changed

2 files changed

+39
-40
lines changed

examples/2_BasicModels/logistic_regression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)
3939

4040
# Initializing the variables
41-
init = tf.initialize_all_variables()
41+
init = tf.global_variables_initializer()
4242

4343
# Launch the graph
4444
with tf.Session() as sess:

notebooks/2_BasicModels/logistic_regression.ipynb

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
{
2020
"cell_type": "code",
21-
"execution_count": 2,
21+
"execution_count": 1,
2222
"metadata": {
2323
"collapsed": false
2424
},
@@ -27,10 +27,10 @@
2727
"name": "stdout",
2828
"output_type": "stream",
2929
"text": [
30-
"Extracting /tmp/data/train-images-idx3-ubyte.gz\n",
31-
"Extracting /tmp/data/train-labels-idx1-ubyte.gz\n",
32-
"Extracting /tmp/data/t10k-images-idx3-ubyte.gz\n",
33-
"Extracting /tmp/data/t10k-labels-idx1-ubyte.gz\n"
30+
"Extracting MNIST_data/train-images-idx3-ubyte.gz\n",
31+
"Extracting MNIST_data/train-labels-idx1-ubyte.gz\n",
32+
"Extracting MNIST_data/t10k-images-idx3-ubyte.gz\n",
33+
"Extracting MNIST_data/t10k-labels-idx1-ubyte.gz\n"
3434
]
3535
}
3636
],
@@ -39,14 +39,14 @@
3939
"\n",
4040
"# Import MINST data\n",
4141
"from tensorflow.examples.tutorials.mnist import input_data\n",
42-
"mnist = input_data.read_data_sets(\"/tmp/data/\", one_hot=True)"
42+
"mnist = input_data.read_data_sets(\"MNIST_data/\", one_hot=True)"
4343
]
4444
},
4545
{
4646
"cell_type": "code",
4747
"execution_count": 3,
4848
"metadata": {
49-
"collapsed": true
49+
"collapsed": false
5050
},
5151
"outputs": [],
5252
"source": [
@@ -73,12 +73,12 @@
7373
"optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)\n",
7474
"\n",
7575
"# Initializing the variables\n",
76-
"init = tf.initialize_all_variables()"
76+
"init = tf.global_variables_initializer()"
7777
]
7878
},
7979
{
8080
"cell_type": "code",
81-
"execution_count": 4,
81+
"execution_count": null,
8282
"metadata": {
8383
"collapsed": false
8484
},
@@ -87,33 +87,23 @@
8787
"name": "stdout",
8888
"output_type": "stream",
8989
"text": [
90-
"Epoch: 0001 cost= 1.182138961\n",
91-
"Epoch: 0002 cost= 0.664670898\n",
92-
"Epoch: 0003 cost= 0.552613988\n",
93-
"Epoch: 0004 cost= 0.498497931\n",
94-
"Epoch: 0005 cost= 0.465418769\n",
95-
"Epoch: 0006 cost= 0.442546219\n",
96-
"Epoch: 0007 cost= 0.425473814\n",
97-
"Epoch: 0008 cost= 0.412171735\n",
98-
"Epoch: 0009 cost= 0.401359516\n",
99-
"Epoch: 0010 cost= 0.392401536\n",
100-
"Epoch: 0011 cost= 0.384750201\n",
101-
"Epoch: 0012 cost= 0.378185581\n",
102-
"Epoch: 0013 cost= 0.372401533\n",
103-
"Epoch: 0014 cost= 0.367302442\n",
104-
"Epoch: 0015 cost= 0.362702316\n",
105-
"Epoch: 0016 cost= 0.358568827\n",
106-
"Epoch: 0017 cost= 0.354882155\n",
107-
"Epoch: 0018 cost= 0.351430912\n",
108-
"Epoch: 0019 cost= 0.348316068\n",
109-
"Epoch: 0020 cost= 0.345392556\n",
110-
"Epoch: 0021 cost= 0.342737278\n",
111-
"Epoch: 0022 cost= 0.340264994\n",
112-
"Epoch: 0023 cost= 0.337890242\n",
113-
"Epoch: 0024 cost= 0.335708558\n",
114-
"Epoch: 0025 cost= 0.333686476\n",
115-
"Optimization Finished!\n",
116-
"Accuracy: 0.889667\n"
90+
"Epoch: 0001 cost= 1.182138959\n",
91+
"Epoch: 0002 cost= 0.664778162\n",
92+
"Epoch: 0003 cost= 0.552686284\n",
93+
"Epoch: 0004 cost= 0.498628905\n",
94+
"Epoch: 0005 cost= 0.465469866\n",
95+
"Epoch: 0006 cost= 0.442537872\n",
96+
"Epoch: 0007 cost= 0.425462044\n",
97+
"Epoch: 0008 cost= 0.412185303\n",
98+
"Epoch: 0009 cost= 0.401311587\n",
99+
"Epoch: 0010 cost= 0.392326203\n",
100+
"Epoch: 0011 cost= 0.384736038\n",
101+
"Epoch: 0012 cost= 0.378137191\n",
102+
"Epoch: 0013 cost= 0.372363752\n",
103+
"Epoch: 0014 cost= 0.367308579\n",
104+
"Epoch: 0015 cost= 0.362704660\n",
105+
"Epoch: 0016 cost= 0.358588599\n",
106+
"Epoch: 0017 cost= 0.354823110\n"
117107
]
118108
}
119109
],
@@ -146,6 +136,15 @@
146136
" accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))\n",
147137
" print \"Accuracy:\", accuracy.eval({x: mnist.test.images[:3000], y: mnist.test.labels[:3000]})"
148138
]
139+
},
140+
{
141+
"cell_type": "code",
142+
"execution_count": null,
143+
"metadata": {
144+
"collapsed": true
145+
},
146+
"outputs": [],
147+
"source": []
149148
}
150149
],
151150
"metadata": {
@@ -157,16 +156,16 @@
157156
"language_info": {
158157
"codemirror_mode": {
159158
"name": "ipython",
160-
"version": 2.0
159+
"version": 2
161160
},
162161
"file_extension": ".py",
163162
"mimetype": "text/x-python",
164163
"name": "python",
165164
"nbconvert_exporter": "python",
166165
"pygments_lexer": "ipython2",
167-
"version": "2.7.11"
166+
"version": "2.7.13"
168167
}
169168
},
170169
"nbformat": 4,
171170
"nbformat_minor": 0
172-
}
171+
}

0 commit comments

Comments
 (0)