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
Release files for vlm-occlusion 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| vlm_occlusion-0.1.0.tar.gz | 6.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| vlm_occlusion-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.8 kB
Release files / vlm_occlusion-0.1.0.tar.gz
| Download URL | vlm_occlusion-0.1.0.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4950ee87a7ccd5eab3553ac2f064deaf050658acef2cbaed39d5462cdf69ec12
|
|
BLAKE2b-256 checksum How to use checksums |
a861d42bcd57541254a5dec64e26e8d01b831d31cc9da217fdaee517ed1a6536
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / vlm_occlusion-0.1.0-py3-none-any.whl
| Download URL | vlm_occlusion-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6d59f4798be6b150319a3925516d823d1c24405aa83f973d3c9e3ae92247650f
|
|
BLAKE2b-256 checksum How to use checksums |
3b653f14f0b6692f7285a0ec0671f4fb3d3277a078c5c17745e65aa9f7ab6382
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|