微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决你能在 TensorFlow 中结合两个神经网络吗?

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

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

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

感谢您花时间阅读本文

解决方法

是的,您可以,在 Keras 中,您可以使用 this 博文中详细说明的函数式 API。

您的代码应如下所示:

# 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)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。