你能在 TensorFlow 中组合两个神经网络吗?

Can you combine two NNs in TensorFlow?

我有一组图像,例如猫和狗。我还有一个 CSV 伴随着这个。 CSV 包含图像的元数据,例如动物的重量。

我已经为猫 VS 狗图像做了一个分类器。我如何使用带有元数据的 CSV 来改进这个分类器?我是否需要为元数据制作一个单独的分类器并将这两个分类器组合起来?

对不起,如果这是一个愚蠢的问题,但我在网上找不到任何东西,我什至不知道我要找的东西的术语。

感谢您花时间阅读本文

是的,您可以,在 Keras 中,您可以使用 API 函数,如 this post.

中的详细说明

您的代码应如下所示:

# define two sets of inputs
inputA = Input(shape=(32,))
inputB = Input(shape=(128,))

# the first branch operates on the first input
x = Dense(8, activation="relu")(inputA)
x = Dense(4, activation="relu")(x)
x = Model(inputs=inputA, outputs=x)

# the second branch opreates on the second input
y = Dense(64, activation="relu")(inputB)
y = Dense(32, activation="relu")(y)
y = Dense(4, activation="relu")(y)
y = Model(inputs=inputB, outputs=y)

# combine the output of the two branches
combined = concatenate([x.output, y.output])

# apply a FC layer and then a regression prediction on the
# combined outputs
z = Dense(2, activation="relu")(combined)
z = Dense(1, activation="linear")(z)

# our model will accept the inputs of the two branches and
# then output a single value
model = Model(inputs=[x.input, y.input], outputs=z)