A Python-based image processing system that:
- Extracts metadata from images stored in Immich.
- Uses AI models (BLIP, ViT, and DETR) for captioning, scene recognition, and object detection.
- Organizes images into location-based and time-based albums.
- Stores metadata in a PostgreSQL database.
- Uses reverse geocoding to generate meaningful album names.
- Fully logged with debug mode support.
- AI-Powered Image Analysis:
Extracts captions, classifies scenes, and detects objects using state-of-the-art models. - Automatic Album Creation:
Groups images into albums based on location and time. - Reverse Geocoding:
Converts GPS coordinates to city/country names for improved album naming. - PostgreSQL Integration:
Stores all processed metadata in a relational database. - Robust Logging:
Logs events to both the console and a file with adjustable debug levels. - Error Handling:
Ensures the process continues gracefully even if errors occur.
git clone https://github.com/rlombard/photo-analyzer.git
cd photo-analyzerpip install -r requirements.txtEdit the config.py file to set:
- Immich API credentials
- Database connection details
- AI model selections
Example configuration:
# IMMICH API Configuration
IMMICH_URL = "http://192.168.0.217:2283"
API_KEY = "your_immich_api_key"
# PostgreSQL Database Configuration
DB_CONFIG = {
"dbname": "immich_db",
"user": "your_db_user",
"password": "your_db_password",
"host": "localhost",
"port": "5432"
}
# Reverse Geocoding API
GEOCODING_URL = "https://nominatim.openstreetmap.org/reverse"
# Model Selection
MODEL_BLIP = "Salesforce/blip-image-captioning-base"
MODEL_SCENE = "nateraw/vit-base-beans"
MODEL_OBJECTS = "facebook/detr-resnet-50"
# Model Cache Directory
MODEL_CACHE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "models"))
# Clustering Parameters
TIME_CLUSTERING_EPS = 86400 # 1 day in seconds
TIME_CLUSTERING_MIN_SAMPLES = 3 # Minimum images per clusterpython main.pyThis command will:
- Fetch new images from Immich.
- Process them to extract metadata.
- Organize them into albums based on time and location.
python main.py --rerunForces reprocessing of all images, even if they've been processed before.
python main.py --image-id <IMAGE_ID>Processes a single image identified by its Immich ID.
python main.py --debugActivates detailed logging to help with troubleshooting.
python main.py --list-albumsDisplays a list of current albums in Immich.
The project includes comprehensive unit tests using pytest, covering:
- AI-powered analysis (BLIP, Scene Recognition, Object Detection)
- Database connection handling
- Immich API interactions (fetching images, uploading metadata)
- Reverse geocoding
- Album name formatting
pip install pytest pillow requestspytest tests/pytest tests/tests.pyTo see detailed logging and output for debugging, run:
pytest -v tests/pytest --cov=your_project_directoryphoto-analyzer/
βββ main.py # Entry point
βββ requirements.txt # Dependencies
βββ README.md # Project Documentation
βββ config.py # Configuration (API, DB, Models)
β
βββ database/
β βββ connection.py # Database connection & table creation
β βββ queries.py # Database queries for metadata
β
βββ immich_api/
β βββ client.py # Fetches images from Immich
β βββ uploader.py # Creates albums and adds images
β
βββ analysis/
β βββ blip.py # Image captioning
β βββ scene.py # Scene classification
β βββ object.py # Object detection
β
βββ clustering/
β βββ time_based.py # Clusters images by time
β βββ location_based.py # Clusters images by location
β
βββ utils/
β βββ download_models.py # Model downloader
β βββ geocode.py # Reverse geocoding
β βββ helpers.py # Helper functions
β βββ logger.py # Logging configuration (console & file)
β βββ model_loader.py # Centralized model loading
β
βββ tests/
β βββ test_analysis.py # Unit tests for analysis modules
β βββ test_image.jpg # Sample test image
β
βββ logs/
βββ app.log # Log file for debugging
- Database connection pooling implemented for efficiency.
- AI model loading refactored to
utils/model_loader.py. - Clustering parameters now configurable via
config.py. - Utility functions centralized in
utils/helpers.py. - Unit tests added using
unittest.mockand a local test image.
This software is released under the Unlicense.
This means:
- The code is fully open-source and can be used by anyone for any purpose.
- There are no restrictions on how you can modify, distribute, or commercialize the software.
- The software is provided as-is, without any warranty or liability.
For more details, see: https://unlicense.org
π₯ Automate your image processing with AI-powered metadata and smart albums! π