我如何使用Tensorboard for Detectron2获得测试精度?

问题描述 投票:0回答:1

我正在学习使用Detecron2。我按照this链接创建了一个自定义对象检测器。我的训练代码-

# training Detectron2
from detectron2.engine import DefaultTrainer
from detectron2.config import get_cfg
import os

cfg = get_cfg()
cfg.merge_from_file("./detectron2_repo/configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
cfg.DATASETS.TRAIN = ("pedestrian",)
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.SOLVER.IMS_PER_BATCH = 2
cfg.SOLVER.BASE_LR = 0.02
cfg.SOLVER.MAX_ITER = 300    # 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 dataset
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 1  

os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
trainer = DefaultTrainer(cfg)
trainer.resume_or_load(resume=False)
trainer.train()

它在输出目录中保存了一个日志文件,因此我可以使用张量板显示训练的准确性-

%load_ext tensorboard
%tensorboard --logdir output

效果很好,我可以看到我模型的训练精度。但是在测试/验证模型时-

cfg.MODEL.WEIGHTS = os.path.join(cfg.OUTPUT_DIR, "model_final.pth")
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.7   # set the testing threshold for this model
cfg.DATASETS.TEST = ("pedestrian_day", )
predictor = DefaultPredictor(cfg)

尽管我从Detectron2教程中得到-

from detectron2.evaluation import COCOEvaluator, inference_on_dataset
from detectron2.data import build_detection_test_loader
evaluator = COCOEvaluator("pedestrian_day", cfg, False, output_dir="./output/")
val_loader = build_detection_test_loader(cfg, "pedestrian_day", mapper=None)
inference_on_dataset(trainer.model, val_loader, evaluator)

但这为AP,AP50,AP75,APm,AP1和AP进行了培训和测试。我的问题是我如何能够像训练一个那样在张量板上看到测试的准确性?

python object-detection tensorboard
1个回答
0
投票

在输出文件夹中将有metrics.json文件。在此有培训的结果。但是'cls_accuarcy'的值是完全错误的。因为我尝试使用错误的数据集(具有随机框位置和随机类)并且还没有进行过预训练。我得到0.94。大声笑。

如果您使用cocotrainer而不是默认教练,则将获得AP(平均精度)值。这样您就可以计算出精度。但是现在我不知道这是理想的价值。您可以阅读https://tarangshah.com/blog/2018-01-27/what-is-map-understanding-the-statistic-of-choice-for-comparing-object-detection-models/

对于CocoTrainer:

类CocoTrainer(DefaultTrainer):

@ classmethoddef build_evaluator(cls,cfg,dataset_name,output_folder = None):

 if output_folder is None:
    os.makedirs("coco_eval", exist_ok=True)
    output_folder = "coco_eval"

 return COCOEvaluator(dataset_name, cfg, False, output_folder)
© www.soinside.com 2019 - 2024. All rights reserved.