Autodistill Transformers Module
This repository contains the code supporting the Transformers models model for use with Autodistill.
Transformers, maintained by Hugging Face, features a range of state of the art models for Natural Language Processing (NLP), computer vision, and more.
This package allows you to write a function that calls a Transformers object detection model and use it to automatically label data. You can use this data to train a fine-tuned model using an architecture supported by Autodistill (i.e. YOLOv8, YOLOv5, or DETR).
Read the full Autodistill documentation.
Installation
To use Transformers with autodistill, you need to install the following dependency:
pip3 install autodistill-transformers
Quickstart
The following example shows how to use the Transformers module to label images using the Owlv2ForObjectDetection model.
You can update the inference() functon to use any object detection model supported in the Transformers library.
import cv2
import torch
from autodistill.detection import CaptionOntology
from autodistill.utils import plot
from transformers import OwlViTForObjectDetection, OwlViTProcessor
from autodistill_transformers import TransformersModel
processor = OwlViTProcessor.from_pretrained("google/owlvit-base-patch32")
model = OwlViTForObjectDetection.from_pretrained("google/owlvit-base-patch32")
def inference(image, prompts):
inputs = processor(text=prompts, images=image, return_tensors="pt")
outputs = model(**inputs)
target_sizes = torch.Tensor([image.size[::-1]])
results = processor.post_process_object_detection(
outputs=outputs, target_sizes=target_sizes, threshold=0.1
)[0]
return results
base_model = TransformersModel(
ontology=CaptionOntology(
{
"a photo of a person": "person",
"a photo of a cat": "cat",
}
),
callback=inference,
)
# run inference
results = base_model.predict("image.jpg", confidence=0.1)
print(results)
# plot results
plot(
image=cv2.imread("image.jpg"),
detections=results,
classes=base_model.ontology.classes(),
)
# label a directory of images
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!
Metadata
Release files for autodistill-transformers 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| autodistill-transformers-0.1.1.tar.gz | 4.1 kB | Without provenance | Details for autodistill-transformers-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| autodistill_transformers-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for autodistill_transformers-0.1.1-py3-none-any.whl |
Total release size: 8.6 kB
Release files / autodistill-transformers-0.1.1.tar.gz
| Download URL | autodistill-transformers-0.1.1.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fde324d48426fa1d9ec877cfc4016ce18521b621f9d367f9b1bbdcad7d607823
|
|
BLAKE2b-256 checksum How to use checksums |
029766c9a571e9341fa4dc981f6a9f5bf453e3b5ea189bf57ba524c8560a248e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / autodistill_transformers-0.1.1-py3-none-any.whl
| Download URL | autodistill_transformers-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f1a6e3c3edbb91f3def12fd716bf1bd54687f157750f9e76a76544c70ee4a64d
|
|
BLAKE2b-256 checksum How to use checksums |
111b01bfb9a140956e164a89e33c73391c3f85174b38c824da976a4208272b3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for autodistill-transformers 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.