Skip to main content

Autodistill GCP Vision Module

This repository contains the code supporting the Google Cloud Object Localization API base model for use with Autodistill.

With this repository, you can label images using the Google Cloud Object Localization API and train a fine-tuned model using the generated labels.

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.

See our Autodistill modules for AWS Rekognition and Azure Custom Vision if you are interested in using those services instead.

Read the full Autodistill documentation.

Read the GCP Vision Autodistill documentation.

Installation

[!NOTE]
Using this project will incur billing charges for API calls to the Google Cloud Object Localization API. Refer to the Google Cloud Vision pricing for more information. This package makes one API call per image you want to label.

To use the Google Cloud Object Localization API with autodistill, you need to install the following dependency:

pip install autodistill-gcp-vision

You will then need to authenticate with the gcloud CLI.

Learn how to install gcloud.

Learn how to set up and authenticate with gcloud.

Quickstart

from autodistill_gcp_vision import GCPVision
from autodistill.detection import CaptionOntology
import supervision as sv
import cv2

# define an ontology to map class names to our Google Cloud Object Localization API 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 = GCPVision(
    ontology=CaptionOntology(
        {
            "Person": "Person",
            "a forklift": "forklift"
        }
    )
)

detections = base_model.predict("image.jpeg")
print(detections)

# 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))

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

Built distribution (wheel)

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

Total release size: 9.6 kB

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

Download URL autodistill-gcp-vision-0.1.0.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
729d125c65b3dd5ca6a85099e090b1729e43c11975e43f1aef6c047de5208c74
BLAKE2b-256 checksum
How to use checksums
1c5d2d8771cc065c349a1ddbd707654bc95d55fda8cf27068537a3720a9ca71e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

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

Download URL autodistill_gcp_vision-0.1.0-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7709dca1f14d8baddcadb75785689f5cee3e83b6407216a0f3a1dab6cfa38b2f
BLAKE2b-256 checksum
How to use checksums
df3b1325285af98f952478f5f4dee220090df5f74f2c016d4caffc8b6ba8eeb6
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