我想用COCO数据集训练一个yolo模型。有80多个类,如何过滤?我只需要类person和car。
发布于 2020-05-06 15:37:25
您可以使用PyCoco API来处理COCO数据集。有了这个库,从数据集中过滤类就很容易了!
# 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上写了一整篇文章。一定要看一看。
发布于 2020-08-05 19:05:13
在不重新训练Coco数据集上的模型的情况下过滤类的唯一方法是检查检测输出,以避免为无用的类绘制一个框,但模型将继续在后台检测所有类。
发布于 2021-10-19 14:59:24
如今,最简单的方法是使用COCO网站上推荐给download, visualize, and evaluate the dataset including any subset of classes的fiftyone
。
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 format和train models操作。
# 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,
)
要安装:
pip install fiftyone
https://stackoverflow.com/questions/55336355
复制相似问题