筆記本|推理| 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(這個項目) | 自動標記用於訓練計算機視覺模型的圖像。 |
| 推理 | 一款易於使用的,可用於生產的推理服務器,用於計算機視覺,支持部署許多流行的模型體系結構和微調模型。 |
| 筆記本 | 計算機視覺任務的教程,從訓練最先進的模型到跟踪對象再到區域中的對象。 |
| 收集 | 由剪輯提供動力的自動化,智能數據收集。 |