Skip to content

Commit

Permalink
fix the problem of nan gradient for zero vector input in Length layer (
Browse files Browse the repository at this point in the history
  • Loading branch information
shshemi authored and Xifeng Guo committed Dec 3, 2018
1 parent 0621dd5 commit 923809b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion capsulelayers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Length(layers.Layer):
output: shape=[None, num_vectors]
"""
def call(self, inputs, **kwargs):
return K.sqrt(K.sum(K.square(inputs), -1))
return K.sqrt(K.sum(K.square(inputs), -1) + K.epsilon())

def compute_output_shape(self, input_shape):
return input_shape[:-1]
Expand Down

0 comments on commit 923809b

Please sign in to comment.