Skip to content

Commit cf5d47c

Browse files
committed
fix the compatibility with Python3
It's come out a very fix. Just convert the `print` from statement to function calls and open the json dump file in text mode. Nothing else.
1 parent d0f4285 commit cf5d47c

File tree

6 files changed

+28
-28
lines changed

6 files changed

+28
-28
lines changed

cnn_1_char.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ def max_pool_2x2(x):
4949
def main(_):
5050
# load data
5151
meta, train_data, test_data = input_data.load_data(FLAGS.data_dir, flatten=False)
52-
print 'data loaded'
53-
print 'train images: %s. test images: %s' % (train_data.images.shape[0], test_data.images.shape[0])
52+
print('data loaded')
53+
print('train images: %s. test images: %s' % (train_data.images.shape[0], test_data.images.shape[0]))
5454

5555
LABEL_SIZE = meta['label_size']
5656
IMAGE_HEIGHT = meta['height']
5757
IMAGE_WIDTH = meta['width']
5858
IMAGE_SIZE = IMAGE_WIDTH * IMAGE_HEIGHT
59-
print 'label_size: %s, image_size: %s' % (LABEL_SIZE, IMAGE_SIZE)
59+
print('label_size: %s, image_size: %s' % (LABEL_SIZE, IMAGE_SIZE))
6060

6161
# variable in the graph for input data
6262
with tf.name_scope('input'):
@@ -147,15 +147,15 @@ def main(_):
147147
test_summary, test_accuracy = sess.run([merged, accuracy], feed_dict={x: test_x, y_: test_y, keep_prob: 1.0})
148148
test_writer.add_summary(test_summary, i)
149149

150-
print 'step %s, training accuracy = %.2f%%, testing accuracy = %.2f%%' % (i, train_accuracy * 100, test_accuracy * 100)
150+
print('step %s, training accuracy = %.2f%%, testing accuracy = %.2f%%' % (i, train_accuracy * 100, test_accuracy * 100))
151151

152152
train_writer.close()
153153
test_writer.close()
154154

155155
# final check after looping
156156
test_x, test_y = test_data.next_batch(2000)
157157
test_accuracy = accuracy.eval(feed_dict={x: test_x, y_: test_y, keep_prob: 1.0})
158-
print 'testing accuracy = %.2f%%' % (test_accuracy * 100, )
158+
print('testing accuracy = %.2f%%' % (test_accuracy * 100, ))
159159

160160

161161
if __name__ == '__main__':

cnn_n_char.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ def max_pool_2x2(x):
4949
def main(_):
5050
# load data
5151
meta, train_data, test_data = input_data.load_data(FLAGS.data_dir, flatten=False)
52-
print 'data loaded'
53-
print 'train images: %s. test images: %s' % (train_data.images.shape[0], test_data.images.shape[0])
52+
print('data loaded')
53+
print('train images: %s. test images: %s' % (train_data.images.shape[0], test_data.images.shape[0]))
5454

5555
LABEL_SIZE = meta['label_size']
5656
NUM_PER_IMAGE = meta['num_per_image']
5757
IMAGE_HEIGHT = meta['height']
5858
IMAGE_WIDTH = meta['width']
5959
IMAGE_SIZE = IMAGE_WIDTH * IMAGE_HEIGHT
60-
print 'label_size: %s, image_size: %s' % (LABEL_SIZE, IMAGE_SIZE)
60+
print('label_size: %s, image_size: %s' % (LABEL_SIZE, IMAGE_SIZE))
6161

6262
# variable in the graph for input data
6363
with tf.name_scope('input'):
@@ -151,15 +151,15 @@ def main(_):
151151
test_summary, test_accuracy = sess.run([merged, accuracy], feed_dict={x: test_x, y_: test_y, keep_prob: 1.0})
152152
test_writer.add_summary(test_summary, i)
153153

154-
print 'step %s, training accuracy = %.2f%%, testing accuracy = %.2f%%' % (i, train_accuracy * 100, test_accuracy * 100)
154+
print('step %s, training accuracy = %.2f%%, testing accuracy = %.2f%%' % (i, train_accuracy * 100, test_accuracy * 100))
155155

156156
train_writer.close()
157157
test_writer.close()
158158

159159
# final check after looping
160160
test_x, test_y = test_data.next_batch(2000)
161161
test_accuracy = accuracy.eval(feed_dict={x: test_x, y_: test_y, keep_prob: 1.0})
162-
print 'testing accuracy = %.2f%%' % (test_accuracy * 100, )
162+
print('testing accuracy = %.2f%%' % (test_accuracy * 100, ))
163163

164164

165165
if __name__ == '__main__':

datasets/base.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ def next_batch(self, batch_size):
112112

113113

114114
def display_debug_info(meta, train_data, test_data):
115-
print '%s Meta Info %s' % ('=' * 10, '=' * 10)
115+
print('%s Meta Info %s' % ('=' * 10, '=' * 10))
116116
for k, v in meta.items():
117-
print '%s: %s' % (k, v)
118-
print '=' * 30
117+
print('%s: %s' % (k, v))
118+
print('=' * 30)
119119

120-
print 'train images: %s, labels: %s' % (train_data.images.shape, train_data.labels.shape)
120+
print('train images: %s, labels: %s' % (train_data.images.shape, train_data.labels.shape))
121121

