class_docstr: Class to bind an optimizer, model, strategy, and training step function.
class_docstr_tok: ["Class","to","bind","an","optimizer",",","model",",","strategy",",","and","training","step","function","."]
docstr: Restore model and optimizer from a checkpoint if it exists.
  
  Args:
    checkpoint_path: Path to checkpoint file or directory.
    restore_keys: Optional list of strings for submodules to restore.
  
  Raises:
    FileNotFoundError: If no checkpoint is found.
docstr_tok: ["Restore","model","and","optimizer","from","a","checkpoint","if","it","exists",".","Args",":","checkpoint_path",":","Path","to","checkpoint","file","or","directory",".","restore_keys",":","Optional","list","of","strings","for","submodules","to","restore",".","Raises",":","FileNotFoundError",":","If","no","checkpoint","is","found","."]
code: def restore(self, checkpoint_path, restore_keys=None):
      """Restore model and optimizer from a checkpoint if it exists.
  
      Args:
        checkpoint_path: Path to checkpoint file or directory.
        restore_keys: Optional list of strings for submodules to restore.
  
      Raises:
        FileNotFoundError: If no checkpoint is found.
      """
      logging.info("Restoring from checkpoint...")
      start_time = time.time()
  
      # Prefer function args over object properties.
      restore_keys = restore_keys or self.restore_keys
      if restore_keys is None:
          # If no keys are passed, restore the whole model.
          model = self.model
          logging.info("Trainer restoring the full model")
      else:
          # Restore only sub-modules by building a new subgraph.
          restore_dict = {
              k: getattr(self.model, k) for k in restore_keys
          }
          model = tf.train.Checkpoint(**restore_dict)
  
          logging.info("Trainer restoring model subcomponents:")
          for k, v in restore_dict.items():
              log_str = "Restoring {}: {}".format(k, v)
              logging.info(log_str)
  
      # Restore from latest checkpoint.
      checkpoint = self.get_checkpoint(model)
      latest_checkpoint = train_util.get_latest_checkpoint(
          checkpoint_path
      )
      # checkpoint.restore must be within a strategy.scope() so that optimizer
      # slot variables are mirrored.
      with self.strategy.scope():
          if restore_keys is None:
              checkpoint.restore(latest_checkpoint)
          else:
              checkpoint.restore(latest_checkpoint).expect_partial()
          logging.info("Loaded checkpoint %s", latest_checkpoint)
      logging.info(
          "Loading model took %.1f seconds", time.time() - start_time
      )
  
file_path: ddsp/ddsp/training/trainers.py
imports: import time
  from absl import logging
  from ddsp.training import train_util
  import gin
  import tensorflow.compat.v2
label_desc: Use image node_id 4 for calling the Trainer obj's underlying member method code with example usage: obj.restore(checkpoint_path, restore_keys) without return types