Benchmark Corpus
The Img2Num benchmark corpus records metadata for benchmark source images without storing the actual image binaries in Git.
Img2Num does not redistribute benchmark source images. The repository stores only the metadata required to retrieve and verify them reproducibly.
Each image is assigned:
- a stable identity
- a SHA-256 digest
- dimensions
- attribution metadata
- licensing information
This allows contributors and CI systems to retrieve and verify identical image bytes reproducibly.
The scripts below assume the user is in the Docker development environment.
Directory Layout
benchmarks/
├── README.md
├── main.py
├── corpus.toml
├── images/
│ ├── .gitkeep
│ └── <id>.toml
├── pyproject.toml
└── tests/
└── test_main.py
Key Files
| File | Purpose |
|---|---|
main.py | Corpus management CLI |
corpus.toml | Corpus schema version and shared config |
images/*.toml | One metadata entry per image |
tests/test_main.py | Benchmark corpus test suite |
Corpus Schema
The root corpus config currently declares:
schema_version = 1
[config]
The [config] section is reserved for future shared configuration.
Entry Schema
Each image metadata file contains:
| Field | Type | Description |
|---|---|---|
id | string | Unique entry ID matching the filename |
dataset | string | Dataset name |
url | string | Source image URL |
sha256 | string | SHA-256 digest |
size | [width, height] | Image dimensions |
license | string | Approved license identifier |
author | string | Rights holder |
source | string | Attribution/source reference |
tags | array | Optional descriptive tags |
Example:
id = "coco-2017-val-000000002153-jpg"
dataset = "COCO 2017 val"
url = "http://images.cocodataset.org/val2017/000000002153.jpg"
sha256 = "8795ff243cf20405bd442631d5d1cb7e60665dd459c8d57f5764333808dd49fd"
size = [640, 480]
license = "CC-BY-SA-2.0"
author = "Jack (RiverRatt3)"
source = "https://www.flickr.com/photos/44458147@N00/2535221304/"
tags = ["natural"]
Installation
Install the tooling dependencies with:
uv sync --only-group dev --no-install-project
Cache System
Image binaries are never committed to Git.
Downloaded images are stored in a local content-addressed cache.
Default Cache Locations
| Operating System | Cache Location |
|---|---|
| Linux & Docker | ~/.cache/img2num-bench |
| macOS | ~/Library/Caches/img2num-bench |
| Windows | %LOCALAPPDATA%\img2num-bench |
Overriding the Cache Location
To override the cache location, change the IMG2NUM_BENCH_CACHE environment variable:
Linux / macOS (bash / zsh)
IMG2NUM_BENCH_CACHE="/tmp/my benchmark cache" \
uv run benchmarks fetch
Windows
PowerShell
$env:IMG2NUM_BENCH_CACHE = "C:\Users\Username\My Benchmark Cache"
uv run benchmarks fetch
Command Prompt (CMD)
set IMG2NUM_BENCH_CACHE="C:\Users\Username\My Benchmark Cache"
uv run benchmarks fetch
Adding an Image
Interactive Usage
Launch the interactive corpus manager:
uv run benchmarks add --interactive
The CLI:
- validates inputs
- checks licenses
- downloads the image
- computes SHA-256
- extracts dimensions
- writes metadata atomically
Img2Num Benchmark Corpus
────────────────────────
Image URL: https://images.cocodataset.org/val2017/000000002153.jpg
Dataset name: COCO 2017 val
License identifier: CC-BY-SA-2.0
Author / rights holder: Jack (RiverRatt3)
Source / attribution reference: https://www.flickr.com/photos/44458147@N00/2535221304/
Tags (comma-separated, optional): natural
Entry ID (optional, press Enter for auto 'coco-2017-val-000000002153-jpg'):
Review your entry:
Image URL: https://images.cocodataset.org/val2017/000000002153.jpg
Dataset: COCO 2017 val
License: CC-BY-SA-2.0
Author: Jack (RiverRatt3)
Source: https://www.flickr.com/photos/44458147@N00/2535221304/
Tags: natural
Entry ID: coco-2017-val-000000002153-jpg
Add this entry? (Y/n): y
Added coco-2017-val-000000002153-jpg (8795ff243cf20405bd442631d5d1cb7e60665dd459c8d57f5764333808dd49fd)
Non-Interactive Usage
For CI and automation:
uv run benchmarks add "$IMAGE_URL" \
--dataset "$DATASET" \
--license "$LICENSE_ID" \
--author "$AUTHOR" \
--source "$SOURCE_URL"
Optional:
--tags: "nature,smoke"--id: custom-id
Verification
Offline Metadata Verification
uv run benchmarks verify
Checks:
- schema validity
- required fields
- ID uniqueness
- URL validity
- license allow-list
Full Hash Verification
uv run benchmarks verify --hashes
Additionally verifies:
- cached files exist
- SHA-256 matches
- image dimensions match metadata
Fetching Images
Img2Num intentionally does not commit these images. Instead, they go into a cache outside of the repository.
uv run benchmarks fetch
This:
- downloads only missing files
- verifies SHA-256 immediately
- writes atomically into the cache
Tests
The benchmark corpus includes a dedicated pytest suite.
uv run benchmarks-tests
The suite validates:
- corpus verification
- cache integrity
- duplicate protection
- interactive CLI workflows
- hash verification
- image validation
- fetch behavior
- TOML serialization
- error handling
- cache lifecycle handling
Example Test Coverage
Cache Verification
assert verify_corpus(add_corpus, hashes=True) == []
Validates:
- SHA-256 correctness
- image dimensions
- cache existence
Duplicate Protection
with pytest.raises(CorpusManagerError):
add_entry(...)
Prevents:
- duplicate IDs
- duplicate image hashes
Interactive CLI Testing
entry = interactive_add_entry(...)
Covers:
- invalid input recovery
- duplicate prompts
- cancellation handling
- EOF handling
- keyboard interrupts
CI Integration
CI runs:
uv sync --only-group dev --no-install-project
Then:
uv run benchmarks-tests
uv run benchmarks verify
If image entries exist:
uv run benchmarks fetch
uv run benchmarks verify --hashes
License Policy
- CC0-1.0
- CC-BY-2.0
- CC-BY-4.0
- CC-BY-SA-2.0
- CC-BY-SA-4.0
- Public-Domain
Any licenses not explicitly listed above are rejected by default, including:
- ND licenses
- NC licenses
Additional licenses require explicit approval from a head maintainer.
If any additional licenses are to be added to the whitelist, explicit approval must be given by a head maintainer (e.g., @Ryan-Millard and @Krasner).