Skip to main content
imcluster

PyPI package version Documentation build status Coverage badge Test suite status

imcluster clusters images using features from pretrained vision models. It produces a reusable cache and a self-contained HTML gallery organized by cluster.

By default, imcluster uses DINOv3 when its weights are cached or accessible and otherwise falls back to DINOv2. UMAP and K-means are the default reduction and clustering methods, with density-based methods available when the number of groups is not known.

Example imcluster gallery showing clustered image cards and navigation

Installation

imcluster requires Python 3.10–3.13:

pip install imcluster

DINOv2 presets are public and require no authentication. DINOv3 model repositories are gated. Before using --dino-version 3:

  1. Sign in to Hugging Face and open the DINOv3 ViT-B/16 model page.

  2. Review and accept Meta’s DINOv3 license and agree to share the requested contact information. Approval is usually automatic, but access can take several minutes (often 5–15 minutes) to propagate.

  3. Authenticate the machine that will run imcluster:

    hf auth login

    This opens Hugging Face’s browser login flow and stores the resulting token locally. Confirm the active account with:

    hf auth whoami

For a server or non-interactive environment, create a read token in Hugging Face token settings and expose it to the process instead:

export HF_TOKEN=hf_your_token_here

Never commit a Hugging Face token to the repository or place it directly in a script. Accepting access on the website and authenticating locally are both required; a valid token from an account without model access cannot download the weights.

DINOv2 weights use the Apache License 2.0. DINOv3 weights use the DINOv3 license; the imcluster source code uses the Apache License 2.0.

Quick start

Cluster the images directly inside a directory and open the gallery:

imcluster photos/

Include nested directories, request 12 groups, and preserve the outputs:

imcluster photos/ --recursive --n-clusters 12 \
    --cache results.parquet --gallery clusters.html

Inputs may be individual image files, directories, or UTF-8 text manifests with one image path per line. Relative manifest entries are resolved from the manifest’s directory. Supported formats are PNG, JPEG, TIFF, BMP, and GIF.

Outputs

Without output options, imcluster writes temporary processing data and a temporary HTML gallery, then opens the gallery in the default browser. Pass --no-open to suppress browser launching.

--cache PATH preserves the Parquet cache, which contains resolved paths, filenames, feature vectors, cluster labels, thumbnails, and run metadata. --gallery PATH preserves the standalone HTML gallery. It embeds its styles and JPEG thumbnails and does not require an internet connection.

If the input list no longer matches an existing cache, imcluster stops with a clear error. Pass --force to intentionally replace the cache. More targeted controls are available as --force-features, --force-cluster, and --force-thumbnails.

After creating a cache, rerun it without repeating the image inputs:

imcluster --cache results.parquet

Models

The default selection is --dino-version auto --size base. Automatic mode uses DINOv3 when the selected model is cached or accessible with the active Hugging Face account. Otherwise it reports the fallback and uses DINOv2.

Explicit DINOv2 selection uses --dino-version 2. Its presets are small, base, large, and max; max selects DINOv2 Giant. For DINOv2, --arch is ignored. In automatic mode, tiny falls back to DINOv2 Small and huge falls back to DINOv2 Giant.

Size

Hugging Face model

small

facebook/dinov2-small

base

facebook/dinov2-base

large

facebook/dinov2-large

max

facebook/dinov2-giant

DINOv3 is selected with --dino-version 3. Its available presets are:

Architecture

Size

Hugging Face model

vit

tiny

facebook/dinov3-vits16-pretrain-lvd1689m

vit

small

facebook/dinov3-vits16plus-pretrain-lvd1689m

vit

base

facebook/dinov3-vitb16-pretrain-lvd1689m

vit

large

facebook/dinov3-vitl16-pretrain-lvd1689m

vit

huge

facebook/dinov3-vith16plus-pretrain-lvd1689m

vit

max

facebook/dinov3-vit7b16-pretrain-lvd1689m

convnext

tiny

facebook/dinov3-convnext-tiny-pretrain-lvd1689m

convnext

small

facebook/dinov3-convnext-small-pretrain-lvd1689m

