當前位置: 首頁>>代碼示例>>Python>>正文


Python logging.Logger方法代碼示例

本文整理匯總了Python中utils.logging.Logger方法的典型用法代碼示例。如果您正苦於以下問題:Python logging.Logger方法的具體用法?Python logging.Logger怎麽用?Python logging.Logger使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在utils.logging的用法示例。


在下文中一共展示了logging.Logger方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_logger

# 需要導入模塊: from utils import logging [as 別名]
# 或者: from utils.logging import Logger [as 別名]
def create_logger(self):
        """
        Create the logger including the file log and summary log
        :return: logger and summary writer
        """
        if self.args.training:
            logger = Logger(self.args.log, '%s-%s' % (self.args.method, self.args.postfix),
                            rm_exist=self.args.start_epoch == 0)
            logger.update_dict(vars(self.args))

            if self.args.mxboard:
                from mxboard import SummaryWriter
                sw = SummaryWriter(logdir=self.args.log)
            else:
                sw = None
        else:
            logger, sw = None, None

        return logger, sw 
開發者ID:aws-samples,項目名稱:d-SNE,代碼行數:21,代碼來源:training_sda.py

示例2: train

# 需要導入模塊: from utils import logging [as 別名]
# 或者: from utils.logging import Logger [as 別名]
def train(opt, model, dataloader):
  # Logging
  logger = logging.Logger(opt.ckpt_path, opt.split)
  stats = logging.Statistics(opt.ckpt_path, opt.split)
  logger.log(opt)

  model.load(opt.load_ckpt_paths, opt.load_opts, opt.load_epoch)
  for epoch in range(1, opt.n_epochs + 1):
    for step, data in enumerate(dataloader, 1):
      # inputs is a list of input of each modality
      inputs, label, _ = data
      ret = model.train(inputs, label)
      update = stats.update(len(label), ret)
      if utils.is_due(step, opt.print_every):
        utils.info('epoch {}/{}, step {}/{}: {}'.format(
            epoch, opt.n_epochs, step, len(dataloader), update))

    logger.log('[Summary] epoch {}/{}: {}'.format(epoch, opt.n_epochs,
                                                  stats.summarize()))

    if utils.is_due(epoch, opt.n_epochs, opt.save_every):
      model.save(epoch)
      stats.save()
      logger.log('***** saved *****')

    if utils.is_due(epoch, opt.lr_decay_at):
      lrs = model.lr_decay()
      logger.log('***** lr decay *****: {}'.format(lrs)) 
開發者ID:google,項目名稱:graph_distillation,代碼行數:30,代碼來源:run.py

示例3: test

# 需要導入模塊: from utils import logging [as 別名]
# 或者: from utils.logging import Logger [as 別名]
def test(opt, model, dataloader):
  # Logging
  logger = logging.Logger(opt.ckpt_path, opt.split)
  stats = logging.Statistics(opt.ckpt_path, opt.split)
  logger.log(opt)

  model.load(opt.load_ckpt_paths, opt.load_opts, opt.load_epoch)
  all_scores = []
  video_names = []
  for step, data in enumerate(dataloader, 1):
    inputs, label, vid_name = data
    info_acc, logits, scores = model.test(inputs, label, opt.timestep)

    all_scores.append(scores)
    video_names.append(vid_name[0])
    update = stats.update(logits.shape[0], info_acc)
    if utils.is_due(step, opt.print_every):
      utils.info('step {}/{}: {}'.format(step, len(dataloader), update))

  logger.log('[Summary] {}'.format(stats.summarize()))

  # Evaluate
  iou_thresholds = [0.1, 0.3, 0.5]
  groundtruth_dir = os.path.join(opt.dset_path, opt.dset, 'groundtruth',
                                 'validation/cross-subject')
  assert os.path.exists(groundtruth_dir), '{} does not exist'.format(groundtruth_dir)
  mean_aps = calc_map(opt, all_scores, video_names, groundtruth_dir, iou_thresholds)

  for i in range(len(iou_thresholds)):
    logger.log('IoU: {}, mAP: {}'.format(iou_thresholds[i], mean_aps[i])) 
開發者ID:google,項目名稱:graph_distillation,代碼行數:32,代碼來源:run.py

示例4: train

