gpt4 book ai didi

python - 调整大小未知的 tensorflow 图像

转载 作者:太空宇宙 更新时间:2023-11-04 02:17:09 25 4
gpt4 key购买 nike

我有一个 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.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)

关于python - 调整大小未知的 tensorflow 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52410154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com