Skip to main content

Autodistill Roboflow Universe Module

This repository contains the code supporting the Roboflow Universe base model for use with Autodistill.

Roboflow Universe is a community where people share computer vision models and datasets. Over 50,000 models and 250,000 datasets have been shared on Universe, with new models available every day. You can use Autodistill to run object detection, classification, and segmentation models hosted on Roboflow Universe.

[!NOTE] Using this project will use Roboflow API calls. You will need a free Roboflow account to use this project. Sign up for a free Roboflow account to get started. Learn more about pricing.

Read the full Autodistill documentation.

Read the Roboflow Universe Autodistill documentation.

Installation

To use models hosted on Roboflow Universe with autodistill, you need to install the following dependency:

pip3 install autodistill-roboflow-universe

Quickstart

[!NOTE] Autodistill uses ontology to map model predictions to the expected class labels. For other Autodistill models, the term 'caption' is used when the model accepts prompting or a description for a prediction. When using Roboflow Universe as an Autodistill base model, the 'caption' will be the class name/label that the Universe model will return.

from autodistill_roboflow_universe import RoboflowUniverseModel
from autodistill.detection import CaptionOntology
from autodistill.utils import plot
import cv2

# define an ontology to map class names to our Roboflow model 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 in the generated annotations

model_configs = [
    ("PROJECT_ID", VERSION_NUMBER)
]

base_model = RoboflowUniverseModel(
    ontology=CaptionOntology(
        {
            "person": "person",
            "forklift": "vehicle"
        }
),
    api_key="ROBOFLOW_API_KEY",
    model_configs=model_configs,
)

# run inference on a single image
result = base_model.predict("image.jpeg")

print(result)

plot(
    image=cv2.imread("image.jpeg"),
    detections=result,
    classes=base_model.ontology.classes(),
)

# label a folder of images
base_model.label("./context_images", extension=".jpeg")

Above, replace:

  • API_KEY: with your Roboflow API key
  • PROJECT_NAME: with your Roboflow project ID.
  • VERSION: with your Roboflow model version.
  • model_type: with the type of model you want to run. Options are object-detection, classification, or segmentation. This value must be the same as the model type trained on Roboflow Universe.

You can run multiple models on a single image. This is ideal if you need to identify multiple objects using different models hosted on Roboflow Universe. To run multiple models, add the models you want to run in the model_configs list. For example:

model_configs = [
    ("PROJECT_ID", VERSION_NUMBER),
    ("PROJECT_ID", VERSION_NUMBER)
]

All models will be run on every image.

Learn how to retrieve your Roboflow API key. Learn how to retrieve a model ID.

License

This project is licensed under an MIT license.

🏆 Contributing

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

Metadata

Release files for autodistill-roboflow-universe 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-roboflow-universe 0.1.1
File Size Uploaded
autodistill-roboflow-universe-0.1.1.tar.gz 4.7 kB Details

Built distribution (wheel)

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

Total release size: 9.8 kB

Release files / autodistill-roboflow-universe-0.1.1.tar.gz

Download URL autodistill-roboflow-universe-0.1.1.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a8333cdbbd1312b2ec7502c7c20209d777a5ab0dca9f6973679481d274d0b430
BLAKE2b-256 checksum
How to use checksums
e8e47ced410c6a156ab0758ffff723a694f79ddafc5343f83d5c9925f9502483
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

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

Download URL autodistill_roboflow_universe-0.1.1-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70175cb377896227db3fbfdddc84f4871b5a051954a5f07beed832aa86c3cbed
BLAKE2b-256 checksum
How to use checksums
febf20b7896317cfea152175dd8138f18c6f9c0ff27dd6731a318219c054211e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

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