def log_json_stats()

in pycls/utils/logging.py [0:0]


def log_json_stats(stats, cur_epoch=None, writer=None, is_epoch=False, params=0, flops=0, model=None, is_master=False):
    """Logs json stats."""
    if writer is not None:
        for k, v in stats.items():
            if isinstance(v, float) or isinstance(v, int):
                writer.add_scalar(k, v, cur_epoch + 1)
        # if model is not None:
        #     for name, param in model.named_parameters():
        #         writer.add_histogram(name, param.clone().cpu().data.numpy(), cur_epoch)
    # Decimal + string workaround for having fixed len float vals in logs
    stats = {
        k: decimal.Decimal('{:.6f}'.format(v)) if isinstance(v, float) else v
        for k, v in stats.items()
    }
    json_stats = simplejson.dumps(stats, sort_keys=True, use_decimal=True)
    logger = get_logger(__name__)
    logger.info('{:s}{:s}'.format(_TAG, json_stats))
    if is_epoch and cur_epoch is not None and is_master:
        epoch_id = cur_epoch + 1
        result_info = ', '.join(
            [str(round(params / 1000000, 3)), str(round(flops / 1000000000, 3)), '{:.3f}'.format(stats['time_avg']),
             '{:.3f}'.format(stats['top1_err']), '{:.3f}'.format(stats['top5_err']),
             str(cfg.RGRAPH.GROUP_NUM), str(cfg.RGRAPH.DIM_LIST[0]), str(cfg.RGRAPH.SEED_TRAIN)])
        with open("{}/results_epoch{}.txt".format(cfg.OUT_DIR, epoch_id), "a") as text_file:
            text_file.write(result_info + '\n')