heuritech / convnets-keras

MIT License
594 stars 185 forks source link

Softmax2D computes wrong output shape #21

Open mohamed-ezz opened 7 years ago

mohamed-ezz commented 7 years ago

In the Softmax2D layer below, the forward pass does not change the output shape, but get_output_shape_for does. It gave me an error using Tensorflow backend. I had to change get_output_shape_for to an identity function (just returning input_shape with no change)

def call(self, x,mask=None):
    e = K.exp(x - K.max(x, axis=self.axis, keepdims=True))
    s = K.sum(e, axis=self.axis, keepdims=True)
    return e / s

def get_output_shape_for(self, input_shape):
    axis_index = self.axis % len(input_shape)
    return tuple([input_shape[i] for i in range(len(input_shape)) \
                  if i != axis_index ])