A professional tool for cleaning duplicate or near-duplicate image frames using perceptual hashing and embeddings.
Project description
CleanFrames
Overview
CleanFrames is an advanced tool designed to identify and remove duplicate or near-duplicate images from large datasets using multiple embedding models and sophisticated clustering techniques. It supports exact and perceptual duplicate detection, semantic similarity analysis via deep embeddings, and offers visualization and detailed tabulated reporting for thorough dataset cleaning.
Features
- Multi-model embedding support: Swin, CLIP, DINO, ResNet.
- Exact duplicate detection using MD5 hashing.
- Semantic similarity detection with deep embeddings and clustering.
- Flexible cleaning modes: path-only, embedding-based, or custom embeddings.
- Clustering to group similar images and identify duplicates.
- Visualization tools for inspecting clusters and embeddings.
- Detailed tabulated reports with removed duplicates, retained images, and thresholds.
- Device support for CPU, CUDA GPU, and Apple MPS.
- Efficient caching system to store and reuse embeddings for faster processing.
Installation
Install CleanFrames easily via pip:
pip install cleanframes
Usage
Basic Cleaning by Path
CleanFrames can process a folder of images, compute embeddings using the default Swin model, and remove duplicates.
from cleanframes import CleanFrame
cleaner = CleanFrame(device='cuda') # or 'cpu', 'mps'
input_folder = "path/to/images"
cleaner.cleanframe(input_folder)
This creates an output folder inside the specified directory (default: frames_cleaned/) containing the unique images after cleaning.
A detailed tabulated report is printed to the console summarizing the cleaning results.
Generate Embeddings and Clean
Generate embeddings separately and then clean based on those embeddings:
from cleanframes import CleanFrame
cleaner = CleanFrame(device='cuda')
input_folder = "path/to/images"
embeddings, paths = cleaner.SwinEmbedding(input_folder)
cleaner.cleanframe(paths, embeddings_list=[("swin", embeddings)], threshold=0.95)
Clean Using Custom Embeddings
Supply your own embeddings (e.g., precomputed vectors) for cleaning:
from cleanframes import CleanFrame
import numpy as np
cleaner = CleanFrame(device='cpu')
image_paths = [...] # list of image file paths
custom_embeddings = np.load("custom_embeddings.npy")
cleaner.cleanframe(image_paths, embeddings_list=[("custom_model", custom_embeddings)], threshold=0.9)
Clustering & Visualization
CleanFrames groups similar images using clustering algorithms on embeddings to identify duplicates and near-duplicates effectively.
You can also visualize clusters and embeddings to inspect dataset structure:
cleaner.visualize_clusters(embeddings, image_paths)
This helps in understanding similarity groups and verifying cleaning results.
Report
After cleaning, CleanFrames prints a comprehensive tabulated report including:
- Number of duplicates removed.
- Images retained.
- Threshold values used.
- Embedding models applied.
- Cluster information.
This report facilitates audit and reproducibility of dataset cleaning.
Supported Models
- Swin: Hierarchical Vision Transformer for image representation.
- CLIP: Contrastive Language-Image Pretraining embeddings.
- DINO: Self-distillation with no labels for visual features.
- ResNet: Classic convolutional neural network embeddings.
Generate embeddings with corresponding methods like cleaner.CLIPEmbedding(), cleaner.DINOEmbedding(), etc.
Device Support
CleanFrames supports multiple devices for accelerated embedding computation:
- CPU: Default fallback.
- CUDA GPU: For NVIDIA GPUs.
- MPS: Apple's Metal Performance Shaders for Macs with Apple Silicon.
Specify device during initialization:
cleaner = CleanFrame(device='mps') # or 'cuda', 'cpu'
Caching System
CleanFrames includes a caching mechanism to save and load embeddings, clusters, and visualizations, reducing redundant computations on repeated runs:
- Automatically caches
.npzfiles per folder and model inside the.cleanframe_cache/directory. - Loads cached embeddings and clusters to speed up cleaning.
- Manages cache files for efficient storage and reuse.
Example:
embeddings, paths = cleaner.SwinEmbedding(input_folder, use_cache=True)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cleanframes-0.2.9.tar.gz.
File metadata
- Download URL: cleanframes-0.2.9.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fd968b2b260bed70ae85c46da3089afbf086928204ff5fb8e6707b6e99f17fd
|
|
| MD5 |
54f8a754ed55ebf51eb3a0f4f8a38fbc
|
|
| BLAKE2b-256 |
6d777c51207b2ec20228c8f9272a201fcac90e0c52138d74ab8fecd22da03729
|
File details
Details for the file cleanframes-0.2.9-py3-none-any.whl.
File metadata
- Download URL: cleanframes-0.2.9-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9a2aa14f16a833ddd4d67917d62904c5e1a360f6ecbb983b9a07deeb74d53f4
|
|
| MD5 |
855e72c680f34e72240ea3e7d600c064
|
|
| BLAKE2b-256 |
6f92d626b0cce58a435b9135732214e286618ee25644d3e78b68d89cb21a3f47
|