Skip to main content

CoDet model for use with Autodistill

Project description

Autodistill CoDet Module

This repository contains the code supporting the CoDet base model for use with Autodistill.

CoDet is an open vocabulary zero-shot object detection model. The model was described in the "CoDet: Co-Occurrence Guided Region-Word Alignment for Open-Vocabulary Object Detection" published by Chuofan Ma, Yi Jiang, Xin Wen, Zehuan Yuan, Xiaojuan Qi. The paper was submitted to NeurIPS2023.

Read the full Autodistill documentation.

Read the CoDet Autodistill documentation.

Installation

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

pip3 install autodistill-codet

Quickstart

When you first run the model, it will download CoDet and its dependencies, as well as the required model configuration and weights. The output during the download process will be verbose. If you stop the download process before it has finished, run rm -rf ~/.cache/autodistill/CoDet before running the model again. This ensures that you don't work from a part-installed CoDet setup.

When the predict() function runs, the output will also be verbose. You can ignore the output printed to the console that appears when you call predict().

You can only predict classes in the LVIS vocabulary. You can see a list of supported classes in the class_names.json file in the autodistill-codet GitHub repository.

Use the code snippet below to get started:

from autodistill_codet import CoDet
from autodistill.detection import CaptionOntology
from autodistill.utils import plot
import cv2

# define an ontology to map class names to our CoDet 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 = CoDet(
    ontology=CaptionOntology(
        {
            "person": "person"
        }
    )
)

# run inference on an image and display the results
# class_names is a list of all classes supported by the model
# class_names can be used to turn the class_id values from the model into human-readable class names
# class names is defined in self.class_names
predictions = base_model.predict("./context_images/1.jpeg")
image = cv2.imread("./context_images/1.jpeg")

plot(
  image=image,
  detections=predictions,
  classes=base_model.class_names
)

# run inference on a folder of images and save the results
base_model.label("./context_images", extension=".jpeg")

License

This project is licensed under an Apache 2.0 license, except where files explicitly note a 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-codet-0.1.2.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

autodistill_codet-0.1.2-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file autodistill-codet-0.1.2.tar.gz.

File metadata

  • Download URL: autodistill-codet-0.1.2.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for autodistill-codet-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ba557e0d697fd97ca707ad510bdfda957f0b59279429a0342d17ab02a3f9aad7
MD5 9fa6197deb32c38e1d61275bc7c164bb
BLAKE2b-256 15fad8cf81bce8d398e42c134ecea4934500c45f377d865edac391e20616ea33

See more details on using hashes here.

File details

Details for the file autodistill_codet-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for autodistill_codet-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e8b353980c95d465eefeb1b8b684a4f99753d3b57c43b8f6dde89acc6543d7de
MD5 98811c808552f80475c6c70a7cd23287
BLAKE2b-256 b21e7d798a744f5b527ea17f5c6d6113202fc4f78a726a621ce2a1f91a4419d3

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