Skip to main content

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.

Environment

The scripts below assume the user is in the Docker development environment.

Directory Layout​

Files and folders in the benchmarks directory
benchmarks/
├── README.md
├── main.py
├── corpus.toml
├── images/
│ ├── .gitkeep
│ └── <id>.toml
├── pyproject.toml
└── tests/
└── test_main.py

Key Files​

FilePurpose
main.pyCorpus management CLI
corpus.tomlCorpus schema version and shared config
images/*.tomlOne metadata entry per image
tests/test_main.pyBenchmark corpus test suite

Corpus Schema​

The root corpus config currently declares:

Contents of corpus.toml
schema_version = 1

[config]

The [config] section is reserved for future shared configuration.

Entry Schema​

Each image metadata file contains:

FieldTypeDescription
idstringUnique entry ID matching the filename
datasetstringDataset name
urlstringSource image URL
sha256stringSHA-256 digest
size[width, height]Image dimensions
licensestringApproved license identifier
authorstringRights holder
sourcestringAttribution/source reference
tagsarrayOptional descriptive tags

Example:

images/coco-2017-val-000000002153-jpg.toml
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 SystemCache 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
Example session
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​

Missing by Default

Img2Num intentionally does not commit these images. Instead, they go into a cache outside of the repository.

Download missing images
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.

Run all benchmark tests
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​

Allowed Licenses
  • CC0-1.0
  • CC-BY-2.0
  • CC-BY-4.0
  • CC-BY-SA-2.0
  • CC-BY-SA-4.0
  • Public-Domain
Rejected Licenses

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).