首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何从COCO数据集中过滤类?

如何从COCO数据集中过滤类?
EN

Stack Overflow用户
提问于 2019-03-25 19:03:21
回答 3查看 6.1K关注 0票数 3

我想用COCO数据集训练一个yolo模型。有80多个类,如何过滤?我只需要类person和car。

EN

回答 3

Stack Overflow用户

发布于 2020-05-06 15:37:25

您可以使用PyCoco API来处理COCO数据集。有了这个库,从数据集中过滤类就很容易了!

代码语言:javascript
复制
# Define the classes (out of the 81) which you want to see. Others will not be shown.
filterClasses = ['person', 'dog']

# Fetch class IDs only corresponding to the filterClasses
catIds = coco.getCatIds(catNms=filterClasses) 
# Get all images containing the above Category IDs
imgIds = coco.getImgIds(catIds=catIds)
print("Number of images containing all the  classes:", len(imgIds))

# load and display a random image
img = coco.loadImgs(imgIds[np.random.randint(0,len(imgIds))])[0]
I = io.imread('{}/images/{}/{}'.format(dataDir,dataType,img['file_name']))/255.0

我最近在exploring and manipulating the COCO dataset上写了一整篇文章。一定要看一看。

票数 1
EN

Stack Overflow用户

发布于 2020-08-05 19:05:13

在不重新训练Coco数据集上的模型的情况下过滤类的唯一方法是检查检测输出,以避免为无用的类绘制一个框,但模型将继续在后台检测所有类。

票数 0
EN

Stack Overflow用户

发布于 2021-10-19 14:59:24

如今,最简单的方法是使用COCO网站上推荐给download, visualize, and evaluate the dataset including any subset of classesfiftyone

代码语言:javascript
复制
import fiftyone as fo
import fiftyone.zoo as foz

#
# Only the required images will be downloaded (if necessary).
# By default, only detections are loaded
#

dataset = foz.load_zoo_dataset(
    "coco-2017",
    splits=["validation","train"],
    classes=["person", "car"],
    # max_samples=50,
)

# Visualize the dataset in the FiftyOne App
session = fo.launch_app(dataset)

您还可以使用它直接对数据集执行convert the dataset to YOLO formattrain models操作。

代码语言:javascript
复制
# Export the dataset in YOLO format
export_dir = "/path/for/yolov5-dataset"
label_field = "ground_truth"

dataset.export(
    export_dir=export_dir,
    dataset_type=fo.types.YOLOv5Dataset,
    label_field=label_field,
)

要安装:

代码语言:javascript
复制
pip install fiftyone
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55336355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档