Skip to content

目标检测数据集格式转换

网络上有很多关于数据集转换的脚本,一些自定义脚本可能面临着转换不规范,或只能针对一种数据集进行转换,这里使用 FiftyOne支持多种数据集相互转换的一个开源工具,它只需要简单的三步就能完成一个数据集的转换。

来自FiftyOne 官网的介绍

Improving data quality and understanding your model’s failure modes are the most impactful ways to boost the performance of your model.
提高数据质量和了解模型的失效模式是提高模型性能的最有效方法。

FiftyOne provides the building blocks for optimizing your dataset analysis pipeline. Use it to get hands-on with your data, including visualizing complex labels, evaluating your models, exploring scenarios of interest, identifying failure modes, finding annotation mistakes, and much more!
FiftyOne 提供用于优化数据集分析管道的构建块。使用它来动手处理您的数据,包括可视化复杂标签、评估模型、探索感兴趣的场景、识别故障模式、查找注释错误等等!

预备

在使用FiftyOne 之前,需要安装它

pip install fiftyone

开始

数据集类型

以下是fiftyone支持的数据集类型

'Dataset', 'UnlabeledDataset','UnlabeledImageDataset', 'UnlabeledVideoDataset','LabeledDataset', 'LabeledImageDataset', 'LabeledVideoDataset','ImageClassificationDataset', 'VideoClassificationDataset', 'ImageDetectionDataset', 'VideoDetectionDataset', 'ImageSegmentationDataset','ImageLabelsDataset','VideoLabelsDataset', 'GroupDataset', 'ImageDirectory','VideoDirectory','MediaDirectory', 'FiftyOneImageClassificationDataset', 'ImageClassificationDirectoryTree','VideoClassificationDirectoryTree', TFImageClassificationDataset', 'FiftyOneImageDetectionDataset', 'FiftyOneTemporalDetectionDataset','COCODetectionDataset', 'VOCDetectionDataset', 'KITTIDetectionDataset','OpenImagesV6Dataset','OpenImagesV7Dataset',
'FIWDataset','OpenLABELImageDataset','OpenLABELVideoDataset','YOLOv4Dataset', 'YOLOv5Dataset', 'TFObjectDetectionDataset', 'ImageSegmentationDirectory', 'CVATImageDataset', 'CVATVideoDataset', 'FiftyOneImageLabelsDataset', 'FiftyOneVideoLabelsDataset', 'BDDDataset', 'DICOMDataset', 'ActivityNetDataset',
'GeoJSONDataset', 'GeoTIFFDataset', 'CSVDataset', 'FiftyOneDataset', 'LegacyFiftyOneDataset'

转换脚本

如果你的数据集已经被单独被区分为train/test/val 部分,你需要单独处理每一部分

import fiftyone as fo  

data_img_path = ''  # 数据集图像的路径  
data_label_path = ''  # 数据集标签的路径,支持文件夹或单个文件  

# 参考上面的数据集类型 
# 直接用如 fo.types.YOLOv5Dataset 指定数据集类型

output_data_type = fo.types.COCODetectionDataset  # 保存数据集的类型  
data_type = fo.types.VOCDetectionDataset  # 数据集的类型  


data_img_path = r''  # 数据集图像的路径  
data_label_path = r''  # 数据集标签的路径,支持文件夹或单个文件  

output_dir = r'D:\workspace\out_put'   #输出路径

# 加载数据集  
dataset = fo.Dataset.from_dir(  
    data_path=data_img_path,  
    dataset_type=data_type,  
    labels_path=data_label_path,  
)  

# 导出数据集  
dataset.export(  
    dataset_type=output_data_type,  
    export_dir=output_dir,  
)

更多

如果需要查看FiftyOne 支持的所有数据类型,请查看fiftyone.types.dataset_types

如果你的VOC 标注格式为Annotation 为根标签,fiftyone 可能无法解析,需要做一下改动

https://github.com/voxel51/fiftyone/pull/3637/files