Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

apiprompting: Attention Prompting on Image for Large Vision-Language Models


version license python-version Gradio

👋 hello

Package for an easy implementation of Attention Prompting on Image for Large Vision-Language Models.

💻 install

pip install apiprompting

📄 Quick Start

clip_api

Generates image masks and blends them using CLIP_Based API.

Parameters

  • images (list): list of images. Each item can be a path to image (str) or a PIL.Image.

  • queries (list): list of queries. Each item is a str.

  • batch_size (int): Batch size for processing images. Default is 8.

  • model_name (str):
    Name of the model to load the pretrained model. Available options include "ViT-L-14-336", "ViT-L-14", and "ViT-B-32".

  • layer_index (int, optional, default=22):
    Index of the layer in the model to hook. This is where the feature extraction occurs.

  • enhance_coe (int, optional, default=10):
    Enhancement coefficient for mask blending, which determines the strength of the enhancement applied to the generated masks.

  • kernel_size (int, optional, default=3):
    Kernel size for mask blending, which should be an odd number. This determines the size of the convolution kernel used in blending.

  • interpolate_method_name (str, optional, default="LANCZOS"):
    Name of the interpolation method used for image resizing. It can be any interpolation method supported by PIL.Image.resize, such as "NEAREST", "BILINEAR", "BICUBIC", "LANCZOS", etc.

  • grayscale (float, optional, default=0):
    A flag indicating whether to convert the image to grayscale. A value of 0 means no grayscale conversion, while a value of 1 will convert the image to grayscale.

Returns

  • list:
    A list containing the masked images generated by the function. Each item is a PIL.Image.

llava_api

Generates image masks and blends them using the LLaVA_Based API.

Parameters

  • images (list): list of images. Each item can be a path to image (str) or a PIL.Image.

  • queries (list): list of queries. Each item is a str.

  • batch_size (int): Batch size for processing images. Only support 1.

  • model_name (str):
    Name of the model to load the pretrained model. One of "llava-v1.5-7b" and "llava-v1.5-13b".

  • layer_index (int, optional, default=20):
    Index of the layer in the model to hook. This is where the feature extraction occurs.

  • enhance_coe (int, optional, default=10):
    Enhancement coefficient for mask blending, which determines the strength of the enhancement applied to the generated masks.

  • kernel_size (int, optional, default=3):
    Kernel size for mask blending, which should be an odd number. This determines the size of the convolution kernel used in blending.

  • interpolate_method_name (str, optional, default="LANCZOS"):
    Name of the interpolation method used for image resizing. It can be any interpolation method supported by PIL.Image.resize, such as "NEAREST", "BILINEAR", "BICUBIC", "LANCZOS", etc.

  • grayscale (float, optional, default=0):
    A flag indicating whether to convert the image to grayscale. A value of 0 means no grayscale conversion, while a value of 1 will convert the image to grayscale.

Returns

  • list:
    A list containing the masked images generated by the function. Each item is a PIL.Image.

Example

from apiprompting import clip_api, llava_api

images, queries = ["path/to/image"], ["query"]

# CLIP_Based API
masked_images = clip_api(images, queries, model_name="ViT-L-14-336")
# LLaVA_Based API
masked_images = llava_api(images, queries, model_name="llava-v1.5-13b")

💜 acknowledgement

The README file is adopted from here.

🦸 contribution

We would love your help in making this repository even better! If you noticed any bug, or if you have any suggestions for improvement, feel free to open an issue or submit a pull request.

Release files for apiprompting 0.1.0rc2

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

Source distribution (sdist)

Source distribution for apiprompting 0.1.0rc2
File Size Uploaded
apiprompting-0.1.0rc2.tar.gz 1.6 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for apiprompting 0.1.0rc2
File Interpreter ABI Platform
apiprompting-0.1.0rc2-py3-none-any.whl Python 3 none any Details

Total release size: 3.0 MB

Release files / apiprompting-0.1.0rc2.tar.gz

Download URL apiprompting-0.1.0rc2.tar.gz
Size 1.6 MB
Tags Source
SHA-256 checksum
How to use checksums
3559944ad1785f75f6aee3abd3ae689bfc8f66b4e6f00b8f742647c1cd0500e5
BLAKE2b-256 checksum
How to use checksums
9c7206a5d7423ef25b87c2009bfcf165b695c3c263cd7afd57c9e3a8a1c5eb5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.14 Linux/5.15.0-113-generic

Release files / apiprompting-0.1.0rc2-py3-none-any.whl

Download URL apiprompting-0.1.0rc2-py3-none-any.whl
Size 1.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
ff619990414b20ba72f25019e4b8f40f0f3d8c8cfacf9e06f68c9826f03d3761
BLAKE2b-256 checksum
How to use checksums
c91d2a2145d7e7c0540c06c5e779fe4ed48fc32feb2a23fe2b3194788fd65c01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.14 Linux/5.15.0-113-generic

Release history Release notifications | RSS feed

This release

0.1.0rc2 This release

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