Python 调整大小未知的tensorflow图像的大小
我有一个tensorflow UNet风格的网络。目前,我指定输入图像和目标图像如下:Python 调整大小未知的tensorflow图像的大小,python,tensorflow,deep-learning,Python,Tensorflow,Deep Learning,我有一个tensorflow 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.inp
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_双线性(尽管这个问题对任何tf.image.resize_图像都有效)。目前,我的调整双线性代码如下所示:
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)