因为我的输入图像太大而无法在神经网络中进行计算,所以使用extract_image_patches
将它们拆分为小块。然后在将补丁输入网络之前将补丁一起批处理。目前,每批中有256个补丁,但每个映像总共分为1024个补丁,这意味着需要读取4个批次来重建图像。
对于重建,我使用以下代码:
image = tf.image.decode_png(...)
...
patch_size = [1, 32, 32, 1]
patches = tf.extract_image_patches([image],
patch_size, patch_size, [1, 1, 1, 1], 'VALID')
patches = tf.reshape(patches, [1024, 32, 32, 3])
...
reconstructed = tf.reshape(patches, [1, 1024, 1024, 3])
encoded = tf.image.encode_png(reconstructed[0])
这适用于涉及批处理(除非批次数为1024):
patch_batch = tf.train.batch([patches],
batch_size=256,
enqueue_many=True,
capacity=capacity)
reconstructed = tf.reshape(patch_batch, [1, 1024, 1024, 3]) <-- fails
起初,我尝试使用FIFOQueue,但是这将无限期挂起,因为缓冲区在请求出列队列之前无法累积足够的数据:
buf = tf.FIFOQueue(1024, dtypes=[tf.uint8], shapes=[[32, 32, 3]])
buf.enqueue_many(patch_batch)
all_patches = buf.dequeue_many(1024)
reconstructed = tf.reshape(all_patches, [1, 1024, 1024, 3])
“解密”这些数据的正确方法是什么?