如何在保留批次尺寸的同时在空间尺寸上切片输入张量?

时间:2019-02-19 23:47:54

标签: python tensorflow slice

输入张量是图像数组:

self.image, self.label = self.iterator.get_next()
print("\nDEBUG: self.image:", self.image)

>>> DEBUG: self.image: Tensor("IteratorGetNext_1:0", shape=(?, 1200, 1200, 1), dtype=float32)

我想通过跳过每一侧的boundary数量并裁剪self.image_width//input_pool x self.image_width//input_pool中央部分来获得每个图像的中央剪辑。不幸的是,这段代码产生了关于将Dimension转换为整数的错误:

self.slice_large = tf.slice(self.image, (0, boundary, boundary, 0),
        (self.image.shape[0], self.image_width//input_pool,
            self.image_width//input_pool, self.image.shape[3]))

所以我添加了显式强制转换,但还是没有运气:

self.slice_large = tf.slice(self.image, (0, boundary, boundary, 0),
        (tf.cast(self.image.shape[0], tf.int32), self.image_width//input_pool,
            self.image_width//input_pool, tf.cast(self.image.shape[3], tf.int32)))

>>> ValueError: Cannot convert an unknown Dimension to a Tensor: ?

您能建议如何裁剪输入图像的中心部分吗?

0 个答案:

没有答案