【问题标题】:In tensorflow encoder-decoder model like FCN, segnet, how to give arbitrary input size?在 FCN、segnet 等 TensorFlow 编码器-解码器模型中,如何给出任意输入大小?
【发布时间】:2018-03-29 07:02:23
【问题描述】:

对于 tensorflow 中的图像语义分割模型,我需要为 FCN 或 segnet 模型提供可变大小的输入。所以我使用了占位符:

self.input= tf.placeholder(tf.float32, shape=(batch_size,None,None,3),name='')

在一个encoder-decoder模型中,我需要在maxpooling之后unpool,代码如下:

#upsample fuction used in decoder
def _upsample_along_axis(volume, axis, stride, mode='COPY'):
    shape = volume.get_shape().as_list()
    assert 0 <= axis < len(shape)
    target_shape = shape[:]
    target_shape[axis] *= stride
    padding = tf.zeros(shape, dtype=volume.dtype) if mode == 'ZEROS' else volume
    parts = [volume] + [padding for _ in range(stride - 1)]
    volume = tf.concat(parts, min(axis+1, len(shape)-1))
    target_shape = np.array(target_shape)
    target_shape[0] = -1
    volume = tf.reshape(volume, target_shape)

    return volume

现在 target_shape[axis] 不存在,所以target_shape[axis] *= stride 将引发错误: 类型错误:* 不支持的操作数类型:'NoneType' 和 'int'

那么encoder-decoder模型的输入可以是可变的吗?

【问题讨论】:

    标签: python tensorflow image-segmentation


    【解决方案1】:

    Tensor 的get_shape 函数返回推断的形状,对于动态尺寸推断的形状是None。 TensorFlow 中有一个函数可以返回动态形状:tf.shape

    此函数返回将计算为形状实际值的张量。

    还有两个函数可能对您的案例有用:tf.padtf.tile

    【讨论】:

    • 谢谢。 Tf.shape() 正是我所需要的!!
    猜你喜欢
    • 1970-01-01
    • 2019-05-20
    • 2022-01-04
    • 2021-04-03
    • 2019-07-07
    • 2021-08-05
    • 2022-01-11
    • 2022-07-05
    • 2021-03-25
    相关资源
    最近更新 更多