笔记本|推理| Autodistill |收集
Autodistill使用大型,较慢的基础模型来训练小型,更快的监督模型。使用autodistill ,您可以从未标记的图像到在边缘运行的自定义模型的推断,而没有人为干预。
提示
您可以在自己的硬件上使用Autodistill,也可以使用Roboflow托管版本的Autodistill版本在云中标记图像。
当前, autodistill支持视觉任务,例如对象检测和实例细分,但是将来可以将其扩展到支持语言(和其他)模型。
| 教程 | 文档 | 支持的模型 | 贡献 |
|---|
这是对目标模型在使用AutoDistill进行自动标记数据集进行培训后的目标模型的示例预测(有关完整的演练):
要使用autodistill ,您将未标记的数据输入到基本模型中,该模型使用本体来标记用于训练目标模型的数据集,该数据集输出蒸馏模型以微调执行特定任务。
Autodistill定义了几个基本原始图:
autodistill管道的每个组件(基本模型,本体和目标模型)的任务必须匹配以使其彼此兼容。目前通过detection任务支持对象检测和实例细分。 classification支持将很快添加。CaptionOntology ,它促使带有文本字幕的基本模型并将其映射到班级名称。例如,其他本体可能使用剪辑向量或示例图像而不是文本字幕。autodistill工艺的最终输出;这是一组对您的任务进行微调的权重,可以部署以获得预测。 人类标签是广泛采用计算机视觉的最大障碍之一。制作适合培训生产模型的数据集可能需要数千个小时。训练监督模型的蒸馏过程并不是什么新鲜事物,实际上,传统的人类标签只是从极强的基础模型(人脑?)中蒸馏的另一种形式。
基础模型非常了解很多,但是对于生产而言,我们需要对一些了解的模型。
随着基础模型变得越来越好,他们将越来越能够在标签过程中增加或更换人类。我们需要转向,利用和比较这些模型的工具。此外,这些基础模型很大,昂贵,并且经常在私人API背后进行门。对于许多生产用例,我们需要可以在边缘廉价和实时运行的模型。
Autodistill的基本模型已经可以为许多常见的用例创建数据集(并且通过创造性提示和很少的射击,我们可以将其实用程序扩展到更多),但是它们还不完美。还有很多工作要做。这只是一个开始,我们希望您的帮助测试和扩展系统的功能!
Autodistill是模块化的。您需要安装autodistill软件包(该软件包定义上述概念的接口)以及基本模型和目标模型插件(实现特定模型)。
通过单独包装这些插件,将依赖关系和许可不兼容最小化,任何人都可以实现和维护新模型。
例子:
pip install autodistill autodistill-grounded-sam autodistill-yolov8您也可以从GitHub升级该项目以供本地开发:
git clone https://github.com/roboflow/autodistill
cd autodistill
pip install -e .下面列举了其他基础和目标模型。
请参阅autodistill快速介绍”演示笔记本。该笔记本漫游在没有标签的情况下建立牛奶容器检测模型。
下面,我们将笔记本的关键部分凝结了,以快速介绍autodistill 。
您还可以在一个命令中运行AutoDistill。首先,安装autodistill :
pip install autodistill然后,运行:
autodistill images --base= " grounding_dino " --target= " yolov8 " --ontology ' {"prompt": "label"} ' --output= " ./dataset "该命令将用恐龙接地的目录中的所有图像标记所有images ,并使用标记的图像来训练Yolov8模型。接地Dino将用“提示”标记所有图像,并将标签保存为“标签”。您可以根据需要指定尽可能多的提示和标签。结果数据集将保存在一个名为dataset的文件夹中。
在此示例中,我们将展示如何使用AutoDistill-trounded-SAM和Autodistill-Yolov8将接地SAM提炼成小型Yolov8型号。
pip install autodistill autodistill-grounded-sam autodistill-yolov8
from autodistill_grounded_sam import GroundedSAM
from autodistill . detection import CaptionOntology
from autodistill_yolov8 import YOLOv8
# define an ontology to map class names to our GroundingDINO prompt
# the ontology dictionary has the format {caption: class}
# where caption is the prompt sent to the base model, and class is the label that will
# be saved for that caption in the generated annotations
base_model = GroundedSAM ( ontology = CaptionOntology ({ "shipping container" : "container" }))
# label all images in a folder called `context_images`
base_model . label (
input_folder = "./images" ,
output_folder = "./dataset"
)
target_model = YOLOv8 ( "yolov8n.pt" )
target_model . train ( "./dataset/data.yaml" , epochs = 200 )
# run inference on the new model
pred = target_model . predict ( "./dataset/valid/your-image.jpg" , confidence = 0.5 )
print ( pred )
# optional: upload your model to Roboflow for deployment
from roboflow import Roboflow
rf = Roboflow ( api_key = "API_KEY" )
project = rf . workspace (). project ( "PROJECT_ID" )
project . version ( DATASET_VERSION ). deploy ( model_type = "yolov8" , model_path = f"./runs/detect/train/" )要使用autodistill绘制单个图像的注释,您可以使用以下代码。该代码有助于可视化基本模型(即接地SAM)生成的注释以及目标模型(即Yolov8)的结果。
import supervision as sv
import cv2
img_path = "./images/your-image.jpeg"
image = cv2 . imread ( img_path )
detections = base_model . predict ( img_path )
# annotate image with detections
box_annotator = sv . BoxAnnotator ()
label_annotator = sv . LabelAnnotator ()
labels = [
f" { base_model . ontology . classes ()[ class_id ] } { confidence :0.2f } "
for _ , _ , confidence , class_id , _ , _ in detections
]
annotated_frame = box_annotator . annotate (
scene = image . copy (), detections = detections
)
annotated_frame = label_annotator . annotate (
scene = annotated_frame , detections = detections , labels = labels
)
sv . plot_image ( annotated_frame , ( 16 , 16 ))我们的目标是使autodistill支持使用所有基础模型作为基本模型,而大多数SOTA监督模型作为目标模型。我们首先专注于对象检测和细分任务,但计划尽快启动分类支持!将来,我们希望autodistill也将用于计算机视觉之外的模型。
| 基础 /目标 | Yolov8 | YOLO-NAS | Yolov5 | detr | Yolov6 | Yolov7 | MT-Yolov6 |
|---|---|---|---|---|---|---|---|
| 接地的SAM 2 | ✅ | ✅ | ✅ | ✅ | ? | ||
| 诊断 | ✅ | ✅ | ✅ | ✅ | ? | ||
| 接地萨姆 | ✅ | ✅ | ✅ | ✅ | ? | ||
| 接地 | ✅ | ✅ | ✅ | ✅ | ? | ||
| 猫头鹰 | ✅ | ✅ | ✅ | ✅ | ? | ||
| Sam-CLIP | ✅ | ✅ | ✅ | ✅ | ? | ||
| llava-1.5 | ✅ | ✅ | ✅ | ✅ | ? | ||
| KOSMOS-2 | ✅ | ✅ | ✅ | ✅ | ? | ||
| OWLV2 | ✅ | ✅ | ✅ | ✅ | ? | ||
| Roboflow Universe模型(50K+预训练模型) | ✅ | ✅ | ✅ | ✅ | ? | ||
| codet | ✅ | ✅ | ✅ | ✅ | ? | ||
| Azure自定义视觉 | ✅ | ✅ | ✅ | ✅ | ? | ||
| AWS重新认知 | ✅ | ✅ | ✅ | ✅ | ? | ||
| Google Vision | ✅ | ✅ | ✅ | ✅ | ? |
| 基础 /目标 | Yolov8 | YOLO-NAS | Yolov5 | Yolov7 | Segformer |
|---|---|---|---|---|---|
| 接地萨姆 | ✅ | ? | ? | ||
| Sam-CLIP | ✅ | ? | ? | ||
| Seggpt | ✅ | ? | ? | ||
| 快餐 | ? | ? | ? |
| 基础 /目标 | VIT | Yolov8 | Yolov5 |
|---|---|---|---|
| 夹子 | ✅ | ✅ | ? |
| metaclip | ✅ | ✅ | ? |
| dinov2 | ✅ | ✅ | ? |
| blip | ✅ | ✅ | ? |
| ALBEF | ✅ | ✅ | ? |
| fastvit | ✅ | ✅ | ? |
| AltClip | ✅ | ✅ | ? |
| 撤离 | ✅ | ✅ | ? |
| 双子座 | ✅ | ✅ | ? |
| 富尤 | ? | ? | ? |
| 开放火烈鸟 | ? | ? | ? |
| GPT-4 | |||
| 棕榈-2 |
您可以选择使用Roboflow上的AutoDistill训练的一些目标模型。部署在Roboflow上使您可以使用一系列简洁的SDK来在边缘使用模型,从roboflow.js进行Web部署到Nvidia Jetson设备。
Roboflow支持以下AutoDistill目标模型进行部署:
| 模型名称 | 支持? |
|---|---|
| Yolov8对象检测 | ✅ |
| yolov8实例分割 | ✅ |
| Yolov5对象检测 | ✅ |
| yolov5实例分割 | ✅ |
| yolov8分类 |
Autodistill:训练Yolov8的零注释
除了添加新型号外,我们计划在autodistill中探索几个领域,包括:
我们爱您的投入!请参阅我们的贡献指南以开始。感谢我们所有的贡献者!
autodistill软件包已在Apache 2.0下许可。每个基础或目标模型插件都可以使用其自己的许可证,与其基础模型的许可相对应。有关更多信息,请参考每个插件存储库中的许可证。
PytorchStreamReader failed reading zip archive: failed finding central directory ?当Pytorch无法为模型加载模型权重时,这是造成此错误。进入~/.cache/autodistill目录,然后删除与要加载的模型关联的文件夹。然后,再次运行您的代码。模型权重将从划痕下载。保持安装过程不间断。
| 项目 | 描述 |
|---|---|
| 监督 | 从预测过滤和显示到对象跟踪再到模型评估,用于计算机视觉项目的通用实用程序。 |
| Autodistill(这个项目) | 自动标记用于训练计算机视觉模型的图像。 |
| 推理 | 一款易于使用的,可用于生产的推理服务器,用于计算机视觉,支持部署许多流行的模型体系结构和微调模型。 |
| 笔记本 | 计算机视觉任务的教程,从训练最先进的模型到跟踪对象再到区域中的对象。 |
| 收集 | 由剪辑提供动力的自动化,智能数据收集。 |