title: Calculating the pearson coefficients in a keras model met with AttributeError: 'NoneType' object has no attribute '_inbound_nodes'
body: <p>I'm using pearson correlation coefficients as the input features of the MLP model, and meeting with problem when establishing the model.</p>
  
  <p>I've updated and run my code according to <strong>today</strong>'s favorable comment that wrapping the function inside a Lambda layer, whereas the same error still occurs. I thought I've fixed the errors <strong>today</strong> mentioned. Below is my updated code:</p>
  
  <pre><code>from keras.layers import Conv2D, Input, Lambda, MaxPooling2D, BatchNormalization, Add, Flatten, Dense, Concatenate
  from keras.models import Model, Sequential
  import keras.backend as K
  
  def cal_cor(x):
      a, b = x
      assert a.shape[1] == b.shape[1], 'lengths not compatible'
  
      a_mean = K.mean(a)
      b_mean = K.mean(b)
      a_norm = a - a_mean
      b_norm = b - b_mean
      numerator = a_norm * b_norm
  
      a_var = K.square(a_norm)
      b_var = K.square(b_norm)
      denominator = (a_var * b_var) ** 0.5
  
      return numerator / denominator
  
  def cnn_with_pearson():
  
      # Pearson part
      cor_layer = Lambda(function=cal_cor, name='correlation_layer')
  
      cors = []
      for i in range(28):
          cor_added = []
          for j in range(28):
              if i == j:
                  continue
              cor_added.append( cor_layer( [input[:, i, :, 0], input[:, j, :, 0]] ) )
          cors.append(Add()(cor_added))
  
      con = Concatenate()(cors)
      f = Flatten()(K.expand_dims(con, -1))
      d = Dense(units=10, activation='softmax')(f)
      model = Model(inputs=input, outputs=d)
  
      return model
  
  model = cnn_with_pearson()
  </code></pre>
  
  <p>Error occurs in the line <code>model = Model(inputs=input, outputs=d)</code>:</p>
  
  <pre><code>AttributeError: 'NoneType' object has no attribute '_inbound_nodes'
  </code></pre>