创建一个层,为我的张量添加一个零通道
Create a layer that add a zero-channel to my tensor
我正在研究 DCSCN(用于图像 super-rez 的神经网络),我想根据 "What Uncertainties Do We Need in Bayesian Deep Learning for Computer Vision?" 使用 Keras 中的 Alex Kendall 和 Yarin Gal 方法评估不确定性。
为此,我需要一个张量为 (?,n,m,3) 的层,return 为 (?,n,m,4) 的张量和 (?,n ,m,-1) 带零。
我试过这个功能:
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]
是动态的,但我没有看到另一种方法来获得我想要的东西。
有人知道吗?
谢谢!
尝试将 K.int_shape
替换为 K.shape
以获得张量或变量的符号形状而不是整数形状。
我正在研究 DCSCN(用于图像 super-rez 的神经网络),我想根据 "What Uncertainties Do We Need in Bayesian Deep Learning for Computer Vision?" 使用 Keras 中的 Alex Kendall 和 Yarin Gal 方法评估不确定性。
为此,我需要一个张量为 (?,n,m,3) 的层,return 为 (?,n,m,4) 的张量和 (?,n ,m,-1) 带零。
我试过这个功能:
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]
是动态的,但我没有看到另一种方法来获得我想要的东西。
有人知道吗?
谢谢!
尝试将 K.int_shape
替换为 K.shape
以获得张量或变量的符号形状而不是整数形状。