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.0.tar.gz (10.3 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.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: smartdownsample-0.3.0.tar.gz
  • Upload date:
  • Size: 10.3 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.0.tar.gz
Algorithm Hash digest
SHA256 2269fc8032a5181a149dc096058a91e9f9ce7076c2dd82e5383fcbec52e17331
MD5 afdae564d77de511b4fb14bf511c9af3
BLAKE2b-256 5faa32f50b7efd5e626d66f4bb382e63226fa3607a1d908239c6de4f64bfffad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for smartdownsample-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ac8e5deddf448a9e8d2b244a206954763a277b6669843e12cffdda2ccf66dcb
MD5 1f6f0784d9bb7f81e421b308f39b8348
BLAKE2b-256 c7c9d0741988e0216aa0e41e3330f2264e4198f26bf24027e3517e2fe6f1adea

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