name: fiftyone-dataset-inference description: 从媒体文件目录(图像、视频、点云)创建FiftyOne数据集,可选导入常见格式标签(COCO、YOLO、VOC),运行模型推理并存储预测结果。当用户需要将本地文件加载到FiftyOne、应用ML模型进行检测、分类或分割,或构建端到端推理管道时使用。
创建数据集并运行推理
概述
从本地目录创建FiftyOne数据集,导入标准格式标签,并运行模型推理生成预测结果。
在以下情况使用此技能:
- 从目录加载图像、视频或点云
- 导入带标签的数据集(COCO、YOLO、VOC、CVAT等)
- 在媒体文件上运行模型推理
- 构建端到端ML管道
前提条件
- 已安装并运行FiftyOne MCP服务器
@voxel51/io插件用于导入数据@voxel51/zoo插件用于模型推理@voxel51/utils插件用于数据集管理
关键指令
始终遵循以下规则:
1. 先探索目录
在导入前扫描用户目录以检测媒体类型和标签格式。
2. 与用户确认
在创建数据集或运行推理前,展示发现并获取确认。
3. 操作前设置上下文
set_context(dataset_name="my-dataset")
4. 为推理启动应用
launch_app(dataset_name="my-dataset")
5. 用户指定字段名称
始终询问用户:
- 数据集名称
- 预测标签字段
6. 完成后关闭应用
close_app()
工作流程
步骤1:探索目录
使用Bash扫描用户目录:
ls -la /path/to/directory
find /path/to/directory -type f | head -20
识别媒体文件和标签文件。查看支持的数据集类型部分了解格式检测。
步骤2:向用户展示发现
在创建数据集前,与用户确认:
我在/path/to/directory中发现以下内容:
- 150个图像文件(.jpg、.png)
- 标签:COCO格式(annotations.json)
建议的数据集名称:"my-dataset"
标签字段:"ground_truth"
是否使用这些设置继续?
步骤3:创建数据集
execute_operator(
operator_uri="@voxel51/utils/create_dataset",
params={
"name": "my-dataset",
"persistent": true
}
)
步骤4:设置上下文
在导入前为新创建的数据集设置上下文:
set_context(dataset_name="my-dataset")
步骤5:导入样本
仅媒体(无标签):
execute_operator(
operator_uri="@voxel51/io/import_samples",
params={
"import_type": "MEDIA_ONLY",
"style": "DIRECTORY",
"directory": {"absolute_path": "/path/to/images"}
}
)
带标签的媒体:
execute_operator(
operator_uri="@voxel51/io/import_samples",
params={
"import_type": "MEDIA_AND_LABELS",
"dataset_type": "COCO",
"data_path": {"absolute_path": "/path/to/images"},
"labels_path": {"absolute_path": "/path/to/annotations.json"},
"label_field": "ground_truth"
}
)
步骤6:验证导入
通过比较源数据验证样本是否正确导入:
load_dataset(name="my-dataset")
将num_samples与步骤1中的文件计数进行比较。向用户报告任何差异。
步骤7:启动应用
launch_app(dataset_name="my-dataset")
步骤8:应用模型推理
询问用户模型名称和预测标签字段。
execute_operator(
operator_uri="@voxel51/zoo/apply_zoo_model",
params={
"tab": "BUILTIN",
"model": "yolov8n-coco-torch",
"label_field": "predictions"
}
)
步骤9:查看结果
set_view(exists=["predictions"])
步骤10:清理
close_app()
支持的媒体类型
| 扩展名 | 媒体类型 |
|---|---|
.jpg, .jpeg, .png, .gif, .bmp, .webp |
图像 |
.mp4, .avi, .mov, .mkv, .webm |
视频 |
.pcd |
点云 |
.fo3d |
3D |
支持的数据集类型
| 值 | 文件模式 | 标签类型 |
|---|---|---|
图像分类目录树 |
每个类别的文件夹 | 分类 |
视频分类目录树 |
每个类别的文件夹 | 分类 |
COCO |
*.json |
检测、分割、关键点 |
VOC |
每个图像*.xml |
检测 |
KITTI |
每个图像*.txt |
检测 |
YOLOv4 |
*.txt + classes.txt |
检测 |
YOLOv5 |
data.yaml + labels/*.txt |
检测 |
CVAT图像 |
单个*.xml文件 |
分类、检测、多边形、关键点 |
CVAT视频 |
XML目录 | 帧标签 |
TF图像分类 |
TFRecords | 分类 |
TF目标检测 |
TFRecords | 检测 |
常用Zoo模型
用于apply_zoo_model的流行模型。某些模型需要额外的包 - 如果模型因依赖错误失败,响应包含install_command。为用户提供运行安装命令的选项。
检测(仅PyTorch):
faster-rcnn-resnet50-fpn-coco-torch- Faster R-CNN(无需额外依赖)retinanet-resnet50-fpn-coco-torch- RetinaNet(无需额外依赖)
检测(需要ultralytics):
yolov8n-coco-torch- YOLOv8 nano(快速)yolov8s-coco-torch- YOLOv8 smallyolov8m-coco-torch- YOLOv8 medium
分类:
resnet50-imagenet-torch- ResNet-50mobilenet-v2-imagenet-torch- MobileNet v2
分割:
sam-vit-base-hq-torch- Segment Anythingdeeplabv3-resnet101-coco-torch- DeepLabV3
嵌入:
clip-vit-base32-torch- CLIP嵌入dinov2-vits14-torch- DINOv2嵌入
常见用例
用例1:加载图像并运行检测
execute_operator(
operator_uri="@voxel51/utils/create_dataset",
params={"name": "my-images", "persistent": true}
)
set_context(dataset_name="my-images")
execute_operator(
operator_uri="@voxel51/io/import_samples",
params={
"import_type": "MEDIA_ONLY",
"style": "DIRECTORY",
"directory": {"absolute_path": "/path/to/images"}
}
)
load_dataset(name="my-images") # 验证导入
launch_app(dataset_name="my-images")
execute_operator(
operator_uri="@voxel51/zoo/apply_zoo_model",
params={
"tab": "BUILTIN",
"model": "faster-rcnn-resnet50-fpn-coco-torch",
"label_field": "predictions"
}
)
set_view(exists=["predictions"])
用例2:导入COCO数据集并添加预测
execute_operator(
operator_uri="@voxel51/utils/create_dataset",
params={"name": "coco-dataset", "persistent": true}
)
set_context(dataset_name="coco-dataset")
execute_operator(
operator_uri="@voxel51/io/import_samples",
params={
"import_type": "MEDIA_AND_LABELS",
"dataset_type": "COCO",
"data_path": {"absolute_path": "/path/to/images"},
"labels_path": {"absolute_path": "/path/to/annotations.json"},
"label_field": "ground_truth"
}
)
load_dataset(name="coco-dataset") # 验证导入
launch_app(dataset_name="coco-dataset")
execute_operator(
operator_uri="@voxel51/zoo/apply_zoo_model",
params={
"tab": "BUILTIN",
"model": "faster-rcnn-resnet50-fpn-coco-torch",
"label_field": "predictions"
}
)
set_view(exists=["predictions"])
用例3:导入YOLO数据集
execute_operator(
operator_uri="@voxel51/utils/create_dataset",
params={"name": "yolo-dataset", "persistent": true}
)
set_context(dataset_name="yolo-dataset")
execute_operator(
operator_uri="@voxel51/io/import_samples",
params={
"import_type": "MEDIA_AND_LABELS",
"dataset_type": "YOLOv5",
"dataset_dir": {"absolute_path": "/path/to/yolo/dataset"},
"label_field": "ground_truth"
}
)
load_dataset(name="yolo-dataset")
launch_app(dataset_name="yolo-dataset")
用例4:使用目录树进行分类
对于如下文件夹结构:
/dataset/
/cats/
cat1.jpg
cat2.jpg
/dogs/
dog1.jpg
dog2.jpg
execute_operator(
operator_uri="@voxel51/utils/create_dataset",
params={"name": "classification-dataset", "persistent": true}
)
set_context(dataset_name="classification-dataset")
execute_operator(
operator_uri="@voxel51/io/import_samples",
params={
"import_type": "MEDIA_AND_LABELS",
"dataset_type": "Image Classification Directory Tree",
"dataset_dir": {"absolute_path": "/path/to/dataset"},
"label_field": "ground_truth"
}
)
load_dataset(name="classification-dataset")
launch_app(dataset_name="classification-dataset")
故障排除
错误:“数据集已存在”
- 使用不同的数据集名称
- 或先使用
@voxel51/utils/delete_dataset删除现有数据集
错误:“未找到样本”
- 验证目录路径是否正确
- 检查文件扩展名是否受支持
- 确保文件不在嵌套子目录中(如果需要,使用
recursive=true)
错误:“未找到标签路径”
- 验证标签文件/目录是否存在
- 检查路径是否为绝对路径,而非相对路径
错误:“未找到模型”
- 检查模型名称拼写
- 验证模型是否存在于FiftyOne Zoo中
- 使用
list_operators()和get_operator_schema()发现可用模型
错误:“缺少依赖”(例如torch、ultralytics)
- MCP服务器检测到缺少依赖
- 响应包含
missing_package和install_command - 安装所需包并重启MCP服务器
推理速度慢
- 使用较小的模型变体(例如,使用
yolov8n而非yolov8x) - 减小批处理大小
- 对于大型数据集考虑委托执行
最佳实践
- 导入前先探索 - 始终先扫描目录以了解数据
- 与用户确认 - 在创建数据集前展示发现并获取确认
- 使用描述性名称 - 数据集名称和标签字段应具有意义
- 分离真实标签与预测 - 使用不同的字段名称(例如
ground_truth与predictions) - 从快速模型开始 - 首先使用轻量级模型,然后根据需要升级
- 检查操作符模式 - 使用
get_operator_schema()发现可用参数
资源
许可证
版权所有 2017-2025, Voxel51, Inc. Apache 2.0许可证