This commit is contained in:
Glenn Jocher 2019-11-30 17:47:33 -08:00
parent a699c901d3
commit 0f6954fa04
1 changed files with 20 additions and 19 deletions

13
test.py
View File

@ -167,13 +167,15 @@ def test(cfg,
# Save JSON # Save JSON
if save_json and map and len(jdict): if save_json and map and len(jdict):
try:
imgIds = [int(Path(x).stem.split('_')[-1]) for x in dataset.img_files] imgIds = [int(Path(x).stem.split('_')[-1]) for x in dataset.img_files]
with open('results.json', 'w') as file: with open('results.json', 'w') as file:
json.dump(jdict, file) json.dump(jdict, file)
try:
from pycocotools.coco import COCO from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval from pycocotools.cocoeval import COCOeval
except:
print('WARNING: missing pycocotools package, can not compute official COCO mAP. See requirements.txt.')
# https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocoEvalDemo.ipynb # https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocoEvalDemo.ipynb
cocoGt = COCO('../coco/annotations/instances_val2014.json') # initialize COCO ground truth api cocoGt = COCO('../coco/annotations/instances_val2014.json') # initialize COCO ground truth api
@ -185,8 +187,6 @@ def test(cfg,
cocoEval.accumulate() cocoEval.accumulate()
cocoEval.summarize() cocoEval.summarize()
map = cocoEval.stats[1] # update mAP to pycocotools mAP map = cocoEval.stats[1] # update mAP to pycocotools mAP
except:
print('WARNING: missing dependency pycocotools from requirements.txt. Can not compute official COCO mAP.')
# Return results # Return results
maps = np.zeros(nc) + map maps = np.zeros(nc) + map
@ -198,16 +198,17 @@ def test(cfg,
if __name__ == '__main__': if __name__ == '__main__':
parser = argparse.ArgumentParser(prog='test.py') parser = argparse.ArgumentParser(prog='test.py')
parser.add_argument('--cfg', type=str, default='cfg/yolov3-spp.cfg', help='cfg file path') parser.add_argument('--cfg', type=str, default='cfg/yolov3-spp.cfg', help='cfg file path')
parser.add_argument('--data', type=str, default='data/coco.data', help='coco.data file path') parser.add_argument('--data', type=str, default='data/coco_16img.data', help='coco.data file path')
parser.add_argument('--weights', type=str, default='weights/yolov3-spp.weights', help='path to weights file') parser.add_argument('--weights', type=str, default='weights/yolov3-spp.weights', help='path to weights file')
parser.add_argument('--batch-size', type=int, default=16, help='size of each image batch') parser.add_argument('--batch-size', type=int, default=4, help='size of each image batch')
parser.add_argument('--img-size', type=int, default=416, help='inference size (pixels)') parser.add_argument('--img-size', type=int, default=800, help='inference size (pixels)')
parser.add_argument('--iou-thres', type=float, default=0.5, help='iou threshold required to qualify as detected') parser.add_argument('--iou-thres', type=float, default=0.5, help='iou threshold required to qualify as detected')
parser.add_argument('--conf-thres', type=float, default=0.001, help='object confidence threshold') parser.add_argument('--conf-thres', type=float, default=0.001, help='object confidence threshold')
parser.add_argument('--nms-thres', type=float, default=0.5, help='iou threshold for non-maximum suppression') parser.add_argument('--nms-thres', type=float, default=0.5, help='iou threshold for non-maximum suppression')
parser.add_argument('--save-json', action='store_true', help='save a cocoapi-compatible JSON results file') parser.add_argument('--save-json', action='store_true', help='save a cocoapi-compatible JSON results file')
parser.add_argument('--device', default='', help='device id (i.e. 0 or 0,1) or cpu') parser.add_argument('--device', default='', help='device id (i.e. 0 or 0,1) or cpu')
opt = parser.parse_args() opt = parser.parse_args()
opt.save_json = True
print(opt) print(opt)
with torch.no_grad(): with torch.no_grad():