Spaces:
Sleeping
Sleeping
File size: 3,441 Bytes
6a6d363 fcd8868 6a6d363 fcd8868 6a6d363 fcd8868 79b6993 fcd8868 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | ---
title: ColorGradingAE
emoji: π¨
colorFrom: purple
colorTo: indigo
sdk: gradio
sdk_version: 6.20.0
python_version: '3.13'
app_file: gradio_demo2.py
pinned: false
license: mit
---
# ColorGradingAE - Contrastive Color Grade AI
An AI-powered color grading tool that uses contrastive learning with an encoder-decoder architecture to automatically analyze and apply professional color grading to images.
## Features
- π¨ **Automatic Color Analysis**: Extracts color features from images using HSV color space analysis
- π§ **Contrastive Learning Model**: Uses encoder-decoder architecture trained on color grading patterns
- π― **Zone-based Processing**: Analyzes shadows, midtones, and highlights separately
- π **Interactive Web Interface**: Easy-to-use Gradio interface for real-time color grading
- π **GPU Acceleration**: CUDA support for fast inference
## Installation
Clone the repository and install dependencies:
```bash
pip install -r requirements.txt
```
### Requirements
- Python 3.13+
- PyTorch with CUDA support (or CPU)
- OpenCV
- Gradio
- Pillow
- NumPy
## Usage
### Web Interface
Run the interactive Gradio demo:
```bash
python gradio_demo.py
```
This launches a web interface where you can upload images and apply color grading in real-time.
### Python API
Use the color grading functions programmatically:
```python
from inference import generate_grade, apply_grade
# Generate color grade parameters for an image
grade = generate_grade("input.jpg")
# Apply the generated grade to an image
output = apply_grade("input.jpg", grade)
```
### Training
To train or fine-tune the model on your own images:
```bash
python trainer.py
```
Place your training images in the `data/images/` directory.
## Project Structure
```
βββ gradio_demo.py # Main Gradio web interface
βββ gradio_demo2.py # Alternative demo interface
βββ inference.py # Color grading inference functions
βββ trainer.py # Model training and feature extraction
βββ downloader.py # Utility for downloading images/models
βββ encoder.pt # Pre-trained encoder model
βββ decoder.pt # Pre-trained decoder model
βββ data/
β βββ images/ # Training images directory
βββ flagged/ # Gradio flagged/saved results
```
## How It Works
1. **Feature Extraction**: Analyzes image color distributions across HSV channels in 16 hue bins
2. **Zone Analysis**: Processes shadows, midtones, and highlights separately for more nuanced grading
3. **Encoding**: Compresses color features using the trained encoder
4. **Decoding**: Generates color grading parameters using the trained decoder
5. **Application**: Applies the generated grade to produce the final color-graded output
## Model Architecture
- **Encoder**: Compresses color feature vectors into latent space
- **Decoder**: Reconstructs color grading parameters from latent vectors
- **Training**: Uses contrastive learning to learn meaningful color relationships
## Performance
- Supports GPU acceleration via CUDA for fast inference
- Falls back to CPU if GPU unavailable
- Real-time processing suitable for interactive applications
## License
MIT License - See LICENSE file for details
---
For more information, check out the [Hugging Face documentation](https://huggingface.co/docs/hub/spaces-config-reference)
|