class_docstr: Progressive GAN model for a specific stage and batch_size.
class_docstr_tok: ["Progressive","GAN","model","for","a","specific","stage","and","batch_size","."]
docstr: Instantiate a Model for eval using flags and weights from a saved model.
  
  Currently only supports models trained by the experiment runner, since
  Model itself doesn't save flags (so we rely the runner's experiment.json)
  
  Args:
    path: Path to model directory (which contains stage folders).
    flags: Additional flags for loading the model.
  
  Raises:
    ValueError: If folder of path contains no stage folders.
  
  Returns:
    model: Instantiated model with saved weights.
docstr_tok: ["Instantiate","a","Model","for","eval","using","flags","and","weights","from","a","saved","model",".","Currently","only","supports","models","trained","by","the","experiment","runner",",","since","Model","itself","does","n't","save","flags","(","so","we","rely","the","runner","'s","experiment.json",")","Args",":","path",":","Path","to","model","directory","(","which","contains","stage","folders",")",".","flags",":","Additional","flags","for","loading","the","model",".","Raises",":","ValueError",":","If","folder","of","path","contains","no","stage","folders",".","Returns",":","model",":","Instantiated","model","with","saved","weights","."]
code: def load_from_path(cls, path, flags=None):
      """Instantiate a Model for eval using flags and weights from a saved model.
  
      Currently only supports models trained by the experiment runner, since
      Model itself doesn't save flags (so we rely the runner's experiment.json)
  
      Args:
        path: Path to model directory (which contains stage folders).
        flags: Additional flags for loading the model.
  
      Raises:
        ValueError: If folder of path contains no stage folders.
  
      Returns:
        model: Instantiated model with saved weights.
      """
      # Read the flags from the experiment.json file
      # experiment.json is in the folder above
      # Remove last '/' if present
      path = path.rstrip("/")
      if not path.startswith("gs://"):
          path = util.expand_path(path)
      if flags is None:
          flags = lib_flags.Flags()
      flags["train_root_dir"] = path
      experiment_json_path = os.path.join(path, "experiment.json")
      try:
          # Read json to dict
          with tf.gfile.GFile(experiment_json_path, "r") as f:
              experiment_json = json.load(f)
          # Load dict as a Flags() object
          flags.load(experiment_json)
      except Exception as e:  # pylint: disable=broad-except
          print(
              "Warning! Couldn't load model flags from experiment.json"
          )
          print(e)
      # Set default flags
      set_flags(flags)
      flags.print_values()
      # Get list_of_directories
      train_sub_dirs = sorted(
          [
              sub_dir
              for sub_dir in tf.gfile.ListDirectory(path)
              if sub_dir.startswith("stage_")
          ]
      )
      if not train_sub_dirs:
          raise ValueError(
              "No stage folders found, is %s the correct model path?"
              % path
          )
      # Get last checkpoint
      last_stage_dir = train_sub_dirs[-1]
      stage_id = int(last_stage_dir.split("_")[-1].strip("/"))
      weights_dir = os.path.join(path, last_stage_dir)
      ckpt = tf.train.latest_checkpoint(weights_dir)
      print("Load model from {}".format(ckpt))
      # Load the model, use eval_batch_size if present
      batch_size = flags.get(
          "eval_batch_size",
          train_util.get_batch_size(stage_id, **flags),
      )
      model = cls(stage_id, batch_size, flags)
      model.saver.restore(model.sess, ckpt)
      return model
  
imports: import json
  import os
  import time
  from magenta.models.gansynth.lib import data_helpers
  from magenta.models.gansynth.lib import flags
  from magenta.models.gansynth.lib import network_functions
  from magenta.models.gansynth.lib import networks
  from magenta.models.gansynth.lib import train_util
  from magenta.models.gansynth.lib import util
  import numpy
  import tensorflow.compat.v1
  import tensorflow_gan
label_desc: Use image node_id 1 for calling the Model obj's underlying member method code with example usage: obj.load_from_path(cls, path, flags) and returns: model