This Python script organizes images and videos by date and event, renames them systematically, detects duplicates (exact and near), and uses AI to label images.
- 🗃️ Organizes files into
/destination/YYYY/MM-DD/EventName - 🧠 Labels images using a pretrained ResNet-50 model
- 🔒 Detects exact duplicates using SHA-256
- 🧬 Detects near-duplicates (images & videos) using perceptual hashing
- 📝 Stores rename counters in
organize_config.json - 🎥 Uses multiple video frames to improve duplicate accuracy
- 🛠️ Dry run mode to test before going live
- 🚀 Ski treating same images on different batches storing the list of processed hashes
pip install pillow torchvision timm exifread imagehash opencv-python pyheifOn macOS, you may also need:
brew install libheifPut all your unsorted media in the /source folder.
Run the script:
python organize_media.pyor run
make runSorted files will be moved to /destination.
/destination/
├── 2024-
│ └── 03-10/
│ └── Birthday/
│ ├── pict00001_dog.jpg
│ └── vid00001_party.mp4
├── duplicated/
├── near_duplicated/
└── noevaluate/
📦 Configuration The script stores its counters in organize_config.json, so it can resume where it left off on the next run.
After the first run, organize_config.json is created:
{
"pic_counter": 34,
"vid_counter": 12
}This ensures that counters continue across multiple runs.
Images are classified with ResNet-50 using PyTorch + TIMM. The label is added to the filename automatically.
Example:
Original: IMG_1234.JPG
Renamed: pict00012_golden_retriever.jpg
- Exact duplicates: Detected with
SHA-256file hash - Near-duplicates:
- Images:
imagehash.phash - Videos: Sample 5 frames → compute average perceptual hash
- Images:
These are moved to:
/destination/exact_duplicated/
/destination/near_duplicated/
- Drop unsorted media into
/source - Run the script:
python organize_media.py- Organized files will be moved to
/destination
- Python 3.10+
- macOS and Linux
- NVIDIA CUDA GPU (optional for faster AI classification)
MIT License
Feel free to fork and contribute! Ideas, PRs, and issues are welcome.
Happy organizing! 🧹📁📸
Developed by Nynor-code.