122-
print 'test images: %s, labels: %s' % (test_data.images.shape, test_data.labels.shape)
122+
print('test images: %s, labels: %s' % (test_data.images.shape, test_data.labels.shape))
123123

124124

125125
if __name__ == '__main__':

datasets/gen_captcha.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _gen_captcha(img_dir, num_per_image, n, width, height, choices):
3030

3131
image = ImageCaptcha(width=width, height=height)
3232

33-
print 'generating %s epoches of captchas in %s' % (n, img_dir)
33+
print('generating %s epoches of captchas in %s' % (n, img_dir))
3434
for _ in range(n):
3535
for i in itertools.permutations(choices, num_per_image):
3636
captcha = ''.join(i)
@@ -62,15 +62,15 @@ def gen_dataset():
6262
'height': height,
6363
}
6464

65-
print '%s choices: %s' % (len(choices), ''.join(choices) or None)
65+
print('%s choices: %s' % (len(choices), ''.join(choices) or None))
6666

6767
_gen_captcha(build_file_path('train'), num_per_image, n_epoch, width, height, choices=choices)
6868
_gen_captcha(build_file_path('test'), num_per_image, max(1, int(n_epoch * test_ratio)), width, height, choices=choices)
6969

7070
meta_filename = build_file_path(META_FILENAME)
71-
with open(meta_filename, 'wb') as f:
71+
with open(meta_filename, 'w') as f:
7272
json.dump(meta, f, indent=4)
73-
print 'write meta info in %s' % meta_filename
73+
print('write meta info in %s' % meta_filename)
7474

7575

7676
if __name__ == '__main__':

simple_softmax.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
def main(_):
1616
# load data
1717
meta, train_data, test_data = input_data.load_data(FLAGS.data_dir, flatten=True)
18-
print 'data loaded'
19-
print 'train images: %s. test images: %s' % (train_data.images.shape[0], test_data.images.shape[0])
18+
print('data loaded')
19+
print('train images: %s. test images: %s' % (train_data.images.shape[0], test_data.images.shape[0]))
2020

2121
LABEL_SIZE = meta['label_size']
2222
IMAGE_SIZE = meta['width'] * meta['height']
23-
print 'label_size: %s, image_size: %s' % (LABEL_SIZE, IMAGE_SIZE)
23+
print('label_size: %s, image_size: %s' % (LABEL_SIZE, IMAGE_SIZE))
2424

2525
# variable in the graph for input data
2626
x = tf.placeholder(tf.float32, [None, IMAGE_SIZE])
@@ -55,11 +55,11 @@ def main(_):
5555
if i % 100 == 0:
5656
# Test trained model
5757
r = sess.run(accuracy, feed_dict={x: test_data.images, y_: test_data.labels})
58-
print 'step = %s, accuracy = %.2f%%' % (i, r * 100)
58+
print('step = %s, accuracy = %.2f%%' % (i, r * 100))
5959

6060
# final check after looping
6161
r_test = sess.run(accuracy, feed_dict={x: test_data.images, y_: test_data.labels})
62-
print 'testing accuracy = %.2f%%' % (r_test * 100, )
62+
print('testing accuracy = %.2f%%' % (r_test * 100, ))
6363

6464

6565
if __name__ == '__main__':

softmax_with_log.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ def variable_summaries(var):
3131
def main(_):
3232
# load data
3333
meta, train_data, test_data = input_data.load_data(FLAGS.data_dir, flatten=True)
34-
print 'data loaded. train images: %s. test images: %s' % (train_data.images.shape[0], test_data.images.shape[0])
34+
print('data loaded. train images: %s. test images: %s' % (train_data.images.shape[0], test_data.images.shape[0]))
3535

3636
LABEL_SIZE = meta['label_size']
3737
IMAGE_WIDTH = meta['width']
3838
IMAGE_HEIGHT = meta['height']
3939
IMAGE_SIZE = IMAGE_WIDTH * IMAGE_HEIGHT
40-
print 'label_size: %s, image_size: %s' % (LABEL_SIZE, IMAGE_SIZE)
40+
print('label_size: %s, image_size: %s' % (LABEL_SIZE, IMAGE_SIZE))
4141

4242
# variable in the graph for input data
4343
with tf.name_scope('input'):
@@ -100,14 +100,14 @@ def main(_):
100100
# Test trained model
101101
test_summary, r = sess.run([merged, accuracy], feed_dict={x: test_data.images, y_: test_data.labels})
102102
train_writer.add_summary(test_summary, i)
103-
print 'step = %s, accuracy = %.2f%%' % (i, r * 100)
103+
print('step = %s, accuracy = %.2f%%' % (i, r * 100))
104104

105105
train_writer.close()
106106

107107
# final check after looping
108108
test_summary, r_test = sess.run([merged, accuracy], feed_dict={x: test_data.images, y_: test_data.labels})
109109
train_writer.add_summary(test_summary, i)
110-
print 'testing accuracy = %.2f%%' % (r_test * 100, )
110+
print('testing accuracy = %.2f%%' % (r_test * 100, ))
111111

112112

113113
if __name__ == '__main__':

0 commit comments

Comments
 (0)