Skip to main content

👋 Hello

autodistill is a Python package to distill large foundational models into smaller, domain-specific models for deployment. Using autodistill, you can go from images to inference on a custom model with little to no labeling in between for a range of use cases.

Distilled models are smaller than general vision models and easier to refine and fine-tune to the situation in which your model will be deployed.

You can also use autodistill to annotate images for use with your existing models.

Installation

To install autodistill, run the following command:

pip install autodistill
Install from source

You can also clone the project from GitHub for local development:

git clone https://github.com/roboflow/autodistill
cd autodistill
pip install -e .

🚀 Quickstart

See the Quickstart.ipynb notebook for a quick introduction to autodistill. Below, we have condensed key parts of the notebook for a quick introduction to autodistill.

Create an Ontology

from autodistill_grounding_dino import GroundingDINO
from autodistill_yolov8 import YOLOv8

# define an ontology to map class names to our GroundingDINO prompt
ontology = {
    "ontology_type": "class_descriptions",
    "prompts": [
        {
            "class_name": "dog",
            "prompt_type": "text",
            "prompt_value": "all dogs"
        },
    ]
}

# load the base model and set the ontology
base_model = GroundingDINO(ontology)
base_model.set_ontology(ontology)

# see predictions on an image
detections_list = base_model.view_grounding_dino_prediction("./dog.jpeg")

# label all images in a folder called `context_images`
base_model.label("./context_images", extension=".jpeg")

from autodistill_yolov8 import YOLOv8
target_model = YOLOv8("yolov8n.pt")
target_model.train("./context_images_labeled/data.yaml", epochs=200)

# run inference on the new model
pred = target_model.predict("./context_images_labeled/train/images/dog-7.jpg", conf=0.01)

# 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"{HOME}/runs/detect/train/")

base_models are models that have been pre-trained to have a wide breadth of knowledge.

Base models have ontologies which are the prompts we can use to draw predictions from them. Deciding the proper ontology (and installing your CUDA drivers) is most of the work you will have to do to train distilled models with autodistill.

To distill a model, you will need to bring example data of the context you want to your model to operate in.

target_models are smaller in-domain models that you will train using the annotations generated by your base model.

Annotate a Single Image

To plot the annotations for a single image using autodistill, you can use the code below. This code is helpful to visualize the annotations generated by your base model (i.e. Grounding DINO) and the results from your target model (i.e. YOLOv8).

import supervision as sv
import cv2

img_path = "./context_images/dog.jpeg"

image = cv2.imread(img_path)

detections = base_model.predict(img_path)
# annotate image with detections
box_annotator = sv.BoxAnnotator()

labels = [
    f"{base_model.ontology.class_id_map[class_id]} {confidence:0.2f}"
    for _, _, confidence, class_id, _ in detections
]

annotated_frame = box_annotator.annotate(
    scene=image.copy(), detections=detections, labels=labels
)

sv.plot_image(annotated_frame, (16, 16))

📍 roadmap

🚧 - work in progress

object detection

base / target YOLOv5 YOLOv7 YOLOv8 RT-DETR
Grounded DINO
Grounded SAM 🚧
DETIC
OWL-ViT

instance segmentation

base / target YOLOv5 YOLOv7 YOLOv8 RT-DETR
Grounded SAM 🚧

classification

base / target YOLOv8 YOLOv5
CLIP

🏆 Contributing

We love your input! Please see our contributing guide to get started. Thank you 🙏 to all our contributors!

License

The autodistill package is licensed under an MIT license. Each model that integrates with autodistill uses their own license. Please refer to the license associated with each supported model for more information.

Metadata

Release files for autodistill 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for autodistill 0.1.1
File Size Uploaded
autodistill-0.1.1.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for autodistill 0.1.1
File Interpreter ABI Platform
autodistill-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.5 kB

Release files / autodistill-0.1.1.tar.gz

Download URL autodistill-0.1.1.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
13514508955daa80f1efd9cda12eb311338064961092f181fa9861125aa761fe
BLAKE2b-256 checksum
How to use checksums
2997fa02a8df7374323ae585744a7648be6c8f539a4d0ca5ab02e2e125d0e3c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.6

Release files / autodistill-0.1.1-py3-none-any.whl

Download URL autodistill-0.1.1-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0cd66f7604f076646def841a2e8b9e5fe8ddcbfca7ac49b5e30775671797daf3
BLAKE2b-256 checksum
How to use checksums
15b9464bd031a64840baf9cb43aa70b2def1a7e5f3012e06b77c4744287691e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.6

Release history Release notifications | RSS feed

0.1.29

2 release files

0.1.28

2 release files

0.1.27

2 release files

0.1.26

2 release files

0.1.25

2 release files

0.1.24

2 release files

0.1.21

2 release files

0.1.19

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

2 release files

0.0.7

1 release file

0.0.6

2 release files

0.0.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page