title: Loading model with custom loss + keras
body: <p>In Keras, if you need to have a custom loss with additional parameters, we can use it like mentioned on <a href="https://datascience.stackexchange.com/questions/25029/custom-loss-function-with-additional-parameter-in-keras">https://datascience.stackexchange.com/questions/25029/custom-loss-function-with-additional-parameter-in-keras</a></p>
  
  <pre><code>def penalized_loss(noise):
      def loss(y_true, y_pred):
          return K.mean(K.square(y_pred - y_true) - K.square(y_true - noise), axis=-1)
      return loss
  </code></pre>
  
  <p>The above method works when I am training the model. However, once the model is trained I am having difficulty in loading the model. When I try to use the custom_objects parameter in load_model like below</p>
  
  <pre><code>model = load_model(modelFile, custom_objects={'penalized_loss': penalized_loss} )
  </code></pre>
  
  <p>it complains <code>ValueError: Unknown loss function:loss</code></p>
  
  <p>Is there any way to pass in the loss function as one of the custom losses in <code>custom_objects</code> ? From what I can gather, the inner function is not in the namespace during load_model call. Is there any easier way to load the model or use a custom loss with additional parameters</p>