我的背景是
python 3.9 numpy 1.21.0 cuda 10.2
现在我在接收两条错误消息时遇到问题
一是: 错误:Pycools无法运行:“numpy.float64”对象不能解释为整数
二是: 错误:pycocotools无法运行:numpy.ndarray大小已更改,可能表示二进制不兼容。C头预期为88,PyObject预期为80
情况是,我寻找封闭式问题并找到了解决方案。 对于第一个错误,对numpy进行降级是许多人的解决方案。(减至1.16.5)
对于第二个错误,升级numpy是许多人的解决方案。(高达1.21.0)
所以如果我升级numpy,第一个问题出现,降级,第二个问题出现。相反的解决方案
我一直试图在不降低numpy等级的情况下解决第一个错误,但效果不太好
这是下面的问题代码
# 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 (mAP@0.5:0.95, mAP@0.5)
except Exception as e:
print('ERROR: pycocotools unable to run: %s' % e)
下面是每个cocoGt和cocoDt的值和类型
<;位于0x000002351F4CE6A0处的pycocotools.coco.coco对象>; <;“椰子醇.椰子油.椰子油”类>
<;位于0x000002351F4E58E0处的pycotools.coco.coco对象>; <;“椰子醇.椰子油.椰子油”类>
cocoEval=cocoEval(cocoGt,cocoDt,'bbox') 我认为这部分是代码中最可疑的部分 我试图用int覆盖值(cocoGt,cocoDt),但显示错误时无效: int()参数必须是字符串、类似字节的对象或数字,而不是“COCO”
下面是cocoeval.py的一部分,其中包含定义cocoeval=cocoeval(cocoGt,cocoDt,'bbox'),以防它可能是有用的信息
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())
非常感谢您抽出时间
目前没有回答
相关问题 更多 >
编程相关推荐