title: How do I cast properly a boolean layer in keras?
body: <p>I am working with some custom layers and having problems with the shape of them, when I work with it separately it works, but when I load the model to use in another one as a layer, it doesn't work anymore. Here is my layers definition:</p>
  
  <pre><code>def signumTransform(x):
      """
      SIGNUM function
      if positive 1
      if negative -1
      """
      import keras.backend
      return keras.backend.sign(x)
  
  def logical_or_layer(x):
      """Processing an OR operation"""
      import keras.backend
      #normalized to 0,1 
      aux_array = keras.backend.sign(x)
      aux_array = keras.backend.relu(aux_array)
      # OR operation
      aux_array = keras.backend.any(aux_array)
      # casting back the True/False to 1,0
      aux_array = keras.backend.cast(aux_array, dtype='float32')
      return aux_array
  
  
  #this is the input tensor
  inputs = Input(shape=(inputSize,), name='input')
  
  #this is the Neurule layer
  x = Dense(neurulesQt, activation='softsign', name='neurules')(inputs)
  #after each neuron layer, the outputs need to be put into SIGNUM (-1 or 1)
  x = Lambda(signumTransform, output_shape=lambda x:x, name='signumAfterNeurules')(x)
  
  #separating into 2 (2 possible outputs)
  layer_split0 = Lambda( lambda x: x[:, :11], output_shape=[11], name='layer_split0')(x)
  layer_split1 = Lambda( lambda x: x[:, 11:20], output_shape=[9], name='layer_split1')(x)
  #this is the OR layer
  y_0 = Lambda(logical_or_layer, output_shape=[1], name='or0')(layer_split0)
  y_1 = Lambda(logical_or_layer, output_shape=[1], name='or1')(layer_split1)
  
  y = Lambda(lambda x: K.stack([x[0], x[1]]),output_shape=[2],  name="output")([y_0, y_1])
  </code></pre>
  
  <p>Until the <code>layer_split</code> everything works properly, but in my <code>y_0</code> and <code>y_1</code> I need to do an OR operation with <code>keras.backend.any()</code>, as a return I receive a boolean so I cast it back with <code>keras.backend.cast()</code>.</p>
  
  <p>If I use the Model as it is here described, it works...it compiles, can be validated and so on, but if I try to save it and load it, it simply loses one dimension, the batch dimension (<code>None</code>). The output in the summary is shown as <code>(None, 2)</code>, but when used as a layer and concatenated with another one, it shows <code>(2,)</code> and an error is thrown:</p>
  
  <p><code>InvalidArgumentError: Shape must be rank 2 but is rank 1 for 'merging_layer_10/concat' (op: 'ConcatV2') with input shapes: [?,16], [2], [].</code></p>
  
  <p>How should I properly cast it in the <code>logical_or_layer</code> function? Should I change the <code>output_shape</code> in the Lambda Layer?</p>