I work with Keras and I am trying to rewrite categorical_rossentropy using the Keras backend, but I am stuck.
This is my custom function, I only need a weighted amount of cross-entropy:
def custom_entropy( y_true, y_pred):
y_pred /= K.sum(y_pred, axis=-1, keepdims=True)
y_pred = K.clip(y_pred, K.epsilon(), 1 - K.epsilon())
loss = y_true * K.log(y_pred)
loss = -K.sum(loss, -1)
return loss
In my program, I create a label_predwith model.predict().
Finally, I:
label_pred = model.predict(mfsc_train[:,:,5])
cc = custom_entropy(label, label_pred)
ce = K.categorical_crossentropy(label, label_pred)
I get the following error:
Traceback (most recent call last):
File "SAMME_train_all.py", line 47, in <module>
ce = K.categorical_crossentropy(label, label_pred)
File "C:\Users\gionata\AppData\Local\Programs\Python\Python36\lib
s\keras\backend\tensorflow_backend.py", line 2754, in categorical_c
axis=len(output.get_shape()) - 1,
AttributeError: 'numpy.ndarray' object has no attribute 'get_shape'
source
share