在 Keras 中深度连接

Depth-wise concatenate in Keras

我正在尝试将单热向量深度连接(StarGAN 使用 Pytorch 的实现示例)到图像输入中,比如

input_img = Input(shape = (row, col, chann))
one_hot = Input(shape = (7, ))

我之前偶然发现了同样的问题(),所以我使用了 RepeatVector+Reshape 然后是 Concatenate。但我发现 RepeatVector 不兼容,当你想将 3D 重复为 4D 时(包括 batch_num)。

如何在 Keras 中实现此方法?我发现 Upsampling2D 可以完成工作,但我不知道它是否能够在上采样过程中保持单热向量结构

我从 中找到了一个想法,您可以使用 tile,但您需要重塑 one_hot 使其具有与 input_img 相同的维数

one_hot = Reshape((1, 1, 6))(one_hot)
one_hot = Lambda(K.tile, arguments = {'n' : (-1, row, col, 1)})(one_hot)
model_input = Concatenate()([input_img, one_hot])