创建一个为我的张量添加零通道的图层

问题描述 投票:1回答:1

我正在研究DCSCN(图像超级rez的神经网络),我想根据Alex Kendall和Yarin Gal方法在“贝叶斯深度学习计算机视觉需要什么不确定性?”中评估不确定性。使用Keras。

为此,我需要一个采用张量形状(?,n,m,3)的层,并用(?,n,m,-1)返回带有零的(?,n,m,4)张量。

我试过这个功能:

def AddChan(**kwargs):

    def layer(x):
        input_shape = K.int_shape(x)
        output_shape = (input_shape[0], input_shape[1],input_shape[2],1)
        z = K.zeros(output_shape)
        res = K.concatenate([x, z], axis=-1)
        return res
    return Lambda(layer, **kwargs)

提出:

Expected int32, got None of type '_Message' instead.

我认为这是因为input_shape[0]是动态的,但我没有看到另一种方式来获得我想要的东西。

有没有人有想法?

谢谢 !

python image keras layer
1个回答
0
投票

尝试用K.int_shape替换K.shape以获得张量或变量的符号形状而不是整数形状。

© www.soinside.com 2019 - 2024. All rights reserved.