Find which image regions influence a VLM claim through grid-based occlusion testing.
Project description
vlm-occlusion
Find which image regions influence a Vision-Language Model claim through black-box occlusion testing.
Installation
pip install vlm-occlusion
Usage
from vlm_occlusion import analyze_occlusion
result = analyze_occlusion(
image="example.png",
predict_fn=describe_image,
score_fn=claim_score,
grid_size=(4, 4),
occlusion="blur",
output_path="heatmap.png",
)
print(result["most_influential_region"])
print(result["importance_scores"])
predict_fn receives a Pillow image and returns text or a number. score_fn turns that result into a numerical score for the claim you are testing. The package compares the original score with scores produced after occluding each grid cell.
It is model-agnostic and includes no VLM, model adapter, or network client. It measures black-box sensitivity to controlled perturbations; it does not inspect attention or reveal a model's internal reasoning.
Example
The included deterministic example tests the claim:
There is a red desk lamp in the upper-left area.
The mock predictor measures visible red evidence; no model, API key, or network connection is used. The 4×4 analysis identifies the left-side cell containing most of the lamp as the strongest influence.
| Input image | Most influential cell occluded | Importance heatmap |
|---|---|---|
The scene is an original generated illustration created for this repository. The occluded image and heatmap are produced locally by the example.
python examples/generate_example_images.py
python examples/basic_usage.py
The README assets are saved under docs/images/.
Features
- Model-agnostic callback API
- Grid-based black, white, mean, and blur occlusion
- Normalized regional importance scores
- Pillow-only visualization
- No network access required
Limitations
Occlusion sensitivity is an approximation. A perturbation may change a response for reasons unrelated to visual grounding, and results can vary with grid size and occlusion strategy. This package does not expose internal model attention.
Issues
Report issues at https://github.com/edujbarrios/vlm-occlusion/issues.
Author
Eduardo J. Barrios — edujbarrios@outlook.com
License
Mozilla Public License 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vlm_occlusion-0.1.0.tar.gz.
File metadata
- Download URL: vlm_occlusion-0.1.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4950ee87a7ccd5eab3553ac2f064deaf050658acef2cbaed39d5462cdf69ec12
|
|
| MD5 |
134c292ca9d717b0195308aa723ebdb3
|
|
| BLAKE2b-256 |
a861d42bcd57541254a5dec64e26e8d01b831d31cc9da217fdaee517ed1a6536
|
File details
Details for the file vlm_occlusion-0.1.0-py3-none-any.whl.
File metadata
- Download URL: vlm_occlusion-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d59f4798be6b150319a3925516d823d1c24405aa83f973d3c9e3ae92247650f
|
|
| MD5 |
fa28555e7d6592a89ec66bf562d5ffb3
|
|
| BLAKE2b-256 |
3b653f14f0b6692f7285a0ec0671f4fb3d3277a078c5c17745e65aa9f7ab6382
|