# 需要導入模塊: from utils import logging [as 別名]
# 或者: from utils.logging import Logger [as 別名]
def train(opt, model, dataloader):
  """Train the model."""
  # Logging
  logger = logging.Logger(opt.ckpt_path, opt.split)
  stats = logging.Statistics(opt.ckpt_path, opt.split)
  logger.log(opt)

  model.load(opt.load_ckpt_paths, opt.load_epoch)
  for epoch in range(1, opt.n_epochs + 1):
    for step, data in enumerate(dataloader, 1):
      ret = model.train(*data)
      update = stats.update(data[-1].size(0), ret)
      if utils.is_due(step, opt.print_every):
        utils.info('epoch {}/{}, step {}/{}: {}'.format(
            epoch, opt.n_epochs, step, len(dataloader), update))

    logger.log('[Summary] epoch {}/{}: {}'.format(epoch, opt.n_epochs,
                                                  stats.summarize()))

    if utils.is_due(epoch, opt.n_epochs, opt.save_every):
      model.save(epoch)
      logger.log('***** saved *****')

    if utils.is_due(epoch, opt.lr_decay_at):
      lrs = model.lr_decay()
      logger.log('***** lr decay *****: {}'.format(lrs)) 
開發者ID:google,項目名稱:graph_distillation,代碼行數:28,代碼來源:run.py

示例5: test

# 需要導入模塊: from utils import logging [as 別名]
# 或者: from utils.logging import Logger [as 別名]
def test(opt, model, dataloader):
  '''Test model.'''
  # Logging
  logger = logging.Logger(opt.load_ckpt_path, opt.split)
  stats = logging.Statistics(opt.ckpt_path, opt.split)
  logger.log(opt)

  logits, labels = [], []
  model.load(opt.load_ckpt_paths, opt.load_epoch)
  for step, data in enumerate(dataloader, 1):
    inputs, label = data
    info_acc, logit = model.test(inputs, label)
    logits.append(utils.to_numpy(logit.squeeze(0)))
    labels.append(utils.to_numpy(label))
    update = stats.update(label.size(0), info_acc)
    if utils.is_due(step, opt.print_every):
      utils.info('step {}/{}: {}'.format(step, len(dataloader), update))

  logits = np.concatenate(logits, axis=0)
  length, n_classes = logits.shape
  labels = np.concatenate(labels)
  scores = utils.softmax(logits, axis=1)

  # Accuracy
  preds = np.argmax(scores, axis=1)
  acc = np.sum(preds == labels) / length
  # Average precision
  y_true = np.zeros((length, n_classes))
  y_true[np.arange(length), labels] = 1
  aps = average_precision_score(y_true, scores, average=None)
  aps = list(filter(lambda x: not np.isnan(x), aps))
  mAP = np.mean(aps)

  logger.log('[Summary]: {}'.format(stats.summarize()))
  logger.log('Acc: {}, mAP: {}'.format(acc, mAP)) 
開發者ID:google,項目名稱:graph_distillation,代碼行數:37,代碼來源:run.py

示例6: run

# 需要導入模塊: from utils import logging [as 別名]
# 或者: from utils.logging import Logger [as 別名]
def run(_run, _config, _log):

    # check args sanity
    _config = args_sanity_check(_config, _log)

    args = SN(**_config)
    args.device = "cuda" if args.use_cuda else "cpu"

    # setup loggers
    logger = Logger(_log)

    _log.info("Experiment Parameters:")
    experiment_params = pprint.pformat(_config,
                                       indent=4,
                                       width=1)
    _log.info("\n\n" + experiment_params + "\n")

    # configure tensorboard logger
    unique_token = "{}__{}".format(args.name, datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
    args.unique_token = unique_token
    if args.use_tensorboard:
        tb_logs_direc = os.path.join(dirname(dirname(abspath(__file__))), "results", "tb_logs")
        tb_exp_direc = os.path.join(tb_logs_direc, "{}").format(unique_token)
        logger.setup_tb(tb_exp_direc)

    # sacred is on by default
    logger.setup_sacred(_run)

    # Run and train
    run_sequential(args=args, logger=logger)

    # Clean up after finishing
    print("Exiting Main")

    print("Stopping all threads")
    for t in threading.enumerate():
        if t.name != "MainThread":
            print("Thread {} is alive! Is daemon: {}".format(t.name, t.daemon))
            t.join(timeout=1)
            print("Thread joined")

    print("Exiting script")

    # Making sure framework really exits
    os._exit(os.EX_OK) 
開發者ID:oxwhirl,項目名稱:pymarl,代碼行數:47,代碼來源:run.py


注:本文中的utils.logging.Logger方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。