COCO API(pycocotools)普通版和高版本2.0.1安装
安装前请确保已安装cython
安装命令
pip install cython
1. Linux环境
git clone https://github.com/cocodataset/cocoapi.git
cd cocoapi/PythonAPI
python setup.py build_ext --inplace
python setup.py build_ext install
2. Windows环境
Windows下直接使用pip install pycocotools会报错
解决方案1:
采用github修改版的COCO API
安装方法:
pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
缺点是该方法只能安装2.0版本的,有些开源算法(PySlowFast)可能要求其他高版本的,例如2.0.1。安装方法见解决方案2。
解决方案2:
思路:自己修改2.0.1版本的pycocotools源码,再编译安装。
方案2中涉及的VS2015编译工具以及高版本的COCO API代码,如果大家下载有困难,可以关注微信公众号“CV实战”,回复“coco”,即可获得下载链接。
STEP-1:安装VS2015编译工具
VS2015编译工具可到 https://go.microsoft.com/fwlink/?LinkId=691126 下载visualcppbuildtools_full.exe来安装(以管理员身份)。
STEP-2:下载高版本的COCO API代码
Windows CMD命令窗中输入
pip install pycocotools==2.0.1
命令窗中会显示pip的下载地址
解压下载后的压缩包,假设文件根目录为pycocotools-2.0.1(有setup.py的目录),修改两个文件即可:
(1)修改setup.py
注释掉原来的
extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99'],
修改为
extra_compile_args=[],
如图中蓝色框所示。
(2)修改pycocotools-2.0.1\pycocotools\coco.py
注释掉
if type(resFile) == str or (PYTHON_VERSION == 2 and type(resFile) == unicode):
加入
# Check result type in a way compatible with Python 2 and 3.
if PYTHON_VERSION == 2:
is_string = isinstance(resFile, basestring) # Python 2
elif PYTHON_VERSION == 3:
is_string = isinstance(resFile, str) # Python 3
if is_string:
VS编译工具安装后,在pycocotools-2.0.1(有setup.py的文件夹)目录执行
python setup.py install
即可完成安装。
欢迎关注微信公众号“CV实战”,回复“coco”,即可获得软件和代码下载链接。