title: VGG, perceptual loss in keras
body: <p>I'm wondering if it's possible to add a custom model to a loss function in keras. For example:    </p>
  
  <pre><code>def model_loss(y_true, y_pred):
      inp = Input(shape=(128, 128, 1))
      x = Dense(2)(inp)
      x = Flatten()(x)
  
      model = Model(inputs=[inp], outputs=[x])
      a = model(y_pred)
      b = model(y_true)
  
      # calculate MSE
      mse = K.mean(K.square(a - b))
      return mse
  </code></pre>
  
  <p>This is a simplified example. I'll actually be using a VGG net in the loss, so just trying to understand the mechanics of keras.    </p>