TensorFlow FastGFile 和 max_pool 代码样例。
效果图:
#!/usr/bin/env python # -*- coding: utf-8 -*- import tensorflow as tf import matplotlib.pyplot as plt image_raw_data=tf.gfile.FastGFile("ad.jpg","r").read() with tf.Session() as sess: image_data=tf.image.decode_png(image_raw_data) image=(image_data.eval()) print (image) print image.shape plt.subplot(231) plt.imshow(image[:,:,0]) plt.subplot(232) plt.imshow(image[:, :, 1]) plt.subplot(233) plt.imshow(image[:, :, 2]) result = sess.run(tf.reshape(image, [1,450, 540, 3])) pooling = tf.nn.max_pool(result, [1, 4, 4, 1], [1, 2, 2, 1], padding='VALID') result = sess.run(pooling) print(result.shape) result = sess.run(tf.reshape(result, [224, 269, 3])) plt.subplot(234) plt.imshow(result[:, :, 0]) plt.subplot(235) plt.imshow(result[:, :, 1]) plt.subplot(236) plt.imshow(result[:, :, 2]) plt.show()