Unverified 提交 d3dad422 authored 作者: Glenn Jocher's avatar Glenn Jocher 提交者: GitHub

Move generated *.json annotations into runs/test (#1209)

* Move generated *.json annotations into runs/test * list and string robust
上级 19c8b2c9
...@@ -222,11 +222,11 @@ def test(data, ...@@ -222,11 +222,11 @@ def test(data,
# Save JSON # Save JSON
if save_json and len(jdict): if save_json and len(jdict):
f = 'detections_val2017_%s_results.json' % \ w = Path(weights[0] if isinstance(weights, list) else weights).stem if weights is not None else '' # weights
(weights.split(os.sep)[-1].replace('.pt', '') if isinstance(weights, str) else '') # filename file = save_dir / f"detections_val2017_{w}_results.json" # predicted annotations file
print('\nCOCO mAP with pycocotools... saving %s...' % f) print('\nCOCO mAP with pycocotools... saving %s...' % file)
with open(f, 'w') as file: with open(file, 'w') as f:
json.dump(jdict, file) json.dump(jdict, f)
try: # https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocoEvalDemo.ipynb try: # https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocoEvalDemo.ipynb
from pycocotools.coco import COCO from pycocotools.coco import COCO
...@@ -234,7 +234,7 @@ def test(data, ...@@ -234,7 +234,7 @@ def test(data,
imgIds = [int(Path(x).stem) for x in dataloader.dataset.img_files] imgIds = [int(Path(x).stem) for x in dataloader.dataset.img_files]
cocoGt = COCO(glob.glob('../coco/annotations/instances_val*.json')[0]) # initialize COCO ground truth api cocoGt = COCO(glob.glob('../coco/annotations/instances_val*.json')[0]) # initialize COCO ground truth api
cocoDt = cocoGt.loadRes(f) # initialize COCO pred api cocoDt = cocoGt.loadRes(str(file)) # initialize COCO pred api
cocoEval = COCOeval(cocoGt, cocoDt, 'bbox') cocoEval = COCOeval(cocoGt, cocoDt, 'bbox')
cocoEval.params.imgIds = imgIds # image IDs to evaluate cocoEval.params.imgIds = imgIds # image IDs to evaluate
cocoEval.evaluate() cocoEval.evaluate()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论