After doing a lot of effort here is my question,
I have two models, both models can detect 2-2 classes. As we know that we can merge two models using a FunctionalAPI. I tried it, But I am not getting the desired outcome.
My goal: I want to Merge these models, and the updated model should have (1 input, 4 output).
inputs = tf.keras.Input(shape=(50,50,1))
y_1 = f1_Model(inputs)
y_2 = f2(inputs)
outputs = tf.concat([y_1, y_2], axis=0)
new_model = keras.Model(inputs, outputs)
new_model.summary()
Model: "functional_5"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_2 (InputLayer) [(None, 50, 50, 1)] 0
__________________________________________________________________________________________________
sequential (Sequential) (None, 2) 203874 input_2[0][0]
__________________________________________________________________________________________________
sequential_1 (Sequential) (None, 2) 203874 input_2[0][0]
__________________________________________________________________________________________________
tf_op_layer_concat (TensorFlowO [(None, 2)] 0 sequential[1][0]
sequential_1[1][0]
==================================================================================================
Total params: 407,748
Trainable params: 407,748
Non-trainable params: 0
__________________________________________________________________________________________________
When I pass an image in it, it gives the wrong result. I don't know where did I go wrong.
prediction = new_model.predict([prepare(img)])
prediction
# index_pred=np.argmax(prediction) (this should return from 0 to 3, but not happening)
array([[1., 0.],
[1., 0.]], dtype=float32)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…