glenn-jocher
commited on
Commit
•
d3dad42
1
Parent(s):
19c8b2c
Move generated *.json annotations into runs/test (#1209)
Browse files* Move generated *.json annotations into runs/test
* list and string robust
test.py
CHANGED
@@ -222,11 +222,11 @@ def test(data,
|
|
222 |
|
223 |
# Save JSON
|
224 |
if save_json and len(jdict):
|
225 |
-
|
226 |
-
|
227 |
-
print('\nCOCO mAP with pycocotools... saving %s...' %
|
228 |
-
with open(
|
229 |
-
json.dump(jdict,
|
230 |
|
231 |
try: # https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocoEvalDemo.ipynb
|
232 |
from pycocotools.coco import COCO
|
@@ -234,7 +234,7 @@ def test(data,
|
|
234 |
|
235 |
imgIds = [int(Path(x).stem) for x in dataloader.dataset.img_files]
|
236 |
cocoGt = COCO(glob.glob('../coco/annotations/instances_val*.json')[0]) # initialize COCO ground truth api
|
237 |
-
cocoDt = cocoGt.loadRes(
|
238 |
cocoEval = COCOeval(cocoGt, cocoDt, 'bbox')
|
239 |
cocoEval.params.imgIds = imgIds # image IDs to evaluate
|
240 |
cocoEval.evaluate()
|
|
|
222 |
|
223 |
# Save JSON
|
224 |
if save_json and len(jdict):
|
225 |
+
w = Path(weights[0] if isinstance(weights, list) else weights).stem if weights is not None else '' # weights
|
226 |
+
file = save_dir / f"detections_val2017_{w}_results.json" # predicted annotations file
|
227 |
+
print('\nCOCO mAP with pycocotools... saving %s...' % file)
|
228 |
+
with open(file, 'w') as f:
|
229 |
+
json.dump(jdict, f)
|
230 |
|
231 |
try: # https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocoEvalDemo.ipynb
|
232 |
from pycocotools.coco import COCO
|
|
|
234 |
|
235 |
imgIds = [int(Path(x).stem) for x in dataloader.dataset.img_files]
|
236 |
cocoGt = COCO(glob.glob('../coco/annotations/instances_val*.json')[0]) # initialize COCO ground truth api
|
237 |
+
cocoDt = cocoGt.loadRes(str(file)) # initialize COCO pred api
|
238 |
cocoEval = COCOeval(cocoGt, cocoDt, 'bbox')
|
239 |
cocoEval.params.imgIds = imgIds # image IDs to evaluate
|
240 |
cocoEval.evaluate()
|