import tensorflow as tf

        vars_to_load = {}
        for var in resnet_vars:
          if var.name not in optimizer_vars:
            var_name = var.name
            # Trim the index of the variable.
            if ':' in var_name:
              var_name = var_name[:var_name.rindex(':')]
            if params['skip_checkpoint_variables'] and re.match(
                params['skip_checkpoint_variables'], var_name[len(prefix):]):
              continue
            vars_to_load[var_name[len(prefix):]] = var_name
        tf.logging.info(
            'Optimizer vars: %s.' % ', '.join(var for var in optimizer_vars))
        tf.logging.info('Will train: %s.' % vars_to_load)
        tf.train.init_from_checkpoint(params['resnet_checkpoint'], vars_to_load)
        if not vars_to_load:
          raise ValueError('Variables to load is empty.')
        return tf.train.Scaffold()

    # Batch norm requires update_ops to be added as a train_op dependency.
    update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
    grads_and_vars = optimizer.compute_gradients(total_loss, var_list)
    gradients, variables = zip(*grads_and_vars)
    grads_and_vars = []
    # Special treatment for biases (beta is named as bias in reference model)
    # Reference: https://github.com/facebookresearch/Detectron/blob/master/detectron/modeling/optimizer.py#L113  # pylint: disable=line-too-long
