COCO-style 数据集的准备与训练

COCO-style 标注格式

json 标注文件的格式

{
    "info": info,
    "licenses": [license],
    "images": [image],
    "annotations": [annotation],
    "categories": [category]
}

annotations

在这里插入图片描述

annotation{
    "id": int, # 对象ID,因为每一个图像有不止一个对象,所以要对每一个对象编号(每个对象的ID是唯一的)
    "image_id": int,# 对应的图片ID(与images中的ID对应)
    "category_id": int,# 类别ID(与categories中的ID对应)
    "segmentation": RLE or [polygon],# 对象的边界点(边界多边形,此时iscrowd=0)。
    #segmentation格式取决于这个实例是一个单个的对象(即iscrowd=0,将使用polygons格式)还是一组对象(即iscrowd=1,将使用RLE格式)
    "area": float,# 区域面积
    "bbox": [x,y,width,height], # 定位边框 [x,y,w,h]
    "iscrowd": 0 or 1 #见下
}

categories

在这里插入图片描述

{
	"supercategory": str,# 主类别
    "id": int,# 类对应的id (0 默认为背景)
    "name": str # 子类别
}

COCO数据集可视化

from __future__ import print_function
from pycocotools.coco import COCO
import os, sys, zipfile
import urllib.request
import shutil
import numpy as np
import skimage.io as io
import matplotlib.pyplot as plt
import pylab
pylab.rcParams['figure.figsize'] = (8.0, 10.0)
annFile='/media/fire/d/share_data/datasets/coco/annotations/person_keypoints_val2017.json'
coco=COCO(annFile) # display COCO categories and supercategories
cats = coco.loadCats(coco.getCatIds())
nms=[cat['name'] for cat in cats]
print('COCO categories: \n{}\n'.format(' '.join(nms)))
nms = set([cat['supercategory'] for cat in cats])
print('COCO supercategories: \n{}'.format(' '.join(nms)))
# imgIds = coco.getImgIds(imgIds = [324158])
imgIds = coco.getImgIds()
img = coco.loadImgs(imgIds[0])[0]
dataDir = '/media/fire/d/share_data/datasets/coco'
dataType = 'val2017'
I = io.imread('%s/%s/%s'%(dataDir,dataType,img['file_name']))
#plt.axis('off')
plt.imshow(I)
plt.show()
训练自己的COCO数据集使用Yolox,首先需要创建一个Yolox的conda环境,可以使用以下命令: ``` conda create -n yolox python=3.8 ``` 然后激活这个环境: ``` conda activate yolox ``` 接下来,在Yolox的项目文件夹中安装所需的依赖项: ``` cd yolox pip install -r requirements.txt python setup.py develop ``` 为了使用COCO数据集,需要安装pycocotools,可以按照以下步骤进行: ``` git clone https://github.com/cocodataset/cocoapi cd cocoapi/PythonAPI/ python setup.py build_ext install ``` 接下来,你可以下载Yolox的预训练模型,并将其放置在项目文件夹中。然后,你可以使用以下命令运行测试演示: ``` python tools/demo.py image -f exps/default/yolox_s.py -c yolox_s.pth --path assets/dog.jpg --conf 0.25 --nms 0.45 --tsize 640 --save_result --device gpu ``` 这些命令将加载预训练的Yolox模型,并根据提供的参数对一张图片进行目标检测,结果将保存在指定的路径中。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [YOLOX训练自己的数据集coco格式)](https://blog.csdn.net/weixin_43804047/article/details/120433479)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [YOLOX训练(实现)(COCOcoco数据集)最新最全教程](https://blog.csdn.net/java_pythons/article/details/120513863)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Gallant Hu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值