my setting is
python 3.9 numpy 1.21.0 cuda 10.2
right now i'm having a problem receiving two error messages.
one is : ERROR: pycocotools unable to run: 'numpy.float64' object cannot be interpreted as an integer
second is : ERROR: pycocotools unable to run: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject
situation is, i looked for closed questions and found the solution. For first error, downgrading numpy was a solution for many people. (down to 1.16.5)
For second error, upgrading numpy was a solution for many people. (up to 1.21.0)
So if i upgrade numpy, first problem occurs, downgrade, second problem occurs. Opposite solutions.
I've been trying to solve the first error without downgrading my numpy, but it haven't gone very well.
This is the problem code below.
# Save JSON
if save_json and len(jdict):
f = 'detections_val2017_%s_results.json' % \
(weights.split(os.sep)[-1].replace('.pt', '') if isinstance(weights, str) else '') # filename
print('\nCOCO mAP with pycocotools... saving %s...' % f)
with open(f, 'w') as file:
json.dump(jdict, file)
try: # https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocoEvalDemo.ipynb
# THIS IS WHERE THE CODE STOPS WHEN SECOND ERROR OCCURS
from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval
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
cocoDt = cocoGt.loadRes(f) # initialize COCO pred api
#THIS IS WHERE THE CODE STOPS WHEN FIRST ERROR OCCURS
cocoEval = COCOeval(cocoGt, cocoDt, 'bbox')
cocoEval.params.imgIds = imgIds # image IDs to evaluate
cocoEval.evaluate()
cocoEval.accumulate()
cocoEval.summarize()
map, map50 = cocoEval.stats[:2] # update results ([email protected]:0.95, [email protected])
except Exception as e:
print('ERROR: pycocotools unable to run: %s' % e)
Below is the value and type of each cocoGt, and cocoDt
<pycocotools.coco.COCO object at 0x000002351F4CE6A0> <class 'pycocotools.coco.COCO'>
<pycocotools.coco.COCO object at 0x000002351F4E58E0> <class 'pycocotools.coco.COCO'>
cocoEval = COCOeval(cocoGt, cocoDt, 'bbox') I think this part is the most suspicious part in the code I tried to cover the values (cocoGt, cocoDt) with int but it didn't work displaying an error : int() argument must be a string, a bytes-like object or a number, not 'COCO'.
below is a part of cocoeval.py which contains the def of cocoEval = COCOeval(cocoGt, cocoDt, 'bbox') in case it might be an useful information.
def __init__(self, cocoGt=None, cocoDt=None, iouType='segm'):
'''
Initialize CocoEval using coco APIs for gt and dt
:param cocoGt: coco object with ground truth annotations
:param cocoDt: coco object with detection results
:return: None
'''
if not iouType:
print('iouType not specified. use default iouType segm')
self.cocoGt = cocoGt # ground truth COCO API
self.cocoDt = cocoDt # detections COCO API
self.params = {} # evaluation parameters
self.evalImgs = defaultdict(list) # per-image per-category evaluation results [KxAxI] elements
self.eval = {} # accumulated evaluation results
self._gts = defaultdict(list) # gt for evaluation
self._dts = defaultdict(list) # dt for evaluation
self.params = Params(iouType=iouType) # parameters
self._paramsEval = {} # parameters for evaluation
self.stats = [] # result summarization
self.ious = {} # ious between all gts and dts
if not cocoGt is None:
self.params.imgIds = sorted(cocoGt.getImgIds())
self.params.catIds = sorted(cocoGt.getCatIds())
Thank you very much for your time