text: import argparse
  import copy
  import os
  import sys
  
  import dnnlib
  from dnnlib import EasyDict
  
  from metrics.metric_defaults import metric_defaults
  
  
  def run(dataset, data_dir, result_dir, num_gpus, total_kimg, mirror_augment, metrics):
      train = EasyDict(run_func_name='classifier.training_loop.training_loop')
      classifier = EasyDict(func_name='classifier.network.classifier')
      classifier_opt = EasyDict(beta1=0.0, beta2=0.99, epsilon=1e-8)
      classifier_loss = EasyDict(func_name='classifier.loss.cross_entropy')
      sched = EasyDict()
      sc = dnnlib.SubmitConfig()
      tf_config = {'rnd.np_random_seed': 1000}
  
      train.data_dir = data_dir
      train.total_kimg = total_kimg
      train.mirror_augment = mirror_augment
      train.image_snapshot_ticks = train.network_snapshot_ticks = 10
      metrics = [metric_defaults[x] for x in metrics]
      desc = 'classifier'
  
      desc += '-' + dataset
      dataset_args = EasyDict(tfrecord_dir=dataset)
  
      assert num_gpus in [1, 2, 4, 8]
      sc.num_gpus = num_gpus
      desc += '-%dgpu' % num_gpus
  
      sc.submit_target = dnnlib.SubmitTarget.LOCAL
      sc.local.do_not_copy_source_files = True
      kwargs = EasyDict(train)
      kwargs.update(classifier_args=classifier, classifier_opt_args=classifier_opt, classifier_loss_args=classifier_loss)
      kwargs.update(dataset_args=dataset_args, sched_args=sched, metric_arg_list=metrics, tf_config=tf_config)
      kwargs.submit_config = copy.deepcopy(sc)
      kwargs.submit_config.run_dir_root = result_dir
      kwargs.submit_config.run_desc = desc
      dnnlib.submit_run(**kwargs)
  
  
  def _str_to_bool(v):
      if isinstance(v, bool):
          return v
      if v.lower() in ('yes', 'true', 't', 'y', '1'):
          return True
      elif v.lower() in ('no', 'false', 'f', 'n', '0'):
          return False
      else:
          raise argparse.ArgumentTypeError('Boolean value expected.')
  
  
  def _parse_comma_sep(s):
      if s is None or s.lower() == 'none' or s == '':
          return []
      return s.split(',')
  
  
  def main():
      parser = argparse.ArgumentParser(
          description='Train StyleGAN2.',
          epilog='',
          formatter_class=argparse.RawDescriptionHelpFormatter
      )
      parser.add_argument('--result-dir', help='Root directory for run results (default: %(default)s)', default='results',
                          metavar='DIR')
      parser.add_argument('--data-dir', help='Dataset root directory', required=True)
      parser.add_argument('--dataset', help='Training dataset', required=True)
  
      parser.add_argument('--num-gpus', help='Number of GPUs (default: %(default)s)', default=1, type=int, metavar='N')
      parser.add_argument('--total-kimg', help='Training length in thousands of images (default: %(default)s)',
                          metavar='KIMG', default=25000, type=int)
      parser.add_argument('--mirror-augment', help='Mirror augment (default: %(default)s)', default=False, metavar='BOOL',
                          type=_str_to_bool)
      parser.add_argument('--metrics', help='Comma-separated list of metrics or "none" (default: %(default)s)',
                          default='acc', type=_parse_comma_sep)
  
      args = parser.parse_args()
  
      if not os.path.exists(args.data_dir):
          print('Error: dataset root directory does not exist.')
          sys.exit(1)
  
      for metric in args.metrics:
          if metric not in metric_defaults:
              print('Error: unknown metric \'%s\'' % metric)
              sys.exit(1)
  
      run(**vars(args))
  
  
  if __name__ == "__main__":
      main()
  