Пример #1
0
 def log_epoch_stats(self, cur_epoch):
     """
     Log the stats of the current epoch.
     Args:
         cur_epoch (int): the number of current epoch.
     """
     eta_sec = self.iter_timer.seconds() * (
         self.MAX_ITERS - (cur_epoch + 1) * self.epoch_iters)
     eta = str(datetime.timedelta(seconds=int(eta_sec)))
     stats = {
         "_type": "train_epoch",
         "epoch": "{}/{}".format(cur_epoch + 1, self.MAX_EPOCH),
         "time_diff": self.iter_timer.seconds(),
         "eta": eta,
         "lr": self.lr,
         "gpu_mem": int(np.ceil(misc.gpu_mem_usage())),
     }
     if not self._cfg.DATA.MULTI_LABEL:
         top1_err = self.num_top1_mis / self.num_samples
         top5_err = self.num_top5_mis / self.num_samples
         avg_loss = self.loss_total / self.num_samples
         stats["top1_err"] = top1_err
         stats["top5_err"] = top5_err
         stats["loss"] = avg_loss
     logging.log_json_stats(stats)
Пример #2
0
    def log_epoch_stats(self, cur_epoch):
        """
        Log the stats of the current epoch.
        Args:
            cur_epoch (int): the number of current epoch.
        """
        mem_usage = misc.gpu_mem_usage()
        stats = {
            "_type": "val_epoch",
            "epoch": "{}/{}".format(cur_epoch + 1, self.MAX_EPOCH),
            "time_diff": self.iter_timer.seconds(),
            "gpu_mem": int(np.ceil(mem_usage)),
        }
        if self._cfg.DATA.MULTI_LABEL:
            stats["map"] = get_map(
                torch.cat(self.all_preds).cpu().numpy(),
                torch.cat(self.all_labels).cpu().numpy(),
            )
            self.max_map = max(self.max_map, stats["map"])
            stats["max_map"] = self.max_map
        else:
            top1_err = self.num_top1_mis / self.num_samples
            top5_err = self.num_top5_mis / self.num_samples
            self.min_top1_err = min(self.min_top1_err, top1_err)
            self.min_top5_err = min(self.min_top5_err, top5_err)

            stats["top1_err"] = top1_err
            stats["top5_err"] = top5_err
            stats["min_top1_err"] = self.min_top1_err
            stats["min_top5_err"] = self.min_top5_err
        logging.log_json_stats(stats)

        return stats
Пример #3
0
 def log_iter_stats(self, cur_epoch, cur_iter, global_iter):
     """
     log the stats of the current iteration.
     Args:
         cur_epoch (int): the number of current epoch.
         cur_iter (int): the number of current iteration in current epoch.
         global_iter (int): the number of current iteration in training phase
     """
     if (cur_iter + 1) % self._cfg.LOG_PERIOD != 0:
         return
     eta_sec = self.iter_timer.seconds() * (
         self.MAX_ITERS - (cur_epoch * self.epoch_iters + cur_iter + 1))
     eta = str(datetime.timedelta(seconds=int(eta_sec)))
     stats = {
         "_type": "train_iter",
         "global_iter": "{}/{}".format(global_iter, self.MAX_ITERS),
         "epoch": "{}/{}".format(cur_epoch + 1, self.MAX_EPOCH),
         "iter": "{}/{}".format(cur_iter + 1, self.epoch_iters),
         "time_diff": self.iter_timer.seconds(),
         "eta": eta,
         "loss": self.loss.get_win_median(),
         "lr": self.lr,
         "gpu_mem": int(np.ceil(misc.gpu_mem_usage())),
     }
     if not self._cfg.DATA.MULTI_LABEL:
         stats["top1_err"] = self.mb_top1_err.get_win_median()
         stats["top5_err"] = self.mb_top5_err.get_win_median()
     logging.log_json_stats(stats)
Пример #4
0
 def log_epoch_stats(self, cur_epoch):
     """
     Log the stats of the current epoch.
     Args:
         cur_epoch (int): the number of current epoch.
     """
     if self.mode in ["val", "test"]:
         self.finalize_metrics(log=False)
         stats = {
             "_type": "{}_epoch".format(self.mode),
             "cur_epoch": "{}".format(cur_epoch + 1),
             "mode": self.mode,
             "map": self.full_map,
             "gpu_mem": "{:.2f} GB".format(misc.gpu_mem_usage()),
             "RAM": "{:.2f}/{:.2f} GB".format(*misc.cpu_mem_usage()),
         }
         logging.log_json_stats(stats)
Пример #5
0
 def log_epoch_stats(self, cur_epoch):
     """
     Log the stats of the current epoch.
     Args:
         cur_epoch (int): the number of current epoch.
     """
     eta_sec = self.iter_timer.seconds() * (
         self.MAX_EPOCH - (cur_epoch + 1) * self.epoch_iters)
     eta = str(datetime.timedelta(seconds=int(eta_sec)))
     mem_usage = misc.gpu_mem_usage()
     stats = {
         "_type": "train_epoch",
         "epoch": "{}/{}".format(cur_epoch + 1, self._cfg.SOLVER.MAX_EPOCH),
         "time_diff": self.iter_timer.seconds(),
         "eta": eta,
         "mem": int(np.ceil(mem_usage)),
     }
     infos = {k: v.get_global_avg() for k, v in self.infos}
     stats.update(infos)
     logging.log_json_stats(stats)
Пример #6
0
 def log_iter_stats(self, cur_epoch, cur_iter):
     """
     log the stats of the current iteration.
     Args:
         cur_epoch (int): the number of current epoch.
         cur_iter (int): the number of current iteration.
     """
     if (cur_iter + 1) % self._cfg.LOG_PERIOD != 0:
         return
     eta_sec = self.iter_timer.seconds() * (self.max_iter - cur_iter - 1)
     eta = str(datetime.timedelta(seconds=int(eta_sec)))
     stats = {
         "_type": "val_iter",
         "epoch": "{}/{}".format(cur_epoch + 1, self._cfg.SOLVER.MAX_EPOCH),
         "iter": "{}/{}".format(cur_iter + 1, self.max_iter),
         "time_diff": self.iter_timer.seconds(),
         "eta": eta,
         "gpu_mem": "{:.2f} GB".format(misc.gpu_mem_usage()),
     }
     if not self._cfg.DATA.MULTI_LABEL:
         stats["top1_err"] = self.mb_top1_err.get_win_median()
         stats["top5_err"] = self.mb_top5_err.get_win_median()
     logging.log_json_stats(stats)
Пример #7
0
 def log_iter_stats(self, cur_epoch, cur_iter):
     """
     log the stats of the current iteration.
     Args:
         cur_epoch (int): the number of current epoch.
         cur_iter (int): the number of current iteration.
     """
     if (cur_iter + 1) % self._cfg.LOG_PERIOD != 0:
         return
     eta_sec = self.iter_timer.seconds() * (
         self.MAX_EPOCH - (cur_epoch * self.epoch_iters + cur_iter + 1))
     eta = str(datetime.timedelta(seconds=int(eta_sec)))
     mem_usage = misc.gpu_mem_usage()
     stats = {
         "_type": "train_iter",
         "epoch": "{}/{}".format(cur_epoch + 1, self._cfg.SOLVER.MAX_EPOCH),
         "iter": "{}/{}".format(cur_iter + 1, self.epoch_iters),
         "time_diff": self.iter_timer.seconds(),
         "eta": eta,
         "mem": int(np.ceil(mem_usage)),
     }
     infos = {k: v.get_win_avg() for k, v in self.infos}
     stats.update(infos)
     logging.log_json_stats(stats)