调整未知大小的张量流图像的大小



>我有一个张量流UNet风格的网络。 目前,我指定输入和目标图像如下:

self.inputTensors = tf.placeholder(tf.float32, [None, opt.inputHeight, opt.inputWidth, opt.inputChannels], name='inputTensors')
self.targetColors = tf.placeholder(tf.float32, [None, opt.inputHeight, opt.inputWidth, opt.outputChannels], name='targetColors')

但我希望它也能够在可变宽度和高度图像上运行,即

self.inputTensors = tf.placeholder(tf.float32, [None, None, None, opt.inputChannels], name='inputTensors')
self.targetColors = tf.placeholder(tf.float32, [None, None, None, opt.outputChannels], name='targetColors')

并推断中间层的宽度和高度。 这适用于我的池化层或跨步卷积层,但对于我正在使用的上采样层tf.image.resize_bilinear(尽管该问题对tf.image.resize_images中的任何一个都有效。 目前我的调整大小双线性代码如下所示:

def unpool2xBilinear(inputs, name = 'unpool2xBilinear'):
sh = inputs.get_shape().as_list()
newShape = (sh[1] * 2, sh[2] * 2)
return tf.image.resize_bilinear(inputs, newShape)

但是,这无法处理未知的输入形状,从而给出

TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'

有没有办法允许调整图像大小以接受与输入相关的大小?还是我必须为每个不同的输入图像大小构建一个全新的图形?

改用tf.shape

def unpool2xBilinear(inputs, name = 'unpool2xBilinear'):
sh = tf.shape(inputs)
newShape = 2 * sh[1:3]
return tf.image.resize_bilinear(inputs, newShape)

最新更新