'Evaluate model result for multitask learning with keras
I designed a CNN for a multitask classification in keras, where I have one input and two different class of classes in output.
I compiled the model in this way:
model.compile(loss='categorical_crossentropy',
optimizer=tf.keras.optimizers.Adam(lr=0.00002, decay=1e-6),
metrics=['accuracy'])
I wanted to know what is the meaning of the results obtained with this instruction:
preds = model.evaluate(x=X_test, y=[Y1_test, Y2_test])
I get 5 elements and i suppose the first and second are the losses for first and second class, the third seems like the difference between the two losses and the last two are the accuracies maybe. Is it correct? I did not find the explanation of the output for a multitask classification
Solution 1:[1]
In this dummy example, I provide you a multi-output model and try to make evaluation
X = np.random.uniform(0,1, (1000,10))
y1 = np.random.randint(0,2, 1000)
y2 = np.random.randint(0,2, 1000)
inp = Input((10))
x = Dense(32, activation='relu')(inp)
out1 = Dense(2, activation='softmax')(x)
out2 = Dense(2, activation='softmax')(x)
m = Model(inp, [out1,out2])
m.compile(loss='sparse_categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
m.fit(X, [y1,y2], epochs=10, verbose=2)
m.evaluate(X, [y1,y2])
the evaluate method return 5 numbers:
- total loss (given by the sum of two output loss)
- output1 loss
- output2 loss
- output1 accuracy
- output2 accuracy
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Marco Cerliani |