且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 Keras 中合并多个模型(tensorflow)

更新时间:2022-04-15 07:39:35

据我所知,您想对 4 个类进行分类,为此,您有 2 个模型,每个模型对 2 个类进行分类.
到目前为止,您的 f1 和 f2 模型输出 softmax 激活 的结果,因此首先,您必须将其删除并仅输出 logits 或仅输出 relu activation.之后,正如@dmg2 所提到的,您必须在 tf.concat 中设置 axis=1 现在最后您必须通过一个新的 softmax 激活.在那之后,我希望你能训练你的模型.

From what I understand you want to classify 4 classes and for that, you have 2 models which classify 2 classes each.
As of now, your f1 and f2 model outputs the result of softmax activation so first, you have to remove it and output just the logits or just relu activation. After that as mentioned by the @dmg2, you have to set the axis=1 in the tf.concat now at the end you have to pass the output through a new softmax activation. After that, I hope you could train your model.