something wrong with evaluating
yihui8776 opened this issue · 2 comments
use the coco dataset and run :
python main.py --eval --coco_path coco --resume AnchorDETR_r50_c5.pth
got :
Traceback (most recent call last):
File "main.py", line 330, in
main(args)
File "main.py", line 267, in main
test_stats, coco_evaluator = evaluate(model, criterion, postprocessors,
File "/opt/conda/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 26, in decorate_context
return func(*args, **kwargs)
File "/workspace/engine.py", line 131, in evaluate
coco_evaluator.update(res)
File "/workspace/datasets/coco_eval.py", line 38, in update
coco_dt = COCO.loadRes(self.coco_gt, results) if results else COCO()
File "/opt/conda/lib/python3.8/site-packages/pycocotools/coco.py", line 314, in loadRes
res.dataset['images'] = [img for img in self.dataset['images']]
AttributeError: 'NoneType' object has no attribute 'dataset'
I can not reproduce this error. It may be related to the version of pycocotools.
In pycocotools, the res
should not be a NoneType.
def loadRes(self, resFile):
"""
Load result file and return a result api object.
:param resFile (str) : file name of result file
:return: res (obj) : result api object
"""
res = COCO()
res.dataset['images'] = [img for img in self.dataset['images']]
class COCO:
def __init__(self, annotation_file=None):
"""
Constructor of Microsoft COCO helper class for reading and visualizing annotations.
:param annotation_file (str): location of annotation file
:param image_folder (str): location to the folder that hosts images.
:return:
"""
# load dataset
self.dataset,self.anns,self.cats,self.imgs = dict(),dict(),dict(),dict()
self.imgToAnns, self.catToImgs = defaultdict(list), defaultdict(list)
if not annotation_file == None:
print('loading annotations into memory...')
tic = time.time()
dataset = json.load(open(annotation_file, 'r'))
assert type(dataset)==dict, 'annotation file format {} not supported'.format(type(dataset))
print('Done (t={:0.2f}s)'.format(time.time()- tic))
self.dataset = dataset
self.createIndex()
You can try pip install pycocotools==2.0.1
This issue is not active for a long time and it will be closed in 5 days. Feel free to re-open it if you have further concerns.