0

I am trying to make a layer which flips an image in the horizontal axis and then adds this image to the batch dimension. The code is as follows:

class FlipLayer(keras.layers.Layer):
    def __init__(self, input_layer):
        super(FlipLayer, self).__init__()

    def get_output_shape(self, input_shape):
        return (2 * input_shape[0],) + input_shape[1:]

    def get_output(self, input):
        return keras.layers.Concatenate([
            input,
            flipim(input)
        ], axis=0)

Where 'flipim' is just a function flipping the numpy array in the desired axis. Keras does not give any error when compiling the model using this function, however it isn't doing anything. When I use this layer as my last layer and check the output, it is still the same size in the batch dimension compared to the previous layer.

D haverkamp
  • 41
  • 1
  • 7
  • Isn't your `Concatenate` layer missing your `input`? As in `Concatenate([input, flipim(input)], axis=0)` – sdcbr Dec 11 '18 at 15:27
  • Sorry, that was a typo, the input is indeed given in concatenate – D haverkamp Dec 11 '18 at 15:38
  • You are changing the batch size and I think this is not possible (at least in Keras). Concatenate them on another axis (i.e. the last one, channels). – today Dec 12 '18 at 01:21
  • I believe it is not throwing any exception because your logic should be placed in the `call` method. Check out [this example](https://keras.io/layers/writing-your-own-keras-layers/) to implement your custom layer. – rvinas Dec 12 '18 at 09:21

0 Answers0