IIUC,您應該能夠簡單地使用tf.reshape從批量補丁重建原始圖像: import tensorflow as tfsamples = 5images = tf.random.normal((samples, 256, 256, 3))@tf.functiondef grid(images): img_shape = tf.shape(images) batch_size, height, width, n_filters = img_shape[0], img_shape[1], img_shape[2], img_shape[3] patches = tf.image.extract_patches(images=images, sizes=[1, 32, 32, 1], strides=[1, 32, 32, 1], rates=[1, 1, 1, 1], padding='VALID') return tf.reshape(tf.nn.softmax(patches), (batch_size, height, width, n_filters)) patches = grid(images)print(patches.shape)# (5, 256, 256, 3) 更新1:如果你想以正確的順序重建圖像,你可以計算tf.image.extract_patches的梯