I've built a multi-class, multi-label image classification network using Keras. There are 25 classes overall and each image has at least one class in it. I want to implement a custom accuracy metric which tells me how often the highest probability class is in the image (regular accuracy is less meaningful as the true positives are swamped by the true negatives).
I've built a simple function which generates the desired accuracy metric when I manually feed in y_true and y_pred. However when I try and insert this function into the model training process, it produces an error.
def customAcc(y_true, y_pred):
classPreds = np.array([np.eye(numClasses)[x] for x in np.argmax(y_pred, axis=1)])
correctPreds = y_true * classPreds
return np.mean(np.sum(correctPreds, axis=1))
model.compile(optimizer=tf.keras.optimizers.Adam(lr=0.0001),
loss='binary_crossentropy', metrics=['accuracy', customAcc])
AxisError: axis 1 is out of bounds for array of dimension 1