Skip to main content

Autodistill Azure Vision Module

This repository contains the code supporting the Azure Vision module for use with Autodistill.

The Azure Vision Image Analysis 4.0 API enables you to detect objects in images.

With this package, you can use the API to automatically label data for use in training a fine-tuned computer vision model.

This is ideal if you want to train a model that you own on a custom dataset.

You can then use your trained model on your computer using Autodistill, or at the edge or in the cloud by deploying with Roboflow Inference.

Read the full Autodistill documentation.

Read the Autodistill Azure Vision documentation.

Installation

[!NOTE]
Using this project will incur billing charges for API calls to the Azure Vision Image Analysis 4.0 API. Refer to the Azure Computer Vision pricing for more information and to calculate your expected pricing. This package makes one API call per image you want to label.

To use Azure Vision with autodistill, you need to install the following dependency:

pip install autodistill-azure-vision

Next, you will need to create an Azure account. Once you have an Azure account, create a "Computer vision" deployment in the "Azure AI services" dashboard in Azure.

This deployment will give you two API keys and an endpoint URL. You will need one of these API keys and the endpoint URL to use this Autodistill module.

Set your API key and endpoint URL in your environment:

export AZURE_VISION_SUBSCRIPTION_KEY=<your api key>
export AZURE_VISION_ENDPOINT=<your endpoint>

Use the quickstart below to start labeling images.

Quickstart

Label a Single Image

from autodistill_azure_vision import AzureVision
from autodistill.detection import CaptionOntology

# define an ontology to map class names to our Azure Custom Vision 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
# then, load the model
base_model = AzureVision(
    ontology=CaptionOntology(
        {
            "animal": "animal",
            "a forklift": "forklift"
        }
    ),
    endpoint=os.environ["AZURE_VISION_ENDPOINT"],
    subscription_key=os.environ["AZURE_VISION_SUBSCRIPTION_KEY"]
)

results = base_model.predict("image.jpeg")

print(results)

# annotate predictions on an image
classes = base_model.ontology.classes()

box_annotator = sv.BoxAnnotator()

labels = [
	f"{classes[class_id]} {confidence:0.2f}"
	for _, _, confidence, class_id, _
	in detections
]

image = cv2.imread("image.jpeg")

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

sv.plot_image(image=annotated_frame, size=(16, 16))

Label a Folder of Images

from autodistill_azure_vision import AzureVision
from autodistill.detection import CaptionOntology

# define an ontology to map class names to our Azure Custom Vision 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
# then, load the model
base_model = AzureVision(
    ontology=CaptionOntology(
        {
            "animal": "animal",
            "a forklift": "forklift"
        }
    ),
    endpoint=os.environ["AZURE_VISION_ENDPOINT"],
    subscription_key=os.environ["AZURE_VISION_SUBSCRIPTION_KEY"]
)

base_model.label("./context_images", extension=".jpeg")

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!

Release files for autodistill-azure-vision 0.1.0

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-azure-vision 0.1.0
File Size Uploaded
autodistill-azure-vision-0.1.0.tar.gz 4.8 kB Details

Built distribution (wheel)

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

Total release size: 10.0 kB

Release files / autodistill-azure-vision-0.1.0.tar.gz

Download URL autodistill-azure-vision-0.1.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cc5064edca3b2cd5dac1d1b559723c5f1806a79d7670ed123c9c99203863e750
BLAKE2b-256 checksum
How to use checksums
a8cdc4a86ad97368c947ebdad831252abbd77d6484e32cca68df2d3c64f66d66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / autodistill_azure_vision-0.1.0-py3-none-any.whl

Download URL autodistill_azure_vision-0.1.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c27db864cde494f36f36bc76aa172d029b1d5dd5e56f0f18b939a75a8a6a04e2
BLAKE2b-256 checksum
How to use checksums
dc997a163155a99754c20bb0c280aa3a4da0d3c4e842ef8d166695d9e7dd3d97
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.0 This release

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