参考:
Windows下安装 pycocotools

原版的pycocotools(不支持windows)的Github项目地址:https://github.com/cocodataset/cocoapi
支持windows的改写版本的Github项目地址:https://github.com/philferriere/cocoapi

安装步骤:

1.

安装pycocotools首先需要安装Cython,在相应的conda环境下输入:

pip install cython

2.

由于支持windows的改写pycocotools太久没有更新,直接输入

pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI

进行安装的话会在运行时报错:

...
C:D diskAnacondaAnaconda3envspytorchlibsite-packagespycocotoolscocoeval.py in setDetParams(self)
    505         self.catIds = []
    506         # np.arange causes trouble.  the data point on arange is slightly larger than the true value
--> 507         self.iouThrs = np.linspace(.5, 0.95, np.round((0.95 - .5) / .05) + 1, endpoint=True)
    508         self.recThrs = np.linspace(.0, 1.00, np.round((1.00 - .0) / .01) + 1, endpoint=True)
    509         self.maxDets = [1, 10, 100]

<__array_function__ internals> in linspace(*args, **kwargs)

C:D diskAnacondaAnaconda3envspytorchlibsite-packagesnumpycorefunction_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
    119         raise TypeError(
    120             "object of type {} cannot be safely interpreted as an integer."
--> 121                 .format(type(num)))
    122 
    123     if num < 0:

TypeError: object of type <class 'numpy.float64'> cannot be safely interpreted as an integer.

因此我们需要将下载 https://github.com/philferriere/cocoapi 的源码,并在修改后使用

python setup.py install

来进行安装

3.

报错指向pycocotools的cocoeval.py文件的507行,在对比了原版pycocotools的cocoeval.py文件改写版本的cocoeval.py文件后我们可以发现:
原版的cocoeval.py文件的506、507行分别为:

self.iouThrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True)
self.recThrs = np.linspace(.0, 1.00, int(np.round((1.00 - .0) / .01)) + 1, endpoint=True)

517、518行分别为:

self.iouThrs = np.linspace(.5, 0.95, int(np.round((0.95 - .5) / .05)) + 1, endpoint=True)
self.recThrs = np.linspace(.0, 1.00, int(np.round((1.00 - .0) / .01)) + 1, endpoint=True)

而改写版本的cocoeval.py文件的507、508行分别为:

self.iouThrs = np.linspace(.5, 0.95, np.round((0.95 - .5) / .05) + 1, endpoint=True)
self.recThrs = np.linspace(.0, 1.00, np.round((1.00 - .0) / .01) + 1, endpoint=True)

518、519行分别为:

self.iouThrs = np.linspace(.5, 0.95, np.round((0.95 - .5) / .05) + 1, endpoint=True)
self.recThrs = np.linspace(.0, 1.00, np.round((1.00 - .0) / .01) + 1, endpoint=True)

即原版比改写版本多了int()。

我们在看原版pycocotools的commits记录的时候也能发现,原版pycocotools在2019年12月26号修复了这个问题:

因此我们只需要将Github上改写版本的pycocotools的源码下载下来,解压后修改cocoeval.py文件的上述内容使之与原版一致,再使用python setup.py install安装即可:

(base) PS C:Usersusername> conda activate pytorch
(pytorch) PS C:Usersusername> cd "改版pycocotools解压路径"
(pytorch) PS 改版pycocotools解压路径> python setup.py install

4.

改写版本的pycocotools看起来是不会再更新了,因此能安装原版pycocotools的话最好。我发现了一些windows系统安装原版pycocotools的教程,但还没有去试过:
成功解决ERROR: FAILED BUILDING WHEEL FOR PYCOCOTOOLS
Windows 10 编译 Pycocotools 踩坑记

内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/wildgoose/p/12905200.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!