I insert this line of code in 3.xxx version, but compile an error, How should I modify it in the code. Here is all my code. Please see all the big guys to help you solve it. Thanks very much
import os
import mmcv
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval
from mmdet.apis import init_detector, inference_detector
from mmengine.config import Config
from mmdet.datasets import build_dataset
from mmdet.registry import VISUALIZERS
def getPrecisions(config_file, result_file, metric="bbox"):
"""plot precison-recall curve based on testing results of pkl file.
Args:
config_file (list[list | tuple]): config file path.
result_file (str): pkl file of testing results path.
metric (str): Metrics to be evaluated. Options are
'bbox', 'segm'.
"""
cfg = Config.fromfile(config_file)
print(cfg.test_dataloader.dataset)
# turn on test mode of dataset
# if isinstance(cfg.dataset.test, dict):
# cfg.data.test.test_mode = True
# elif isinstance(cfg.dataset.test, list):
# for ds_cfg in cfg.dataset.test:
# ds_cfg.test_mode = True
if isinstance(cfg.test_dataloader.dataset, dict):
cfg.test_dataloader.dataset.test_mode = True
elif isinstance(cfg.test_dataloader.dataset, list):
for ds_cfg in cfg.test_dataloader.dataset:
ds_cfg.test_mode = True
# build dataset
**dataset = build_dataset(cfg.test_dataloader.dataset)**
# load result file in pkl format
pkl_results = mmcv.load(result_file)
# convert pkl file (list[list | tuple | ndarray]) to json
json_results, _ = dataset.format_results(pkl_results)
# initialize COCO instance
coco = COCO(annotation_file=cfg.data.test.ann_file)
coco_gt = coco
coco_dt = coco_gt.loadRes(json_results[metric])
# initialize COCOeval instance
coco_eval = COCOeval(coco_gt, coco_dt, metric)
coco_eval.evaluate()
coco_eval.accumulate()
coco_eval.summarize()
'''
precisions[T, R, K, A, M]
T: iou thresholds [0.5 : 0.05 : 0.95], idx from 0 to 9
R: recall thresholds [0 : 0.01 : 1], idx from 0 to 100
K: category, idx from 0 to ...
A: area range, (all, small, medium, large), idx from 0 to 3
M: max dets, (1, 10, 100), idx from 0 to 2
'''
return coco_eval.eval["precision"]
def PR(config, result, out, thr=0.5):
"""Export PR Excel data
I insert this line of code in 3.xxx version, but compile an error, How should I modify it in the code. Here is all my code. Please see all the big guys to help you solve it. Thanks very much
import os import mmcv import numpy as np import matplotlib.pyplot as plt import pandas as pd
from pycocotools.coco import COCO from pycocotools.cocoeval import COCOeval from mmdet.apis import init_detector, inference_detector from mmengine.config import Config
from mmdet.datasets import build_dataset
from mmdet.registry import VISUALIZERS
def getPrecisions(config_file, result_file, metric="bbox"): """plot precison-recall curve based on testing results of pkl file.
def PR(config, result, out, thr=0.5): """Export PR Excel data
config='C:/Users/98485/Desktop/mmdetection-main/configs/retinanet/retinanet_r50_fpn_2x_coco_vitV2VPT.py' result_file='our.pkl' PR(config,result_file,'/result_excel')