zoukankan      html  css  js  c++  java
  • Windows下安装pycocotools

    参考:
    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-packages
    umpycorefunction_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 踩坑记

  • 相关阅读:
    预热buffer pool
    MySQL · 性能优化· InnoDB buffer pool flush策略漫谈
    事务并发控制
    LOAD DATA INFILE – performance case study
    隐式锁
    percona-xtrabackup安装
    mysql 表空间及索引的查看方法
    mysql用户权限
    mysql修改数据库名
    MySQL对innodb某一个表进行移动
  • 原文地址:https://www.cnblogs.com/wildgoose/p/12905200.html
Copyright © 2011-2022 走看看