Skip to main content

Smart image downsampling for image classification datasets

Project description

smartdownsample

Fast, simple image downsampling that just works

SmartDownsample selects images from large collections in seconds, not hours. One simple function that works equally fast whether you're selecting 100 or 23,000 images from 24,000.

Installation

pip install smartdownsample

Features

  • Always fast - Seconds for any selection ratio
  • 🎯 Smart bucketing - Better than random, faster than complex algorithms
  • 📊 Scales linearly - 24k images? No problem
  • 🔧 Dead simple - One function, always works
  • 🎲 Reproducible - Set seed for consistent results

Usage

from smartdownsample import select_distinct

# Select 100 images from 24,000 - takes seconds
selected = select_distinct(
    image_paths=my_24k_images,
    target_count=100
)

# Select 23,000 images from 24,000 - also takes seconds!
selected = select_distinct(
    image_paths=my_24k_images,
    target_count=23000
)

# It's that simple.
print(f"Selected {len(selected)} images")

How It Works

  1. Hash images - Quick perceptual hashing (4 parallel workers)
  2. Create buckets - Group similar images together
  3. Sample evenly - Take images from each bucket for diversity

Result: Better than random selection, without the complexity.

Performance

Task Time
100 from 1,000 <5 sec
900 from 1,000 <5 sec
1,000 from 24,000 ~30 sec
23,000 from 24,000 ~30 sec
Any ratio Fast ✓

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
n_workers 4 Number of parallel workers (4 is optimal)
hash_size 8 Hash size (8 is fast and good enough)
random_seed 42 Random seed for reproducible results
show_progress True Whether to display progress bars

Why It's Fast

  • Fixed algorithm - No switching between methods
  • Simple hashing - DHash is faster than PHash
  • Smart bucketing - O(n) grouping instead of O(n²) comparisons
  • Parallel processing - But capped at 4 workers (diminishing returns above that)

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.3.2.tar.gz (7.2 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.3.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for smartdownsample-0.3.2.tar.gz
Algorithm Hash digest
SHA256 d391ef7e44785a9438ffdc5e154478a3230041c95ee4f7845a7e870a433e9a1d
MD5 c01360da78fc12813b348b6e5062cd52
BLAKE2b-256 03b31fcd47565775914e33fe13fb9b6ad9009bf012c8f7a5751a6a99212a52b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for smartdownsample-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7237c1a3f77df415b866bbc84265fd5c2b64f68203c8551fe171c0a056c88bbc
MD5 cd71ec54bae19b3ceaae7f1ed0714310
BLAKE2b-256 5a706ed5f79e4810dd44ca449bd95e9f59899e4d6609b2da489c3276193b02d0

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