在 pytorch 中将 pycocotools 用于 Scaled Yolo v4 的问题:numpy 版本困境

问题描述

我的设置是

蟒蛇 3.9 麻木 1.21.0 CUDA 10.2

现在我在收到两条错误消息时遇到问题。

一个是: 错误:pycocotools 无法运行:'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 ([email protected]:0.95,[email protected])
        except Exception as e:
            print('ERROR: pycocotools unable to run: %s' % e)

下面是每个cocoGt和cocoDt的值和类型

cocoEval = COCOeval(cocoGt,'bbox') 我认为这部分是代码中最可疑的部分 我试图用 int 覆盖值(cocoGt,cocoDt),但它没有工作,显示错误: int() 参数必须是字符串、类似字节的对象或数字,而不是 'COCO'

下面是 cocoeval.py 的一部分,其中包含 cocoEval = COCOeval(cocoGt,'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())

非常感谢您的时间

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)