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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autodistill-0.1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autodistill-0.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file autodistill-0.1.0.tar.gz.

File metadata

  • Download URL: autodistill-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.12

File hashes

Hashes for autodistill-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fa650f0743ea68ed5a5f9598af7b13213e69abcd9f48bfdcdd90cdbc52000e8e
MD5 51f6c2a7528763ff3727a56c8c38b5b6
BLAKE2b-256 1e7adf49872953641331a77f1da3927876588da8877c104cc02ff0a0b66fd830

See more details on using hashes here.

File details

Details for the file autodistill-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: autodistill-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.12

File hashes

Hashes for autodistill-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b12490742b767ceca039028deaf238f8668f776b9ad48ab2576cf5977b888dd
MD5 e04895bfedef83b8d427b23e788c3ae4
BLAKE2b-256 70879ff94c4cf5063e6555e593c847d447dbe4d4b586afbd94295221c30cc6ea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page