Skip to content

Commit 33cedce

Browse files
authored
Merge pull request #3 from mlopezantequera/python3_compat
Python 3 compatibility
2 parents 391bd4d + f790b6c commit 33cedce

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

train_flowers.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from builtins import range
12
import tensorflow as tf
23
from tensorflow.contrib.framework.python.ops.variables import get_or_create_global_step
34
from tensorflow.python.platform import tf_logging as logging
@@ -178,7 +179,7 @@ def run():
178179
images, _, labels = load_batch(dataset, batch_size=batch_size)
179180

180181
#Know the number steps to take before decaying the learning rate and batches per epoch
181-
num_batches_per_epoch = dataset.num_samples / batch_size
182+
num_batches_per_epoch = dataset.num_samples // batch_size
182183
num_steps_per_epoch = num_batches_per_epoch #Because one step is one batch processed
183184
decay_steps = int(num_epochs_before_decay * num_steps_per_epoch)
184185

@@ -245,8 +246,7 @@ def train_step(sess, train_op, global_step):
245246

246247
#Run the managed session
247248
with sv.managed_session() as sess:
248-
for step in xrange(num_steps_per_epoch * num_epochs):
249-
# for step in xrange(1):
249+
for step in range(num_steps_per_epoch * num_epochs):
250250
#At the start of every epoch, show the vital information:
251251
if step % num_batches_per_epoch == 0:
252252
logging.info('Epoch %s/%s', step/num_batches_per_epoch + 1, num_epochs)
@@ -256,10 +256,10 @@ def train_step(sess, train_op, global_step):
256256

257257
# optionally, print your logits and predictions for a sanity check that things are going fine.
258258
logits_value, probabilities_value, predictions_value, labels_value = sess.run([logits, probabilities, predictions, labels])
259-
print 'logits: \n', logits_value[:5]
260-
print 'Probabilities: \n', probabilities_value[:5]
261-
print 'predictions: \n', predictions_value[:5]
262-
print 'Labels:\n:', labels_value[:5]
259+
print('logits: \n', logits_value[:5])
260+
print('Probabilities: \n', probabilities_value[:5])
261+
print('predictions: \n', predictions_value[:5])
262+
print('Labels:\n:', labels_value[:5])
263263

264264
#Log the summaries every 10 step.
265265
if step % 10 == 0:

xception.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import
22
from __future__ import division
33
from __future__ import print_function
4+
from builtins import range
45

56
import tensorflow as tf
67
slim = tf.contrib.slim
@@ -96,7 +97,7 @@ def xception(inputs,
9697
net = tf.add(net, residual, name='block4_add')
9798

9899
#===========MIDDLE FLOW===============
99-
for i in xrange(8):
100+
for i in range(8):
100101
block_prefix = 'block%s_' % (str(i + 5))
101102

102103
residual = net

0 commit comments

Comments
 (0)