title: Average channels of convolutional layer keras
body: <p>I have a problem. I have built a ConvNet. One hidden before the final output the shape of the output of that hidden layer is (None,64,32,32). What I want is to take the element wise average of those 64 channels. I have tried this:</p>
  
  <pre><code>main_inputs=[]
  outputs=[]
  
  def convnet(channels,rows,columns):
          input=Input(shape=(channels,rows,columns))
          main_inputs.append(input)
          conv1=Convolution2D(kernel_size=(3,3) ,filters=64, padding="same")(input)
          activation1= Activation('relu')(conv1)
          conv2=Convolution2D(kernel_size=(3,3), filters=64, padding="same")(activation1)
          activation2 = Activation('relu')(conv2)
          conv3=Convolution2D(kernel_size=(3,3), filters=64, padding="same")(activation2)
          activation3 = Activation('relu')(conv3)
          conv4=Convolution2D(kernel_size=(3,3), filters=channels, padding="same")(activation3)
          out=keras.layers.Average()(conv4)
          activation4 = Activation('linear')(out)
          outputs.append(activation4)
          print(np.shape(outputs))
          model = Model(inputs=main_inputs, outputs=outputs)
  
          return model
  </code></pre>
  
  <p>But when I am getting an error:</p>
  
  <pre><code>ValueError: A merge layer should be called on a list of inputs
  </code></pre>
  
  <p>After that instead of the keras.layer.average I tried with the backend documentation: </p>
  
  <pre><code>out=K.mean(conv4,axis=1)
  </code></pre>
  
  <p>But I am getting this error:</p>
  
  <pre><code>'Tensor' object has no attribute '_keras_history'
  </code></pre>
  
  <p>Any ideas?</p>