参考博客:https://blog.csdn.net/ccbrid/article/details/79368639
在linux上

1.git clone cocoapi

github:

git clone https://github.com/pdollar/coco.git

gitee镜像(我用的这个):

git clone https://gitcode.net/mirrors/cocodataset/cocoapi.git

2.进入文件夹

cd coco

或者是

cd cocoapi

总之进入刚刚clone下来的文件夹

3.放入image和annotation

mkdir images
mkdir annotations

分别放官网https://cocodataset.org/#download下载的image和annotation文件夹(里面包含json),这里我只放了annotation就可以跑api里的demo了
我下载的数据如下:
在这里插入图片描述
解压后长这样:
在这里插入图片描述
我需要用的是captions

4.安装pythoncocoapi接口

cd PythonAPI
make 

这里make报错

error: pycocotools/_mask.c: No such file or directory

解决参考:https://blog.csdn.net/ITtjt/article/details/122062849
解决方案:

pip install Cython
pip install pycocotools
将makefile文件中的python换成python3

5.在python中import pycocotools不报错,即安装成功

6.使用clone内容内pythonapi中的demo代码,就能用caption了

在这里插入图片描述

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