bug-fix cifar10_cnn_capsule.py missing K.sum()
Just add K.sum() around the margin_loss
@@ -44,8 +44,8 @@ def softmax(x, axis=-1):
# define the margin loss like hinge loss
def margin_loss(y_true, y_pred):
lamb, margin = 0.5, 0.1
- return y_true * K.square(K.relu(1 - margin - y_pred)) + lamb * (
- 1 - y_true) * K.square(K.relu(y_pred - margin))
+ return K.sum(y_true * K.square(K.relu(1 - margin - y_pred)) + lamb * (
+ 1 - y_true) * K.square(K.relu(y_pred - margin)), axis=-1)
class Capsule(Layer):