convnext

base

facebook/dinov3-convnext-base-pretrain-lvd1689m

convnext

large

facebook/dinov3-convnext-large-pretrain-lvd1689m

An arbitrary compatible Hugging Face model overrides the preset:

imcluster photos/ --model organization/model-id

Inference

--device auto selects CUDA, then Apple MPS, then CPU. A device can be selected explicitly with --device cpu|cuda|mps. --batch-size defaults to 8; reduce it if inference runs out of memory.

ViT-B is suitable for a quality-oriented default but can be slow on CPU. --dino-version 2 --size small or --dino-version 3 --size tiny provides a lighter run. The largest variants require substantial accelerator memory.

Clustering

The available methods use scikit-learn’s clustering algorithms.

By default, UMAP reduces the DINO vectors and K-means clusters the result. Use --reduce tsne or --reduce pca to select another reduction method, or --reduce none to cluster the original vectors. --reduction-dims sets the PCA or UMAP target and defaults to 50. Reduced vectors are cached.

Spectral, K-means, agglomerative, and hierarchical clustering use a cluster count:

imcluster photos/ --clustering spectral --n-clusters 10

DBSCAN discovers groups and marks outliers as the noise cluster:

imcluster photos/ --clustering dbscan \
    --dbscan-eps 0.35 --min-samples 3

HDBSCAN also discovers groups and noise while adapting to varying densities:

imcluster photos/ --clustering hdbscan --min-samples 5

To evaluate clusters against known classes, provide a CSV with filename and class columns:

imcluster photos/ --evaluate expected_classes.csv

The class names only need to be consistent. The CLI reports Normalized Mutual Information (NMI), Adjusted Rand Index (ARI), and clustering accuracy (ACC) using an optimal mapping between cluster IDs and expected classes.

Add --metric metrics.csv to save the three scores as a CSV file.

Run imcluster --help for the complete command-line reference.

Explore similar images

The gallery can compare every image with its nearest visual neighbours. Click an image card to open the comparison modal: the selected image stays on the left while the 30 most similar images, ranked using cosine similarity between the original model feature vectors, are available on the right. Use the thumbnail strip or arrow buttons to move through the matches.

Click the image on the right to promote it to the selected image. The modal then updates with that image’s nearest neighbours, making it easy to explore related groups without closing the comparison view.

imcluster gallery modal comparing a selected image with similar items

The modal loads full-resolution originals from their file paths when they are available and otherwise falls back to the embedded thumbnails. Each thumbnail is embedded only once in the standalone report and reused by JavaScript.

Limitations

Model downloads can be large, and the biggest presets are impractical without a high-memory GPU. Clustering quality depends on the visual domain and chosen parameters. The models’ training data also carries the biases documented by their authors.

Credits

imcluster is maintained by Robert Turnbull at the Melbourne Data Analytics Platform. Zaher Joukhadar was instrumental in the original idea, and James Quang helped implement DINO feature extraction.

Metadata

Release files for imcluster 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for imcluster 0.4.0
File Size Uploaded Provenance
imcluster-0.4.0.tar.gz 247.4 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for imcluster 0.4.0
File Interpreter ABI Platform
imcluster-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 496.6 kB

Release files / imcluster-0.4.0.tar.gz

Download URL imcluster-0.4.0.tar.gz
Size 247.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1d3e171a388dd8554a87ff45fe19456533681526d6e6c750e133e248a6775a22
BLAKE2b-256 checksum
How to use checksums
bb2a5e97f93654d620042017c411e5a9228fd3a1c0a2877441e77c855c2f2ac4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 11, 2026.

Transparency log

Release files / imcluster-0.4.0-py3-none-any.whl

Download URL imcluster-0.4.0-py3-none-any.whl
Size 249.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5760c7116c0849221662c9f612dbd4858a0716de3fec3f20d47ace0570863d06
BLAKE2b-256 checksum
How to use checksums
8f095fb44ff6c40bf5894945f67cae86b9ab9dff4954d4336f0c98ffbdeedbfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 11, 2026.

Transparency log

Security for imcluster 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for imcluster-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page