I need to build custom categorical cross entropy loss function where I should compare
Q*y_pred instead of just
Q is a matrix.
The problem is that the batch size must not be equal to
1. So, there is a problem with dimensions.
How to built categorical cross entropy loss function which works with
For example, this is the custom categorical cross entropy loss function which works correctly but for
batch_size = 1.
I have 3 classes, so, the shape of
(batch_size, 3, 1) and the shape of
Q is (3,3).
I also tried to transfer a multidimensional numpy array with
shape = (batch_size, 3, 3) but it did not work.
Q=np.matrix([[0, 0.7,0.2], [0,0,0.8],[1,0.3,0]]) def alpha_loss(y_true, y_pred): return K.categorical_crossentropy(y_true,K.dot(tf.convert_to_tensor(Q,dtype=tf.float32 ),K.reshape(y_pred,(3,1)) ))