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))) stats = { "_type": "train_epoch", "epoch": "{}/{}".format(cur_epoch + 1, self._cfg.SOLVER.MAX_EPOCH), "dt": self.iter_timer.seconds(), "dt_data": self.data_timer.seconds(), "dt_net": self.net_timer.seconds(), "eta": eta, "lr": self.lr, "gpu_mem": "{:.2f}G".format(misc.gpu_mem_usage()), "RAM": "{:.2f}/{:.2f}G".format(*misc.cpu_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)
def log_epoch_stats(self, cur_epoch): """ Log the stats of the current epoch. Args: cur_epoch (int): the number of current epoch. """ stats = { "_type": "val_epoch", "epoch": "{}/{}".format(cur_epoch + 1, self._cfg.SOLVER.MAX_EPOCH), "time_diff": self.iter_timer.seconds(), "gpu_mem": "{:.2f}G".format(misc.gpu_mem_usage()), "RAM": "{:.2f}/{:.2f}G".format(*misc.cpu_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(), ) 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)
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))) stats = { "_type": "train_iter", "epoch": "{}/{}".format(cur_epoch + 1, self._cfg.SOLVER.MAX_EPOCH), "iter": "{}/{}".format(cur_iter + 1, self.epoch_iters), "dt": self.iter_timer.seconds(), "dt_data": self.data_timer.seconds(), "dt_net": self.net_timer.seconds(), "eta": eta, "loss": self.loss.get_win_median(), "lr": self.lr, "gpu_mem": "{:.2f}G".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)
def finalize_metrics(self, ks=(1, 5)): """ Calculate and log the final ensembled metrics. ks (tuple): list of top-k values for topk_accuracies. For example, ks = (1, 5) correspods to top-1 and top-5 accuracy. """ if not all(self.clip_count == self.num_clips): logger.warning("clip count {} ~= num clips {}".format( ", ".join([ "{}: {}".format(i, k) for i, k in enumerate(self.clip_count.tolist()) ]), self.num_clips, )) self.stats = {"split": "test_final"} if self.multi_label: map = get_map(self.video_preds.cpu().numpy(), self.video_labels.cpu().numpy()) self.stats["map"] = map else: num_topks_correct = metrics.topks_correct(self.video_preds, self.video_labels, ks) topks = [(x / self.video_preds.size(0)) * 100.0 for x in num_topks_correct] assert len({len(ks), len(topks)}) == 1 for k, topk in zip(ks, topks): self.stats["top{}_acc".format(k)] = "{:.{prec}f}".format( topk, prec=2) logging.log_json_stats(self.stats)
def finalize_metrics(self, log=True): """ Calculate and log the final AVA metrics. """ all_preds = torch.cat(self.all_preds, dim=0) all_ori_boxes = torch.cat(self.all_ori_boxes, dim=0) all_metadata = torch.cat(self.all_metadata, dim=0) if self.mode == "test" or (self.full_ava_test and self.mode == "val"): groundtruth = self.full_groundtruth else: groundtruth = self.mini_groundtruth self.full_map = evaluate_ava( all_preds, all_ori_boxes, all_metadata.tolist(), self.excluded_keys, self.class_whitelist, self.categories, groundtruth=groundtruth, video_idx_to_name=self.video_idx_to_name, ) if log: stats = {"mode": self.mode, "map": self.full_map} logging.log_json_stats(stats)
def log_iter_stats(self, cur_epoch, cur_iter): """ Log the stats. Args: cur_epoch (int): the current epoch. cur_iter (int): the current iteration. """ if (cur_iter + 1) % self.cfg.LOG_PERIOD != 0: return eta_sec = self.iter_timer.seconds() * (self.overall_iters - cur_iter) eta = str(datetime.timedelta(seconds=int(eta_sec))) if self.mode == "train": stats = { "_type": "{}_iter".format(self.mode), "cur_epoch": "{}".format(cur_epoch + 1), "cur_iter": "{}".format(cur_iter + 1), "eta": eta, "dt": self.iter_timer.seconds(), "dt_data": self.data_timer.seconds(), "dt_net": self.net_timer.seconds(), "mode": self.mode, "loss": self.loss.get_win_median(), "lr": self.lr, } elif self.mode == "val": stats = { "_type": "{}_iter".format(self.mode), "cur_epoch": "{}".format(cur_epoch + 1), "cur_iter": "{}".format(cur_iter + 1), "eta": eta, "dt": self.iter_timer.seconds(), "dt_data": self.data_timer.seconds(), "dt_net": self.net_timer.seconds(), "mode": self.mode, } elif self.mode == "test": stats = { "_type": "{}_iter".format(self.mode), "cur_iter": "{}".format(cur_iter + 1), "eta": eta, "dt": self.iter_timer.seconds(), "dt_data": self.data_timer.seconds(), "dt_net": self.net_timer.seconds(), "mode": self.mode, } else: raise NotImplementedError("Unknown mode: {}".format(self.mode)) logging.log_json_stats(stats)
def log_iter_stats(self, cur_iter): """ Log the stats. Args: cur_iter (int): the current iteration of testing. """ eta_sec = self.iter_timer.seconds() * (self.overall_iters - cur_iter) eta = str(datetime.timedelta(seconds=int(eta_sec))) stats = { "split": "test_iter", "cur_iter": "{}".format(cur_iter + 1), "eta": eta, "time_diff": self.iter_timer.seconds(), } logging.log_json_stats(stats)
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}G".format(misc.gpu_mem_usage()), "RAM": "{:.2f}/{:.2f}G".format(*misc.cpu_mem_usage()), } logging.log_json_stats(stats)