Skip to main content

Autodistill Google Cloud Vision module for use in training a custom, fine-tuned model.

Project description

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!

Project details


Download files

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

Source Distribution

autodistill-gcp-vision-0.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

autodistill_gcp_vision-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for autodistill-gcp-vision-0.1.0.tar.gz
Algorithm Hash digest
SHA256 729d125c65b3dd5ca6a85099e090b1729e43c11975e43f1aef6c047de5208c74
MD5 badfb620623d118b21166e0223552ea7
BLAKE2b-256 1c5d2d8771cc065c349a1ddbd707654bc95d55fda8cf27068537a3720a9ca71e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for autodistill_gcp_vision-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7709dca1f14d8baddcadb75785689f5cee3e83b6407216a0f3a1dab6cfa38b2f
MD5 1b6cea4d61a33eaa9121e02e588ac706
BLAKE2b-256 df3b1325285af98f952478f5f4dee220090df5f74f2c016d4caffc8b6ba8eeb6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page