title: keras model subclassing examples
body: <p>starting Keras 2.2.0, the 3rd API of model definition is released: Model subclassing.</p>
  
  <p>According to the FAQ: </p>
  
  <blockquote>
    <p>However, in subclassed models, the model's topology is defined as
    Python code (rather than as a static graph of layers). That means the
    model's topology cannot be inspected or serialized. As a result, the
    following methods and attributes are not available for subclassed
    models:</p>
    
    <p>model.inputs and model.outputs. model.to_yaml() and model.to_json()
    model.get_config() and model.save().</p>
  </blockquote>
  
  <p>The only option to save the trained model for inference is to use <strong>model.save_weights</strong> method. However, I have not had luck in loading the model back for inference. Encountered error messages include:</p>
  
  <blockquote>
    <p>This model has never been called, thus its weights have not yet been created, so no summary can be displayed. Build the model first (e.g. by calling it on some test data).
    You are trying to load a weight file containing 4 layers into a model with 0 layers.
    NotImplementedError</p>
  </blockquote>
  
  <p>Can anyone give a full toy example for creating a subclassed keras model, train, and save_weights, then load it back for inference?</p>