title: Use "Flatten" or "Reshape" to get 1D output of unknown input shape in keras
body: <p>I want to use the keras layer <code>Flatten()</code> or <code>Reshape((-1,))</code> at the end of my model to output an 1D vector like <code>[0,0,1,0,0, ... ,0,0,1,0]</code>. </p>
  
  <p>Sadly there is an problem because of my unknown input shape which is:<br /> <code>input_shape=(4, None, 1)))</code>. </p>
  
  <p>So typically the input shape is something between <code>[batch_size, 4, 64, 1]</code> and <code>[batch_size, 4, 256, 1]</code> the output should be <strong>batch_size x unknown dimension</strong> (for the fist example above: <code>[batch_size, 64]</code> and for the secound <code>[batch_size, 256]</code>).</p>
  
  <p>My model looks like:</p>
  
  <pre class="lang-py prettyprint-override"><code>model = Sequential()
  model.add(Convolution2D(32, (4, 32), padding='same', input_shape=(4, None, 1)))
  model.add(BatchNormalization())
  model.add(LeakyReLU())
  model.add(Convolution2D(1, (1, 2), strides=(4, 1), padding='same'))
  model.add(Activation('sigmoid'))
  # model.add(Reshape((-1,))) produces the error
  # int() argument must be a string, a bytes-like object or a number, not 'NoneType' 
  model.compile(loss='binary_crossentropy', optimizer='adadelta')
  </code></pre>
  
  <p>So that my current output shape is <strong>[batchsize, 1, unknown dimension, 1]</strong>.
  Which does not allow me to use class_weights for example <code>"ValueError: class_weight not supported for 3+ dimensional targets."</code>. </p>
  
  <p>Is it possible to use something like <code>Flatten()</code> or <code>Reshape((1,))</code> to flatt my 3 dimensional output in keras (2.0.4 with tensorflow backend) when I use a flexible input shape?</p>
  
  <p>Thanks a lot!</p>