import tensorflow as tf
n = 10
# images is a 1 x 10 x 10 x 1 array that contains the numbers 1 through 100 in order
images = [[[[x * n + y + 1] for y in range(n)] for x in range(n)]]
# We generate four outputs as follows:
# 1. 3x3 patches with stride length 5
# 2. Same as above, but the rate is increased to 2
# 3. 4x4 patches with stride length 7; only one patch should be generated
# 4. Same as above, but with padding set to 'SAME'
import numpy as np
images = np.array(images)
print(images.shape)
print(images[0,:,:,0])
with tf.Session() as sess:
print(sess.run(tf.extract_image_patches(images=images, ksizes=[1, 3, 3, 1],
strides=[1, 1, 1, 1], rates=[1, 1, 1, 1], padding='VALID')), '\n\n')
# print(sess.run(tf.extract_image_patches(images=images, ksizes=[1, 3, 3, 1],
# strides=[1, 5, 5, 1], rates=[1, 2, 2, 1], padding='VALID')), '\n\n')
# print(sess.run(tf.extract_image_patches(images=images, ksizes=[1, 4, 4, 1],
# strides=[1, 7, 7, 1], rates=[1, 1, 1, 1], padding='SAME')), '\n\n')
# print(sess.run(tf.extract_image_patches(images=images, ksizes=[1, 4, 4, 1],
# strides=[1, 7, 7, 1], rates=[1, 1, 1, 1], padding='SAME')))
根据提示,是将左上角的*内容展平得到,可以对应上面的代码结果辅助理解
* * * 4 5 * * * 9 10
* * * 14 15 * * * 19 20
* * * 24 25 * * * 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
* * * 54 55 * * * 59 60
* * * 64 65 * * * 69 70
* * * 74 75 * * * 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100