Package: autodistill
notebooks|inference|autodistill|collectAutodistill uses big, slower foundation models to train small, faster supervised models. Usingautodistill, you can go from unlabeled images to inference on a custom model running at the edge with no human intervention in between.Currently,autodistillsupports vision tasks like object detection and instance segmentation, but in the future it can be expanded to support language (and other) models.🔗 QuicklinksTutorialDocsSupported ModelsContribute👀 Example OutputHere are example predictions of a Target Model detecting milk bottles and bottlecaps after being trained on an auto-labeled dataset using Autodistill (seethe Autodistill YouTube videofor a full walkthrough):🚀 Features🔌 Pluggable interface to connect models together🤖 Automatically label datasets🐰 Train fast supervised models🔒 Own your model🚀 Deploy distilled models to the cloud or the edge📚 Basic ConceptsTo useautodistill, you input unlabeled data into a Base Model which uses an Ontology to label a Dataset that is used to train a Target Model which outputs a Distilled Model fine-tuned to perform a specific Task.Autodistill defines several basic primitives:Task- A Task defines what a Target Model will predict. The Task for each component (Base Model, Ontology, and Target Model) of anautodistillpipeline must match for them to be compatible with each other. Object Detection and Instance Segmentation are currently supported through thedetectiontask.classificationsupport will be added soon.Base Model- A Base Model is a large foundation model that knows a lot about a lot. Base models are often multimodal and can perform many tasks. They're large, slow, and expensive. Examples of Base Models are GroundedSAM and GPT-4's upcoming multimodal variant. We use a Base Model (along with unlabeled input data and an Ontology) to create a Dataset.Ontology- an Ontology defines how your Base Model is prompted, what your Dataset will describe, and what your Target Model will predict. A simple Ontology is theCaptionOntologywhich prompts a Base Model with text captions and maps them to class names. Other Ontologies may, for instance, use a CLIP vector or example images instead of a text caption.Dataset- a Dataset is a set of auto-labeled data that can be used to train a Target Model. It is the output generated by a Base Model.Target Model- a Target Model is a supervised model that consumes a Dataset and outputs a distilled model that is ready for deployment. Target Models are usually small, fast, and fine-tuned to perform a specific task very well (but they don't generalize well beyond the information described in their Dataset). Examples of Target Models are YOLOv8 and DETR.Distilled Model- a Distilled Model is the final output of theautodistillprocess; it's a set of weights fine-tuned for your task that can be deployed to get predictions.💡 Theory and LimitationsHuman labeling is one of the biggest barriers to broad adoption of computer vision. It can take thousands of hours to craft a dataset suitable for training a production model. The process of distillation for training supervised models is not new, in fact, traditional human labeling is just another form of distillation from an extremely capable Base Model (the human brain 🧠).Foundation models know a lot about a lot, but for production we need models that know a lot about a little.As foundation models get better and better they will increasingly be able to augment or replace humans in the labeling process. We need tools for steering, utilizing, and comparing these models. Additionally, these foundation models are big, expensive, and often gated behind private APIs. For many production use-cases, we need models that can run cheaply and in realtime at the edge.Autodistill's Base Models can already create datasets for many common use-cases (and through creative prompting and few-shotting we can expand their utility to many more), but they're not perfect yet. There's still a lot of work to do; this is just the beginning and we'd love your help testing and expanding the capabilities of the system!💿 InstallationAutodistill is modular. You'll need to install theautodistillpackage (which defines the interfaces for the above concepts) along withBase Model and Target Model plugins(which implement specific models).By packaging these separately as plugins, dependency and licensing incompatibilities are minimized and new models can be implemented and maintained by anyone.Example:pipinstallautodistillautodistill-grounded-samautodistill-yolov8Install from sourceYou can also clone the project from GitHub for local development:gitclonehttps://github.com/roboflow/autodistillcdautodistill
pipinstall-e.Additional Base and Target models areenumerated below.🚀 QuickstartSee thedemo Notebookfor a quick introduction toautodistill. This notebook walks through building a milk container detection model with no labeling.Below, we have condensed key parts of the notebook for a quick introduction toautodistill.You can also run Autodistill in one command. First, installautodistill:pipinstallautodistillThen, run:autodistillimages--base="grounding_dino"--target="yolov8"--ontology'{"prompt": "label"}'--output="./dataset"This command will label all images in a directory calledimageswith Grounding DINO and use the labeled images to train a YOLOv8 model. Grounding DINO will label all images with the "prompt" and save the label as the "label". You can specify as many prompts and labels as you want. The resulting dataset will be saved in a folder calleddataset.Install PackagesFor this example, we'll show how to distillGroundedSAMinto a smallYOLOv8model usingautodistill-grounded-samandautodistill-yolov8.pip install autodistill autodistill-grounded-sam autodistill-yolov8Distill a Modelfromautodistill_grounded_samimportGroundedSAMfromautodistill.detectionimportCaptionOntologyfromautodistill_yolov8importYOLOv8# 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 annotationsbase_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 modelpred=target_model.predict("./dataset/valid/your-image.jpg",confidence=0.5)print(pred)# optional: upload your model to Roboflow for deploymentfromroboflowimportRoboflowrf=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/")Visualize PredictionsTo plot the annotations for a single image usingautodistill, you can use the code below. This code is helpful to visualize the annotations generated by your base model (i.e. GroundedSAM) and the results from your target model (i.e. YOLOv8).importsupervisionassvimportcv2img_path="./images/your-image.jpeg"image=cv2.imread(img_path)detections=base_model.predict(img_path)# annotate image with detectionsbox_annotator=sv.BoxAnnotator()labels=[f"{base_model.ontology.classes()[class_id]}{confidence:0.2f}"for_,_,confidence,class_id,_indetections]annotated_frame=box_annotator.annotate(scene=image.copy(),detections=detections,labels=labels)sv.plot_image(annotated_frame,(16,16))📍 Available ModelsOur goal is forautodistillto support using all foundation models as Base Models and most SOTA supervised models as Target Models. We focused on object detection and segmentation
tasks first but plan to launch classification support soon! In the future, we hopeautodistillwill also be used for models beyond computer vision.✅ - complete (click row/column header to go to repo)🚧 - work in progressobject detectionbase / targetYOLOv8YOLO-NASYOLOv5DETRYOLOv6YOLOv7MT-YOLOv6DETIC✅✅✅✅🚧GroundedSAM✅✅✅✅🚧GroundingDINO✅✅✅✅🚧OWL-ViT✅✅✅✅🚧SAM-CLIP✅✅✅✅🚧LLaVA-1.5✅✅✅✅🚧Kosmos-2✅✅✅✅🚧OWLv2✅✅✅✅🚧Roboflow Universe Models (50k+ pre-trained models)✅✅✅✅🚧CoDet✅✅✅✅🚧VLPart✅✅✅✅🚧Azure Custom Vision✅✅✅✅🚧AWS Rekognition✅✅✅✅🚧Google Vision✅✅✅✅🚧instance segmentationbase / targetYOLOv8YOLO-NASYOLOv5YOLOv7SegformerGroundedSAM✅🚧🚧SAM-CLIP✅🚧🚧SegGPT✅🚧🚧FastSAM🚧🚧🚧classificationbase / targetViTYOLOv8YOLOv5CLIP✅✅🚧MetaCLIP✅✅🚧DINOv2✅✅🚧BLIP✅✅🚧ALBEF✅✅🚧FastViT✅✅🚧AltCLIP✅✅🚧Fuyu🚧🚧🚧Open Flamingo🚧🚧🚧GPT-4PaLM-2Roboflow Model Deployment SupportYou can optionally deploy some Target Models trained using Autodistill on Roboflow. Deploying on Roboflow allows you to use a range of concise SDKs for using your model on the edge, fromroboflow.jsfor web deployment toNVIDIA Jetsondevices.The following Autodistill Target Models are supported by Roboflow for deployment:model nameSupported?YOLOv8 Object Detection✅YOLOv8 Instance Segmentation✅YOLOv5 Object Detection✅YOLOv5 Instance Segmentation✅YOLOv8 Classification🎬 Video GuidesAutodistill: Train YOLOv8 with ZERO AnnotationsPublished: 8 June 2023In this video, we will show you how to use a new library to train a YOLOv8 model to detect bottles moving on a conveyor line. Yes, that's right - zero annotation hours are required! We dive deep into Autodistill's functionality, covering topics from setting up your Python environment and preparing your images, to the thrilling automatic annotation of images.💡 Community ResourcesDistill Large Vision Models into Smaller, Efficient Models with Autodistill: Announcement post with written guide on how to use AutodistillComparing AI-Labeled Data to Human-Labeled Data: A qualitative evaluation of Grounding DINO used with Autodistill across various tasks and domains.How to Evaluate Autodistill Prompts with CVevals: Evaluate Autodistill prompts.Autodistill: Label and Train a Computer Vision Model in Under 20 Minutes: Building a model to detect planes in under 20 minutes.Comparing AI-Labeled Data to Human-Labeled Data: Explore the strengths and limitations of a base model used with Autoditsill.Train an Image Classification Model with No Labeling: Use Grounded SAM to automatically label images for training an Ultralytics YOLOv8 classification model.Train a Segmentation Model with No Labeling: Use CLIP to automatically label images for training an Ultralytics YOLOv8 segmentation model.File a PR to add your own resources here!🗺️ RoadmapApart from adding new models, there are several areas we plan to explore withautodistillincluding:💡 Ontology creation & prompt engineering👩‍💻 Human in the loop support🤔 Model evaluation🔄 Active learning💬 Language tasks🏆 ContributingWe love your input! Please see ourcontributing guideto get started. Thank you 🙏 to all our contributors!👩‍⚖️ LicenseTheautodistillpackage is licensed under anApache 2.0. Each Base or Target model plugin may use its own license corresponding with the license of its underlying model. Please refer to the license in each plugin repo for more information.Frequently Asked Questions ❓What causes thePytorchStreamReader failed reading zip archive: failed finding central directoryerror?This error is caused when PyTorch cannot load the model weights for a model. Go into the~/.cache/autodistilldirectory and delete the folder associated with the model you are trying to load. Then, run your code again. The model weights will be downloaded from scratch. Leave the installation process uninterrupted.💻 explore more Roboflow open source projectsProjectDescriptionsupervisionGeneral-purpose utilities for use in computer vision projects, from predictions filtering and display to object tracking to model evaluation.Autodistill(this project)Automatically label images for use in training computer vision models.InferenceAn easy-to-use, production-ready inference server for computer vision supporting deployment of many popular model architectures and fine-tuned models.NotebooksTutorials for computer vision tasks, from training state-of-the-art models to tracking objects to counting objects in a zone.CollectAutomated, intelligent data collection powered by CLIP.