title: NameError: name 'keras_applications' is not defined when loading model
body: <p>I have a custom keras model built in the following way :</p>
  
  <pre><code>def gen_base_model(n_class):
      cnn_model = InceptionResNetV2(include_top=False, input_shape=(width, width, 3), weights='imagenet')
      inputs = Input((width, width, 3))
  
      x = inputs
      x = Lambda(preprocess_input, name='preprocessing')(x)
      x = cnn_model(x)
      x = GlobalAveragePooling2D()(x)
      x = Dropout(0.5)(x)
      x = Dense(n_class, activation='softmax', name='softmax')(x)
  
      model = Model(inputs, x)
      return model
  </code></pre>
  
  <p>I trained the model and saved it using <code>model.save()</code>.</p>
  
  <p>However, everytime I try to load the model, I get the following error :</p>
  
  <pre><code>&gt;&gt;&gt; model = load_model('coat.hdf5')
  WARNING:tensorflow:From /home/aniruddh/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
  Instructions for updating:
  Colocations handled automatically by placer.
  2019-05-23 23:24:38.613487: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
  2019-05-23 23:24:38.637936: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 1992000000 Hz
  2019-05-23 23:24:38.638313: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x55951c96f170 executing computations on platform Host. Devices:
  2019-05-23 23:24:38.638370: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): &lt;undefined&gt;, &lt;undefined&gt;
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/home/aniruddh/anaconda3/lib/python3.6/site-packages/keras/models.py", line 243, in load_model
      model = model_from_config(model_config, custom_objects=custom_objects)
    File "/home/aniruddh/anaconda3/lib/python3.6/site-packages/keras/models.py", line 317, in model_from_config
      return layer_module.deserialize(config, custom_objects=custom_objects)
    File "/home/aniruddh/anaconda3/lib/python3.6/site-packages/keras/layers/__init__.py", line 55, in deserialize
      printable_module_name='layer')
    File "/home/aniruddh/anaconda3/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 144, in deserialize_keras_object
      list(custom_objects.items())))
    File "/home/aniruddh/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 2520, in from_config
      process_node(layer, node_data)
    File "/home/aniruddh/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 2477, in process_node
      layer(input_tensors[0], **kwargs)
    File "/home/aniruddh/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 617, in __call__
      output = self.call(inputs, **kwargs)
    File "/home/aniruddh/anaconda3/lib/python3.6/site-packages/keras/layers/core.py", line 663, in call
      return self.function(inputs, **arguments)
    File "/usr/local/lib/python3.6/dist-packages/keras/applications/__init__.py", line 23, in wrapper
  NameError: name 'keras_applications' is not defined
  </code></pre>
  
  <p>I have also tried saving the model as a json file along with its weights, but it fails saying </p>
  
  <pre><code>TypeError: ('Not JSON Serializable:', &lt;function preprocess_input at 0x7fa12b5e79d8&gt;)
  </code></pre>
  
  <p>Where might I be going wrong? </p>