title: Reshaping tensor after max pooling ValueError: Shapes are not compatible
body: <p>I am building CNN fitting my own data, based on <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/skflow/text_classification_character_cnn.py" rel="nofollow">this example</a></p>
  
  <p>Basically, my data has 3640 features; I have a convolution layer followed by a pooling layer, that pools every other feature, so I end up with dimensions (?, 1, 1819, 1) because 3638 features after conv layer / 2 == 1819. </p>
  
  <p>When I try to reshape my data after pooling to get it in the form [n_samples, n_fetures] </p>
  
  <pre><code>    print("pool_shape", pool_shape) #pool  (?, 1, 1819, 10)
      print("y_shape", y_shape) #y  (?,)
  
      pool.set_shape([pool_shape[0], pool_shape[2]*pool_shape[3]])
      y.set_shape([y_shape[0], 1])
  </code></pre>
  
  <p>I get an error:</p>
  
  <p><strong><code>ValueError: Shapes (?, 1, 1819, 10) and (?, 18190) are not compatible</code></strong></p>
  
  <p>My code:</p>
  
  <pre><code>N_FEATURES = 140*26
  N_FILTERS = 1
  WINDOW_SIZE = 3
  
  def my_conv_model(x, y):
  
      x = tf.cast(x, tf.float32)
      y = tf.cast(y, tf.float32)
  
      print("x ", x.get_shape())
      print("y ", y.get_shape())
  
      # to form a 4d tensor of shape batch_size x 1 x N_FEATURES x 1
      x = tf.reshape(x, [-1, 1, N_FEATURES, 1])
      # this will give you sliding window of 1 x WINDOW_SIZE convolution.
      features = tf.contrib.layers.convolution2d(inputs=x,
                                                 num_outputs=N_FILTERS,
                                                 kernel_size=[1, WINDOW_SIZE],
                                                 padding='VALID')
  
      print("features ", features.get_shape()) #features  (?, 1, 3638, 10)
  
      # Max pooling across output of Convolution+Relu.
      pool = tf.nn.max_pool(features, ksize=[1, 1, 2, 1],
                               strides=[1, 1, 2, 1], padding='SAME')
  
      pool_shape = pool.get_shape()
      y_shape = y.get_shape()
      print("pool_shape", pool_shape) #pool  (?, 1, 1819, 10)
      print("y_shape", y_shape) #y  (?,)
  
  ### here comes the error ###
      pool.set_shape([pool_shape[0], pool_shape[2]*pool_shape[3]])
      y.set_shape([y_shape[0], 1])
  
      pool_shape = pool.get_shape()
      y_shape = y.get_shape()
      print("pool_shape", pool_shape) #pool  (?, 1, 1819, 10)
      print("y_shape", y_shape) #y  (?,)
  
      prediction, loss = learn.models.logistic_regression(pool, y)
      return prediction, loss
  </code></pre>
  
  <p><strong>How to reshape the data to get any meaningful representation of it and to later pass it to logistic regression layer?</strong></p>