Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
autodistill-transformers
Use object detection models in Hugging Face Transformers to automatically label data to train a fine-tuned model.
Readme
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.
To use Transformers with autodistill, you need to install the following dependency:
pip3 install autodistill-transformers
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")
This project is licensed under an MIT license.
We love your input! Please see the core Autodistill contributing guide to get started. Thank you 🙏 to all our contributors!
FAQs
Use object detection models in Hugging Face Transformers to automatically label data to train a fine-tuned model.
We found that autodistill-transformers demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).