linux安装 pycocotools_Windows下安装pycocotools

安装步骤:

1.

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

pip install cython

2.

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

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

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

...

C:\D disk\Anaconda\Anaconda3\envs\pytorch\lib\site-packages\pycocotools\cocoeval.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 disk\Anaconda\Anaconda3\envs\pytorch\lib\site-packages\numpy\core\function_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 cannot be safely interpreted as an integer.

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:\Users\username> conda activate pytorch

(pytorch) PS C:\Users\username> cd "改版pycocotools解压路径"

(pytorch) PS 改版pycocotools解压路径> python setup.py install

4.

改写版本的pycocotools看起来是不会再更新了,因此能安装原版pycocotools的话最好。我发现了一些windows系统安装原版pycocotools的教程,但还没有去试过:

成功解决ERROR: FAILED BUILDING WHEEL FOR PYCOCOTOOLS

Windows 10 编译 Pycocotools 踩坑记

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值