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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: mit
|
3 |
tags:
|
4 |
+
- image-quality-assessment
|
5 |
+
- computer-vision
|
6 |
- brisque
|
7 |
+
- aesthetic-predictor
|
8 |
- clip
|
9 |
- fusion
|
10 |
+
- pytorch
|
11 |
+
- image-classification
|
12 |
+
language:
|
13 |
+
- en
|
14 |
+
pipeline_tag: image-classification
|
15 |
+
library_name: pytorch
|
16 |
+
datasets:
|
17 |
+
- spaq
|
18 |
+
metrics:
|
19 |
+
- correlation
|
20 |
+
- r2
|
21 |
+
- mae
|
22 |
+
base_model:
|
23 |
+
- openai/clip-vit-base-patch32
|
24 |
---
|
25 |
|
26 |
+
# Image Quality Fusion Model
|
27 |
+
|
28 |
+
A multi-modal image quality assessment system that combines BRISQUE, Aesthetic Predictor, and CLIP features to predict human-like quality judgments on a 1-10 scale.
|
29 |
+
|
30 |
+
## 🎯 Model Description
|
31 |
+
|
32 |
+
This model fuses three complementary approaches to comprehensive image quality assessment:
|
33 |
+
|
34 |
+
- **🔧 BRISQUE (OpenCV)**: Technical quality assessment detecting blur, noise, compression artifacts, and distortions
|
35 |
+
- **🎨 Aesthetic Predictor (LAION)**: Visual appeal assessment using CLIP ViT-B-32 features trained on human aesthetic ratings
|
36 |
+
- **🧠 CLIP (OpenAI)**: Semantic understanding and high-level feature extraction for content awareness
|
37 |
+
|
38 |
+
The fusion network learns optimal weights to combine these diverse quality signals, producing human-like quality judgments that correlate strongly with subjective assessments.
|
39 |
+
|
40 |
+
## 🚀 Quick Start
|
41 |
+
|
42 |
+
### Installation
|
43 |
+
|
44 |
+
```bash
|
45 |
+
pip install torch torchvision huggingface_hub opencv-python pillow open-clip-torch
|
46 |
+
```
|
47 |
+
|
48 |
+
### Basic Usage
|
49 |
+
|
50 |
+
```python
|
51 |
+
from huggingface_hub import PyTorchModelHubMixin
|
52 |
+
from PIL import Image
|
53 |
+
|
54 |
+
# Load the model
|
55 |
+
model = PyTorchModelHubMixin.from_pretrained("matthewyuan/image-quality-fusion")
|
56 |
+
|
57 |
+
# Predict quality for a single image
|
58 |
+
quality_score = model.predict_quality("path/to/your/image.jpg")
|
59 |
+
print(f"Image quality: {quality_score:.2f}/10")
|
60 |
+
|
61 |
+
# Batch prediction
|
62 |
+
image_paths = ["image1.jpg", "image2.jpg", "image3.jpg"]
|
63 |
+
scores = model.predict_batch(image_paths)
|
64 |
+
for path, score in zip(image_paths, scores):
|
65 |
+
print(f"{path}: {score:.2f}/10")
|
66 |
+
```
|
67 |
+
|
68 |
+
### Advanced Usage
|
69 |
+
|
70 |
+
```python
|
71 |
+
# Load with PIL Image
|
72 |
+
from PIL import Image
|
73 |
+
image = Image.open("photo.jpg")
|
74 |
+
score = model.predict_quality(image)
|
75 |
+
|
76 |
+
# Works with different input formats
|
77 |
+
import numpy as np
|
78 |
+
image_array = np.array(image)
|
79 |
+
score = model.predict_quality(image_array)
|
80 |
+
|
81 |
+
# Get model information
|
82 |
+
info = model.get_model_info()
|
83 |
+
print(f"Model: {info['name']} v{info['version']}")
|
84 |
+
print(f"Performance: Correlation = {info['performance']['correlation']}")
|
85 |
+
```
|
86 |
+
|
87 |
+
## 📊 Performance Metrics
|
88 |
+
|
89 |
+
Evaluated on the SPAQ dataset (11,125 smartphone images with human quality ratings):
|
90 |
+
|
91 |
+
| Metric | Value | Description |
|
92 |
+
|--------|-------|-------------|
|
93 |
+
| **Pearson Correlation** | 0.520 | Correlation with human judgments |
|
94 |
+
| **R² Score** | 0.250 | Coefficient of determination |
|
95 |
+
| **Mean Absolute Error** | 1.41 | Average prediction error (1-10 scale) |
|
96 |
+
| **Root Mean Square Error** | 1.69 | RMS prediction error |
|
97 |
+
|
98 |
+
### Comparison with Individual Components
|
99 |
+
|
100 |
+
| Method | Correlation | R² Score | MAE |
|
101 |
+
|--------|-------------|----------|-----|
|
102 |
+
| **Fusion Model** | **0.520** | **0.250** | **1.41** |
|
103 |
+
| BRISQUE Only | 0.31 | 0.12 | 2.1 |
|
104 |
+
| Aesthetic Only | 0.41 | 0.18 | 1.8 |
|
105 |
+
| CLIP Only | 0.28 | 0.09 | 2.3 |
|
106 |
+
|
107 |
+
*The fusion approach significantly outperforms individual components.*
|
108 |
+
|
109 |
+
## 🏗️ Model Architecture
|
110 |
+
|
111 |
+
```
|
112 |
+
Input Image (RGB)
|
113 |
+
├── OpenCV BRISQUE → Technical Quality Score (0-100, normalized)
|
114 |
+
├── LAION Aesthetic → Aesthetic Score (0-10, normalized)
|
115 |
+
└── OpenAI CLIP-B32 → Semantic Features (512-dimensional)
|
116 |
+
↓
|
117 |
+
Feature Fusion Network
|
118 |
+
┌─────────────────────────┐
|
119 |
+
│ BRISQUE: 1D → 64 → 128 │
|
120 |
+
│ Aesthetic: 1D → 64 → 128│
|
121 |
+
│ CLIP: 512D → 256 → 128 │
|
122 |
+
└─────────────────────────┘
|
123 |
+
↓ (concat)
|
124 |
+
Deep Fusion Layers (384D → 256D → 128D → 1D)
|
125 |
+
Dropout (0.3) + ReLU activations
|
126 |
+
↓
|
127 |
+
Human-like Quality Score (1.0 - 10.0)
|
128 |
+
```
|
129 |
+
|
130 |
+
### Technical Details
|
131 |
+
|
132 |
+
- **Input Resolution**: Any size (resized to 224×224 for CLIP)
|
133 |
+
- **Architecture**: Feed-forward neural network with residual connections
|
134 |
+
- **Activation Functions**: ReLU for hidden layers, Linear for output
|
135 |
+
- **Regularization**: Dropout (0.3), Early stopping
|
136 |
+
- **Output Range**: 1.0 - 10.0 (human rating scale)
|
137 |
+
- **Parameters**: ~2.1M total parameters
|
138 |
+
|
139 |
+
## 🔬 Training Details
|
140 |
+
|
141 |
+
### Dataset
|
142 |
+
- **Name**: SPAQ (Smartphone Photography Attribute and Quality)
|
143 |
+
- **Size**: 11,125 high-resolution smartphone images
|
144 |
+
- **Annotations**: Human quality ratings (1-10 scale, 5+ annotators per image)
|
145 |
+
- **Split**: 80% train, 10% validation, 10% test
|
146 |
+
- **Domain**: Consumer smartphone photography
|
147 |
+
|
148 |
+
### Training Configuration
|
149 |
+
- **Framework**: PyTorch 2.0+ with MPS acceleration (M1 optimized)
|
150 |
+
- **Optimizer**: AdamW (lr=1e-3, weight_decay=1e-4)
|
151 |
+
- **Batch Size**: 128 (optimized for 32GB unified memory)
|
152 |
+
- **Epochs**: 50 with early stopping (patience=10)
|
153 |
+
- **Loss Function**: Mean Squared Error (MSE)
|
154 |
+
- **Learning Rate Schedule**: ReduceLROnPlateau (factor=0.5, patience=5)
|
155 |
+
- **Hardware**: M1 MacBook Pro (32GB RAM)
|
156 |
+
- **Training Time**: ~1 hour (with feature caching)
|
157 |
+
|
158 |
+
### Optimization Techniques
|
159 |
+
- **Mixed Precision Training**: MPS autocast for M1 acceleration
|
160 |
+
- **Feature Caching**: Pre-computed embeddings for 20-30x speedup
|
161 |
+
- **Data Loading**: Optimized DataLoader (6-8 workers, memory pinning)
|
162 |
+
- **Memory Management**: Garbage collection every 10 batches
|
163 |
+
- **Preprocessing Pipeline**: Parallel BRISQUE computation
|
164 |
+
|
165 |
+
## 📱 Use Cases
|
166 |
+
|
167 |
+
### Professional Applications
|
168 |
+
- **Content Management**: Automatic quality filtering for large image databases
|
169 |
+
- **Social Media**: Real-time quality assessment for user uploads
|
170 |
+
- **E-commerce**: Product image quality validation
|
171 |
+
- **Digital Asset Management**: Automated quality scoring for photo libraries
|
172 |
+
|
173 |
+
### Research Applications
|
174 |
+
- **Image Quality Research**: Benchmark for perceptual quality metrics
|
175 |
+
- **Dataset Curation**: Quality-based dataset filtering and ranking
|
176 |
+
- **Human Perception Studies**: Computational model of aesthetic judgment
|
177 |
+
- **Multi-modal Learning**: Example of successful feature fusion
|
178 |
+
|
179 |
+
### Creative Applications
|
180 |
+
- **Photography Tools**: Automated photo rating and selection
|
181 |
+
- **Mobile Apps**: Real-time quality feedback during capture
|
182 |
+
- **Photo Editing**: Quality-guided automatic enhancement
|
183 |
+
- **Portfolio Management**: Intelligent photo organization
|
184 |
+
|
185 |
+
## ⚠️ Limitations and Biases
|
186 |
+
|
187 |
+
### Model Limitations
|
188 |
+
- **Domain Specificity**: Trained primarily on smartphone photography
|
189 |
+
- **Resolution Dependency**: Performance may vary with very low/high resolution images
|
190 |
+
- **Cultural Bias**: Aesthetic preferences may reflect training data demographics
|
191 |
+
- **Temporal Bias**: Training data from specific time period may not reflect evolving preferences
|
192 |
+
|
193 |
+
### Technical Limitations
|
194 |
+
- **BRISQUE Scope**: May not capture all types of technical degradation
|
195 |
+
- **CLIP Bias**: Inherits biases from CLIP's training data
|
196 |
+
- **Aesthetic Subjectivity**: Individual preferences vary significantly
|
197 |
+
- **Computational Requirements**: Requires GPU for optimal inference speed
|
198 |
+
|
199 |
+
### Recommended Usage
|
200 |
+
- **Validation**: Always validate on your specific domain before production use
|
201 |
+
- **Human Oversight**: Use as a tool to assist, not replace, human judgment
|
202 |
+
- **Bias Mitigation**: Consider diverse evaluation datasets
|
203 |
+
- **Performance Monitoring**: Monitor performance on your specific use case
|
204 |
+
|
205 |
+
## 📚 Citation
|
206 |
+
|
207 |
+
If you use this model in your research, please cite:
|
208 |
+
|
209 |
+
```bibtex
|
210 |
+
@misc{image-quality-fusion-2024,
|
211 |
+
title={Image Quality Fusion: Multi-Modal Assessment with BRISQUE, Aesthetic, and CLIP Features},
|
212 |
+
author={Matthew Yuan},
|
213 |
+
year={2024},
|
214 |
+
howpublished={\url{https://huggingface.co/matthewyuan/image-quality-fusion}},
|
215 |
+
note={Trained on SPAQ dataset, deployed via GitHub Actions CI/CD}
|
216 |
+
}
|
217 |
+
```
|
218 |
+
|
219 |
+
## 🔗 Related Work
|
220 |
+
|
221 |
+
### Datasets
|
222 |
+
- [SPAQ Dataset](https://github.com/h4nwei/SPAQ) - Smartphone Photography Attribute and Quality
|
223 |
+
- [AVA Dataset](https://github.com/mtobeiyf/ava_downloader) - Aesthetic Visual Analysis
|
224 |
+
- [LIVE IQA](https://live.ece.utexas.edu/research/Quality/) - Laboratory for Image & Video Engineering
|
225 |
+
|
226 |
+
### Models
|
227 |
+
- [LAION Aesthetic Predictor](https://github.com/LAION-AI/aesthetic-predictor) - Aesthetic scoring model
|
228 |
+
- [OpenCLIP](https://github.com/mlfoundations/open_clip) - Open source CLIP implementation
|
229 |
+
- [BRISQUE](https://learnopencv.com/image-quality-assessment-brisque/) - Blind/Referenceless Image Spatial Quality Evaluator
|
230 |
+
|
231 |
+
## 🛠️ Development
|
232 |
+
|
233 |
+
### Local Development
|
234 |
+
```bash
|
235 |
+
# Clone repository
|
236 |
+
git clone https://github.com/mattkyuan/image-quality-fusion.git
|
237 |
+
cd image-quality-fusion
|
238 |
+
|
239 |
+
# Install dependencies
|
240 |
+
pip install -r requirements.txt
|
241 |
+
|
242 |
+
# Run training
|
243 |
+
python src/image_quality_fusion/training/train_fusion.py \
|
244 |
+
--image_dir data/images \
|
245 |
+
--annotations data/annotations.csv \
|
246 |
+
--prepare_data \
|
247 |
+
--epochs 50
|
248 |
+
```
|
249 |
+
|
250 |
+
### CI/CD Pipeline
|
251 |
+
This model is automatically deployed via GitHub Actions:
|
252 |
+
- **Training Pipeline**: Automated model training on code changes
|
253 |
+
- **Deployment Pipeline**: Automatic HF Hub deployment on model updates
|
254 |
+
- **Testing Pipeline**: Comprehensive model validation and testing
|
255 |
+
|
256 |
+
## 📄 License
|
257 |
+
|
258 |
+
This project is licensed under the MIT License - see the [LICENSE](https://github.com/mattkyuan/image-quality-fusion/blob/main/LICENSE) file for details.
|
259 |
+
|
260 |
+
## 🙏 Acknowledgments
|
261 |
+
|
262 |
+
- **SPAQ Dataset**: H4nwei et al. for the comprehensive smartphone photography dataset
|
263 |
+
- **LAION**: For the aesthetic predictor model and training methodology
|
264 |
+
- **OpenAI**: For CLIP model architecture and pre-trained weights
|
265 |
+
- **OpenCV**: For BRISQUE implementation and computer vision tools
|
266 |
+
- **Hugging Face**: For model hosting and deployment infrastructure
|
267 |
+
- **PyTorch Team**: For the deep learning framework and MPS acceleration
|
268 |
+
|
269 |
+
## 📞 Contact
|
270 |
+
|
271 |
+
- **Repository**: [github.com/mattkyuan/image-quality-fusion](https://github.com/mattkyuan/image-quality-fusion)
|
272 |
+
- **Issues**: [GitHub Issues](https://github.com/mattkyuan/image-quality-fusion/issues)
|
273 |
+
- **Hugging Face**: [matthewyuan/image-quality-fusion](https://huggingface.co/matthewyuan/image-quality-fusion)
|
274 |
+
|
275 |
+
---
|
276 |
+
|
277 |
+
*This model was trained and deployed using automated CI/CD pipelines for reproducible ML workflows.*
|