Skip to main content

Smart image downsampling for image classification datasets

Project description

smartdownsample

Efficient downsampling for image classification datasets

SmartDownsample selects the most diverse images from large collections, ideal for reducing dataset size while preserving visual variability.

Installation

pip install smartdownsample

Usage

from smartdownsample import select_distinct

# Example list of image paths
my_image_list = [
    "path/to/img1.jpg",
    "path/to/img2.jpg",
    "path/to/img3.jpg",
    "path/to/img4.jpg"
]

# Simple selection - get 100 most diverse images
selected = select_distinct(
    image_paths=my_image_list,
    target_count=100
)

# With visual verification to see excluded images in context
selected = select_distinct(
    image_paths=my_image_list,
    target_count=100,
    show_verification=True
)

print(f"Selected {len(selected)} images")

Parameters

Parameter Default Description
image_paths Required List of image file paths (str or Path objects)
target_count Required Exact number of images to select
window_size 100 Rolling window size (larger = better quality, slower)
random_seed 42 Random seed for reproducible results
show_progress True Whether to display progress bars
show_verification False Show visual verification comparing excluded vs included images

Step by Step

  1. Sort paths by directory. Within each folder, files are naturally ordered (e.g., img1.jpg, img2.jpg, img10.jpg) so related images remain grouped.
  2. Compute perceptual hashes for all valid image paths.
  3. Apply rolling window selection on the hash array to choose indices of the most diverse images. This runs in O(n) time, scales to large classes of 100k+ images, and compares each candidate only to a sliding window of recent selections.
  4. Return results as [valid_paths[i] for i in selected_indices].
  5. Optional verification plot: If show_verification=True, the algorithm displays a visual check of 18 randomly selected excluded images and their included counterpart. The visualization opens automatically in your default image viewer without saving files to disk.

License

MIT License – see LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smartdownsample-0.1.2.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smartdownsample-0.1.2-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file smartdownsample-0.1.2.tar.gz.

File metadata

  • Download URL: smartdownsample-0.1.2.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for smartdownsample-0.1.2.tar.gz
Algorithm Hash digest
SHA256 cb9c3d73e078f433908f7b56a08dde02261590e158e805e9a3399fac5e89d9ef
MD5 9675038072334d018b61cb3f99a45f95
BLAKE2b-256 6c9ddb13adb6cbdbce4f058ada32c2e58d93bcac1e7d6cf7911b959517950372

See more details on using hashes here.

File details

Details for the file smartdownsample-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for smartdownsample-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cf9f92b951219a081b3846365051de518912adfcf1c60e4af61bd92815c4e22c
MD5 9cbac544deb480f39c062d24c3c8b310
BLAKE2b-256 037ea60ed95939198b17384e33d4581f6b88514d18f9fee92cf36cb72584f0bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page