fovi
Welcome to the fovi codebase, a PyTorch library for implementing foveated vision. This library provides tools for foveated sampling and an interface to deep vision models, including CNNs and ViTs.
We provide an interactive walkthrough of the methods and results at https://nblauch.github.io/fovi/
Version 2.0.0 introduces the sensing, model, and training package boundaries. The pre-refactor source is the 1.0 baseline. Main can advance between releases; record a Git commit for reproducible source installs. See versions and releases.
🛠️ Install
For published releases, choose the capabilities you need:
pip install fovi # sensing, sampling grids, KNN layers
pip install 'fovi[models]' # complete models and checkpoint loading
pip install 'fovi[training]' # models, training utilities, and research tools
pip install 'fovi[all]' # identical dependencies to fovi[models,training]
To work from a source checkout, clone the repository, activate your Python environment, and install from source:
git clone https://github.com/nblauch/fovi.git
cd fovi
pip install -e . # sensing, sampling grids, KNN layers
pip install -e '.[models]' # complete models and checkpoint loading
pip install -e '.[training]' # models, training utilities, and research tools; no FFCV
pip install -e '.[all]' # identical dependencies to .[models,training]
Choose one installation command. All source ships in the same package; extras select dependencies.
The base includes PyTorch, torchvision, geometry/image-processing libraries, CuPy, and Warp, but does not
require model registries, Transformers, FFCV, or experiment tracking. Importing fovi,
fovi.sensing, and primitive fovi.arch modules does not import models or training or require
research storage environment variables.
FFCV is an external prerequisite for the built-in training and validation loaders.
It is installed manually, including when using all. Trainer subclasses or external
training scripts can supply other data loaders.
See package boundaries and migration for public import paths.
Manual FFCV installation
The built-in loaders use the FFCV-SSL fork pinned in requirements-ffcv.txt, imported
in Python as ffcv. This file is for manual installation and is not part of fovi's
package dependency metadata. Install its native build prerequisites in an environment
compatible with that fork, then install it from the repository root:
conda install pkg-config compilers libjpeg-turbo opencv pytorch torchvision torchaudio pytorch-cuda numba -c pytorch -c nvidia -c conda-forge
pip install -e '.[training]'
pip install --no-build-isolation -r requirements-ffcv.txt
For a release installed from PyPI, use requirements-ffcv.txt from its matching
Git release tag. The same native prerequisites apply.
Research storage directories
Base sensing/KNN use and pretrained inference with fovi[models] do not require
any FOVI_*_DIR environment variables. Installing the training extra does not
change this behavior.
Before importing Trainer or fovi.paths, set FOVI_SAVE_DIR for checkpoints and
logs and FOVI_DATASETS_DIR for datasets. Optionally, set FOVI_SLOW_DIR for large
storage (defaults to FOVI_SAVE_DIR) and FOVI_FIGS_DIR for figures (defaults to
the figures subdirectory of FOVI_SLOW_DIR).
Optional Flash Attention
To use Flash Attention, install it separately:
pip install packaging ninja
pip install flash-attn --no-build-isolation
🤗 Pretrained Models
Pretrained models are hosted on HuggingFace Hub and are automatically downloaded on first use:
| Model | Size | Description |
|---|---|---|
fovi-dinov3-hplus_a-2.78_res-64_in1k |
~3.4 GB | ViT-H/16+ backbone, high foveation (a=2.78) |
fovi-dinov3-splus_a-2.78_res-64_in1k |
~131 MB | ViT-S/16+ backbone, high foveation (a=2.78) |
fovi-dinov3-splus_a-60.94_res-64_in1k |
~131 MB | ViT-S/16+ backbone, low foveation (a=60.94) |
fovi-alexnet_a-0.5_res-64_rfmult-1_in1k |
~24 MB | AlexNet, high foveation (a=0.5), rfmult=1 (matched resolution kernel reference frame) |
fovi-alexnet_a-0.5_res-64_rfmult-2_in1k |
~69 MB | AlexNet, high foveation (a=0.5), rfmult=2 (default higher-resolution kernel reference frame) |
fovi-resnet18_a-0.5_res-64_rfmult-2_in1k |
~179 MB | ResNet18, high foveation (a=0.5), rfmult=2 |
import torch
from fovi.models import get_model_from_base_fn
# Models are automatically downloaded from HuggingFace Hub on first use
model = get_model_from_base_fn(
'fovi-dinov3-splus_a-2.78_res-64_in1k', device='cuda'
).eval()
# RGB uint8 images, batch/channel/height/width; coordinates are normalized row/column.
images = torch.randint(0, 256, (1, 3, 256, 256), dtype=torch.uint8, device='cuda')
with torch.inference_mode():
embeddings, layers, retinal_samples = model(
images, setting='supervised', fixations=[(0.5, 0.5)],
n_fixations=1, do_postproc=False,
)
logits = model.head(embeddings)
Inference uses .[models] and needs no FFCV, datasets, trainer, or FOVI_*_DIR
environment variables. The checkpoint configuration retains its historical training
section for model dimensions and preprocessing; reading that data does not import the
training runtime.
📝 Example notebooks
notebooks/step0_sensor_manifold : explore the basic concepts involved in our foveated sensor
notebooks/step1_sampling.ipynb : learn how to do foveated sampling from images
notebooks/step2_knnconv.ipynb : learn how to build kNN-convolutional neural networks to process foveated sensor outputs
notebooks/step3_dinov3.ipynb : work with a state-of-the-art foveated vision system based on the DINOv3 ViT model, adapted to handle foveated inputs.
notebooks/step4_get_activations.ipynb: use hooks to extract intermediate activations from a model, and explore the Trainer class
📚 Documentation
The docs are hosted at: https://nblauch.github.io/fovi/docs/
You can also build locally. Docs are generated semi-automatically from source code and docstrings. The documentation includes:
- API Reference: Complete documentation of all functions, classes, and modules
- User Guide: Installation, quickstart, and usage examples
- Developer Guide: Contributing guidelines and development setup
To do so:
# Install documentation dependencies
pip install -e '.[models]'
pip install -r requirements-docs.txt
# Generate documentation
python scripts/generate_docs.py
# View the documentation
open docs/_build/html/index.html
# View documentation on a remote cluster (need to forward the port separately, this is done automatically in VScode/Cursor)
python -m http.server 8000 --directory docs/_build/html
⚡ Benchmarking: optimized vs baseline
FOVI's KNN convolution and KNN pooling ship with optimized CUDA kernels (selected
automatically); this is the optimization under test.
The native CUDA convolution requires CUDA 12 and an Ampere-or-newer GPU. CuPy is installed
automatically with FOVI; older NVIDIA GPUs use the portable Torch/Warp fallback rather than
attempting to compile an unsupported native kernel. Python 3.9 installations resolve to
CuPy 13, preserving compatibility with FFCV; newer Python versions may use CuPy 14.
benchmarks/benchmark_final_comparison.py is the single entry point that measures what
they buy you — every FOVI model variant runs in two arms (baseline = the reference
conv/pool kernels, optimized = the shipped optimized conv/pool kernels, with
output-parity columns) against two clearly-labeled dense references:
- logpolar@64 — the matched foveated control: the same fixations, retina, and augmentation feeding a standard Conv2d/ViT (a log-polar-warped 64x64 input, with the necessary circular padding) instead of KNNConv, so only the backbone differs from the foveated model — run one warped pass per fixation (matched sample count).
- dense@256 — the native-resolution pipeline a non-foveated system needs
(ResNet18/AlexNet/ViT-S+16 on the full 256x256 image), run exactly once per image:
the foveated design trades one expensive full-res pass for a few cheap glances, so
cells are labeled
(images, n_fixations)and per-image columns are emitted so you can apply either normalization.
# from the repo root (defaults: all 5 variants, 10 & 128 images, 1 & 4 fixations,
# train + inference, both dense references). Write both report formats alongside:
python benchmarks/benchmark_final_comparison.py --device 0 \
--report-out results.md --html-out results.html
# a quick look at one model:
python benchmarks/benchmark_final_comparison.py --models resnet18_rf1 --batch 10 --repeats 5
# render reports from already-collected JSON (one file per GPU), no re-benchmarking:
python benchmarks/benchmark_final_comparison.py \
--report-from run_ada.jsonl run_h100.jsonl --html-out results.html
Output: one JSON-lines record per cell (timings under both protocols — CUDA-event
median/min and wall throughput — memory, parity vs the baseline arm, per-layer backend
routing), followed by a printed summary table with xd@64 and xd@256 speed ratios.
--report-out writes a human-readable Markdown summary; --html-out writes a
self-contained interactive page (select batch, fixations, train/inference, scope, and the
reference — logpolar@64 tracks the fixation count, dense@256 is always one native pass —
with color-coded speedup tables across all GPUs). --report-from renders either format
from existing JSON without re-running.
Useful knobs: --cache-dir points model loading at a local Hugging Face cache (offline
friendly); env vars FOVI_KNN_BACKEND=baseline, FOVI_KNN_POOL_BACKEND=baseline, and
FOVI_KNN_WORK_THRESHOLD override backend selection globally. The harness records
backend availability and any unavailable CUDA runtime/compiler support. The harness
itself is the reproducible evidence — run the commands above to regenerate every number
on your own hardware; final published results will live in the project's PR/release
notes.
Manual optimization test gate
GPU CI is not currently enabled. Before merging changes to the optimized kernels or retinal sampling path, run the complete gate manually on a CUDA 12 Ampere-or-newer machine. The standard installation includes both CuPy and Warp kernel dependencies.
pip install -e .
python -m unittest discover -s tests -p 'test_knn*.py' -v
python -m unittest discover -s tests -p 'test_retinal_sampling.py' -v
Set FOVI_TEST_DEVICE=<index> to select a particular GPU. The gate covers baseline and
automatic routing, forward/backward parity, FP16/BF16 autocast, fused convolution and
pooling, Warp, inference tensors, graph capture, and retinal-sampling equivalence.
🏛️ Citation
Blauch, N. M., Alvarez, G. A., & Konkle, T. (2026). FOVI: a biologically-inspired foveated interface for deep vision models. Proceedings of the 43rd International Conference on Machine Learning (ICML). https://arxiv.org/abs/2602.03766
🙏 Acknowledgements
Originally developed at the Kempner Institute at Harvard University. Ongoing support provided by NVIDIA.
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 fovi-2.0.0.tar.gz.
File metadata
- Download URL: fovi-2.0.0.tar.gz
- Upload date:
- Size: 67.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8547fcc0bd5354bbd0599ff9cb43385502ee15bc59bae0e773a8abbcc2640ddb
|
|
| MD5 |
aca20553a197371dc4954d4a6446437e
|
|
| BLAKE2b-256 |
e4378d426f4801050620f42fafaf0094ceb5ac1973043abece402459e7bbeab7
|
Provenance
The following attestation bundles were made for fovi-2.0.0.tar.gz:
Publisher:
publish.yml on nblauch/fovi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fovi-2.0.0.tar.gz -
Subject digest:
8547fcc0bd5354bbd0599ff9cb43385502ee15bc59bae0e773a8abbcc2640ddb - Sigstore transparency entry: 2780825600
- Sigstore integration time:
-
Permalink:
nblauch/fovi@c6a963879eeebce92f14fd9a8067fd30354c6051 -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/nblauch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c6a963879eeebce92f14fd9a8067fd30354c6051 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fovi-2.0.0-py3-none-any.whl.
File metadata
- Download URL: fovi-2.0.0-py3-none-any.whl
- Upload date:
- Size: 261.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efe6121ea8534e6acb22313d5bb36052c6070f9272f769143dd4890203dff2be
|
|
| MD5 |
22ebf3f8a4890c314ca63d476d34ab75
|
|
| BLAKE2b-256 |
be64d8da006f1f46ca50b3a40cf797fab17001ad33ed0fda6de82ce62bfd9208
|
Provenance
The following attestation bundles were made for fovi-2.0.0-py3-none-any.whl:
Publisher:
publish.yml on nblauch/fovi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fovi-2.0.0-py3-none-any.whl -
Subject digest:
efe6121ea8534e6acb22313d5bb36052c6070f9272f769143dd4890203dff2be - Sigstore transparency entry: 2780825629
- Sigstore integration time:
-
Permalink:
nblauch/fovi@c6a963879eeebce92f14fd9a8067fd30354c6051 -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/nblauch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c6a963879eeebce92f14fd9a8067fd30354c6051 -
Trigger Event:
push
-
Statement type: