Skip to main content

CLIP_BBox

CLIP_BBox is a Python library for detecting image objects with natural language text labels.

Build Status codecov GitHub GitHub issues PyPI Documentation Status

Overview / About

CLIP is a neural network, pretrained on image-text pairs, that can predict the most relevant text snippet for a given image.

Given an image and a natural language text label, CLIP_BBox will obtain the image's spatial embedding and text label's embedding from CLIP, compute the similarity heatmap between the embeddings, then draw bounding boxes around the image regions with the highest image-text correspondences.

Note

The files for building the CLIP model (clip.py, model.py, newpad.py, simple_tokenizer.py) are third-party code from the CLIP repo. They are not included in test coverage.

Features

The library provides functions for the following operations:

  • Getting and appropriately reshaping an image's spatial embedding from the CLIP model before it performs attention-pooling
  • Getting a text snippet's embedding from CLIP
  • Computing the similarity heatmap between an image's spatial and text embeddings from CLIP
  • Drawing bounding boxes on an image, given a similarity heatmap

Install

Use pip to install clip_bbox as a Python package:

$ pip install clip-bbox

Usage Examples

Command Line Script

usage: python -m clip_bbox [-h] imgpath caption outpath

positional arguments:
  imgpath     path to input image
  caption     caption of input image
  outpath     path to output image displaying bounding boxes

optional arguments:
  -h, --help  show this help message and exit

To draw bounding boxes on an image based on its caption, run

$ python -m clip_bbox "path/to/img.png" "caption of your image" "path/to/output_path.png"

Python Module

To draw bounding boxes on an image based on its caption, do the following:

from clip_bbox import run_clip_bbox

run_clip_bbox("path/to/img.png", "caption of your image", "path/to/output_path.png")

Example Output

Here is an example output image for the caption "a camera on a tripod":

example output

Release files for clip-bbox 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clip-bbox 0.3.1
File Size Uploaded
clip_bbox-0.3.1.tar.gz 5.0 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for clip-bbox 0.3.1
File Interpreter ABI Platform
clip_bbox-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.3 MB

Release files / clip_bbox-0.3.1.tar.gz

Download URL clip_bbox-0.3.1.tar.gz
Size 5.0 MB
Tags Source
SHA-256 checksum
How to use checksums
de30ca74e436673b4ac9bf3024ba9dbc10524704dcd8c7fc3c4592af6ff2ec39
BLAKE2b-256 checksum
How to use checksums
7f04ca3733c9159a7c6395568ffac0f5851c307eec9aa2e9a69d7cb0261ecfc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release files / clip_bbox-0.3.1-py3-none-any.whl

Download URL clip_bbox-0.3.1-py3-none-any.whl
Size 3.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
dbe06e16aadc81a90ef361e95d99c736d122737ddd28cafed8e86b9626b255d8
BLAKE2b-256 checksum
How to use checksums
16afa443c7e1eb4d823fcb6bd6080118d638b899658289cec43178c1b512b331
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.16

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.0

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