一、首先创建虚拟环境
二、安装
采用pip 安装:
pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
三、下载源码
然后采用下面的网址:https://github.com/philferriere/cocoapi下载源码进行解压。
然后切换到cocoapi\PythonAPI目录下运行以下指令:
# install pycocotools locally
python setup.py build_ext --inplace
# install pycocotools to the Python site-packages
python setup.py build_ext install
以上便实现pycocotools的安装。
接下来进行pycococreator的安装:
直接运行:pip install git+https://github.com/waspinator/pycococreator.git
最终实现pycococreator的安装。
安装完成后,大概率会出现下面的问题:
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
解决方案如下:
cd到虚拟环境中的pycococreatortools文件夹下,找到pycococreatortools.py代码
一般是在46行:改成下面这三行代码。
contours = measure.find_contours(padded_binary_mask, 0.5)
contours=sorted(contours,key=lambda x: len(x),reverse=True)[0:1]#可能返回多个mask
contours = np.subtract(contours, 1)
最终实现json格式的转换!!