Automation Lab 2024-03-07

AI Photo Organizer: Auto-Tag Your Images

Estimated Time
15 MIN
Environment
Python 3.x, PyTorch, Pillow

Tired of having 10,000 photos in one folder? We'll use a pre-trained ResNet model to look at your images and move them into categorized folders automatically.

 

Code Snippet
import torch
import torchvision.models as models
import torchvision.transforms as transforms
from PIL import Image
import os
import shutil

# Load AI Model
model = models.resnet18(pretrained=True)
model.eval()

def classify_image(path):
    # ... Image processing logic ...
    # Returns label like 'Golden Retriever'
    pass

for img in os.listdir('./unsorted'):
    label = classify_image(os.path.join('./unsorted', img))
    dest_dir = f'./sorted/{label}'
    os.makedirs(dest_dir, exist_ok=True)
    shutil.move(os.path.join('./unsorted', img), os.path.join(dest_dir, img))

Download Full Automation Pack

Get all source codes, advanced configurations, and exclusive troubleshooting guides.

FREE DOWNLOAD

Secure Verification Required