Detectron2: How to enable log?

Created on 23 Oct 2019  路  3Comments  路  Source: facebookresearch/detectron2

I written a simple training script train on a coco-like dataset and I can not saw any log print out:

import random
from detectron2.utils.visualizer import Visualizer
from detectron2.data.catalog import MetadataCatalog, DatasetCatalog
import cityscapes_data
import cv2
from detectron2.engine import DefaultTrainer
from detectron2.config import get_cfg
from detectron2.utils.logger import setup_logger
import os


if __name__ == "__main__":
    cfg = get_cfg()
    cfg.merge_from_file(
        "../../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml"
    )
    cfg.DATASETS.TRAIN = ("cityscapes",)
    cfg.DATASETS.TEST = ()  # no metrics implemented for this dataset
    cfg.DATALOADER.NUM_WORKERS = 2
    cfg.MODEL.WEIGHTS = "detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl"  # initialize from model zoo
    # cfg.MODEL.WEIGHTS = "./output/model_final.pth"  # initialize from model zoo
    cfg.SOLVER.IMS_PER_BATCH = 2
    cfg.SOLVER.BASE_LR = 0.0025
    cfg.SOLVER.MAX_ITER = (2500)  # 300 iterations seems good enough, but you can certainly train longer
    cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = (128)  # faster, and good enough for this toy dataset
    cfg.MODEL.ROI_HEADS.NUM_CLASSES = 8
    os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
    setup_logger(output=cfg.OUTPUT_DIR, name="cityscapes")
    trainer = DefaultTrainer(cfg)
    trainer.resume_or_load(resume=False)
    trainer.train()

It does not print out any log messages:

Config '../../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml' has no VERSION. Assuming it to be compatible with latest v2.
'roi_heads.box_predictor.cls_score.weight' has shape (81, 1024) in the checkpoint but (9, 1024) in the model! Skipped.
'roi_heads.box_predictor.cls_score.bias' has shape (81,) in the checkpoint but (9,) in the model! Skipped.
'roi_heads.box_predictor.bbox_pred.weight' has shape (320, 1024) in the checkpoint but (32, 1024) in the model! Skipped.
'roi_heads.box_predictor.bbox_pred.bias' has shape (320,) in the checkpoint but (32,) in the model! Skipped.
'roi_heads.mask_head.predictor.weight' has shape (80, 256, 1, 1) in the checkpoint but (8, 256, 1, 1) in the model! Skipped.
'roi_heads.mask_head.predictor.bias' has shape (80,) in the checkpoint but (8,) in the model! Skipped.

such as loss information.

Does there any easy way to do this? I know it can be done by override the trainer but does there any easiest way to do this?

Most helpful comment

Add (at the beginning of the file):

from detectron2.utils.logger import setup_logger
setup_logger()

All 3 comments

Add (at the beginning of the file):

from detectron2.utils.logger import setup_logger
setup_logger()

BTW, how to set interval of save checkpoint though?

If you use DefaultTrainer, you need overwrite its build_hooks to change the interval of PeriodicWriter.
If you do not use DefaultTrainer, then the interval is set in your own code.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GiovanniPasq picture GiovanniPasq  路  3Comments

AntonBaumannDE picture AntonBaumannDE  路  3Comments

marcoippolito picture marcoippolito  路  4Comments

limsijie93 picture limsijie93  路  3Comments

DeepLakhani99 picture DeepLakhani99  路  4Comments