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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# TRIQA Hugging Face Demo - Complete Setup Guide
|
| 2 |
+
|
| 3 |
+
## π Overview
|
| 4 |
+
|
| 5 |
+
This guide documents the complete process of creating and deploying a TRIQA Image Quality Assessment demo on Hugging Face Spaces, including all troubleshooting steps and solutions.
|
| 6 |
+
|
| 7 |
+
## π― What We Built
|
| 8 |
+
|
| 9 |
+
- **Web Demo**: Interactive Gradio interface for image quality assessment
|
| 10 |
+
- **Space URL**: https://huggingface.co/spaces/S-Rajesh/triqa-iqa
|
| 11 |
+
- **Features**: Upload images, get quality scores (1-5 scale), sample images, paper links
|
| 12 |
+
- **Architecture**: ConvNeXt-based content-aware and quality-aware feature extraction
|
| 13 |
+
|
| 14 |
+
## π File Structure
|
| 15 |
+
|
| 16 |
+
```
|
| 17 |
+
huggingface_demo/
|
| 18 |
+
βββ app.py # Main Gradio application
|
| 19 |
+
βββ README.md # Space description (Hugging Face format)
|
| 20 |
+
βββ requirements.txt # Python dependencies
|
| 21 |
+
βββ package.json # Node.js configuration
|
| 22 |
+
βββ convnext_original.py # Original ConvNeXt model
|
| 23 |
+
βββ convnext_finetune.py # Fine-tuned ConvNeXt model
|
| 24 |
+
βββ sample_image/ # Sample images for testing
|
| 25 |
+
β βββ 233045618.jpg
|
| 26 |
+
β βββ 25239707.jpg
|
| 27 |
+
β βββ 44009500.jpg
|
| 28 |
+
β βββ 5129172.jpg
|
| 29 |
+
β βββ 85119046.jpg
|
| 30 |
+
βββ test_demo.py # Local testing script
|
| 31 |
+
βββ upload_to_space.py # Python upload script
|
| 32 |
+
βββ upload_with_git.sh # Git upload script
|
| 33 |
+
βββ QUICK_START.md # Quick start guide
|
| 34 |
+
βββ UPLOAD_METHODS.md # Upload methods documentation
|
| 35 |
+
βββ HUGGINGFACE_SETUP.md # Detailed setup guide
|
| 36 |
+
βββ COMPLETE_SETUP_GUIDE.md # This file
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
## π Step-by-Step Setup Process
|
| 40 |
+
|
| 41 |
+
### Step 1: Create Hugging Face Space
|
| 42 |
+
|
| 43 |
+
1. **Go to Hugging Face Spaces**: https://huggingface.co/spaces
|
| 44 |
+
2. **Click "Create new Space"**
|
| 45 |
+
3. **Fill in the details**:
|
| 46 |
+
- **Space name**: `triqa-iqa` (or your preferred name)
|
| 47 |
+
- **License**: MIT
|
| 48 |
+
- **SDK**: Gradio
|
| 49 |
+
- **Hardware**: CPU (or GPU if available)
|
| 50 |
+
- **Visibility**: Public
|
| 51 |
+
|
| 52 |
+
### Step 2: Prepare Files
|
| 53 |
+
|
| 54 |
+
#### Core Application Files:
|
| 55 |
+
- `app.py` - Main Gradio application
|
| 56 |
+
- `README.md` - Space description (with proper metadata)
|
| 57 |
+
- `requirements.txt` - Python dependencies
|
| 58 |
+
- `package.json` - Node.js configuration
|
| 59 |
+
|
| 60 |
+
#### Model Architecture Files:
|
| 61 |
+
- `convnext_original.py` - Original ConvNeXt model
|
| 62 |
+
- `convnext_finetune.py` - Fine-tuned ConvNeXt model
|
| 63 |
+
|
| 64 |
+
#### Sample Images:
|
| 65 |
+
- `sample_image/` directory with 5 sample images
|
| 66 |
+
|
| 67 |
+
### Step 3: Upload Files
|
| 68 |
+
|
| 69 |
+
#### Method 1: Python CLI (Used in this project)
|
| 70 |
+
```bash
|
| 71 |
+
# Login to Hugging Face
|
| 72 |
+
huggingface-cli login
|
| 73 |
+
|
| 74 |
+
# Run upload script
|
| 75 |
+
python upload_to_space.py
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
#### Method 2: Git (Alternative)
|
| 79 |
+
```bash
|
| 80 |
+
# Clone your space
|
| 81 |
+
git clone https://huggingface.co/spaces/your-username/triqa-iqa
|
| 82 |
+
cd triqa-iqa
|
| 83 |
+
|
| 84 |
+
# Copy files
|
| 85 |
+
cp ../huggingface_demo/* .
|
| 86 |
+
cp -r ../huggingface_demo/sample_image .
|
| 87 |
+
|
| 88 |
+
# Commit and push
|
| 89 |
+
git add . && git commit -m "Add TRIQA demo" && git push
|
| 90 |
+
```
|
| 91 |
+
|
| 92 |
+
#### Method 3: Web Interface
|
| 93 |
+
- Go to your space on Hugging Face
|
| 94 |
+
- Click "Files" tab
|
| 95 |
+
- Drag and drop files
|
| 96 |
+
|
| 97 |
+
### Step 4: Upload Model Files
|
| 98 |
+
|
| 99 |
+
**IMPORTANT**: Model files must be uploaded separately due to size:
|
| 100 |
+
|
| 101 |
+
1. **Download from Box**: https://utexas.box.com/s/8aw6axc2lofouja65uc726lca8b1cduf
|
| 102 |
+
2. **Create directories** in your space:
|
| 103 |
+
- `feature_models/`
|
| 104 |
+
- `Regression_Models/`
|
| 105 |
+
3. **Upload model files**:
|
| 106 |
+
- `feature_models/convnext_tiny_22k_224.pth` (170MB)
|
| 107 |
+
- `feature_models/triqa_quality_aware.pth` (107MB)
|
| 108 |
+
- `Regression_Models/KonIQ_scaler.save`
|
| 109 |
+
- `Regression_Models/KonIQ_TRIQA.save` (111MB)
|
| 110 |
+
|
| 111 |
+
## π§ Troubleshooting & Solutions
|
| 112 |
+
|
| 113 |
+
### Issue 1: Short Description Too Long
|
| 114 |
+
**Error**: `"short_description" length must be less than or equal to 60 characters long`
|
| 115 |
+
|
| 116 |
+
**Solution**:
|
| 117 |
+
```yaml
|
| 118 |
+
# In README.md metadata
|
| 119 |
+
short_description: TRIQA-IQA # 9 characters - under limit
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
**Original**: `Image Quality Assessment using ConvNeXt features` (78 characters)
|
| 123 |
+
**Fixed**: `TRIQA-IQA` (9 characters)
|
| 124 |
+
|
| 125 |
+
### Issue 2: Missing timm Module
|
| 126 |
+
**Error**: `ModuleNotFoundError: No module named 'timm'`
|
| 127 |
+
|
| 128 |
+
**Solution**: Add `timm` to requirements.txt
|
| 129 |
+
```txt
|
| 130 |
+
gradio>=4.0.0
|
| 131 |
+
torch>=1.8.0
|
| 132 |
+
torchvision>=0.9.0
|
| 133 |
+
timm>=0.6.0 # Added this
|
| 134 |
+
pillow>=8.0.0
|
| 135 |
+
numpy>=1.19.0
|
| 136 |
+
scikit-learn>=0.24.0
|
| 137 |
+
```
|
| 138 |
+
|
| 139 |
+
### Issue 3: Model Files Not Found
|
| 140 |
+
**Error**: `FileNotFoundError: [Errno 2] No such file or directory: 'feature_models/...'`
|
| 141 |
+
|
| 142 |
+
**Solution**:
|
| 143 |
+
1. Download model files from Box
|
| 144 |
+
2. Create required directories in space
|
| 145 |
+
3. Upload model files to correct locations
|
| 146 |
+
|
| 147 |
+
### Issue 4: Build Failures
|
| 148 |
+
**Common Causes**:
|
| 149 |
+
- Missing dependencies in requirements.txt
|
| 150 |
+
- Incorrect file paths
|
| 151 |
+
- Syntax errors in code
|
| 152 |
+
|
| 153 |
+
**Solution**:
|
| 154 |
+
1. Check space logs for specific errors
|
| 155 |
+
2. Verify all dependencies are listed
|
| 156 |
+
3. Test locally first: `python app.py`
|
| 157 |
+
|
| 158 |
+
## π Key Files Explained
|
| 159 |
+
|
| 160 |
+
### app.py
|
| 161 |
+
- **Purpose**: Main Gradio web interface
|
| 162 |
+
- **Key Features**:
|
| 163 |
+
- Image upload interface
|
| 164 |
+
- Quality prediction function
|
| 165 |
+
- Sample images display
|
| 166 |
+
- Paper links and citation
|
| 167 |
+
- Error handling for missing models
|
| 168 |
+
|
| 169 |
+
### README.md
|
| 170 |
+
- **Purpose**: Space description and metadata
|
| 171 |
+
- **Key Sections**:
|
| 172 |
+
- YAML frontmatter (title, emoji, colors, SDK)
|
| 173 |
+
- Project description
|
| 174 |
+
- Usage instructions
|
| 175 |
+
- Model file requirements
|
| 176 |
+
- Citation and paper links
|
| 177 |
+
|
| 178 |
+
### requirements.txt
|
| 179 |
+
- **Purpose**: Python dependencies
|
| 180 |
+
- **Key Dependencies**:
|
| 181 |
+
- `gradio>=4.0.0` - Web interface
|
| 182 |
+
- `torch>=1.8.0` - Deep learning framework
|
| 183 |
+
- `timm>=0.6.0` - Model architectures
|
| 184 |
+
- `scikit-learn>=0.24.0` - Regression models
|
| 185 |
+
|
| 186 |
+
### convnext_original.py & convnext_finetune.py
|
| 187 |
+
- **Purpose**: Model architectures
|
| 188 |
+
- **convnext_original.py**: Content-aware features
|
| 189 |
+
- **convnext_finetune.py**: Quality-aware features
|
| 190 |
+
|
| 191 |
+
## π― Demo Features
|
| 192 |
+
|
| 193 |
+
### User Interface:
|
| 194 |
+
- **Image Upload**: Drag & drop or click to upload
|
| 195 |
+
- **Quality Assessment**: Click button to get score
|
| 196 |
+
- **Sample Images**: Pre-loaded examples for testing
|
| 197 |
+
- **Results Display**: Quality score (1-5 scale)
|
| 198 |
+
- **Paper Links**: Direct links to research papers
|
| 199 |
+
- **Citation**: Proper BibTeX citation
|
| 200 |
+
|
| 201 |
+
### Technical Features:
|
| 202 |
+
- **Multi-scale Processing**: Original + half-size images
|
| 203 |
+
- **Hook-based Feature Extraction**: Same as original code
|
| 204 |
+
- **Error Handling**: Graceful handling of missing files
|
| 205 |
+
- **Responsive Design**: Works on desktop and mobile
|
| 206 |
+
|
| 207 |
+
## π Upload Methods Comparison
|
| 208 |
+
|
| 209 |
+
| Method | Pros | Cons | Best For |
|
| 210 |
+
|--------|------|------|----------|
|
| 211 |
+
| Python CLI | Automated, handles multiple files | Requires Python setup | Multiple files, automation |
|
| 212 |
+
| Git | Version control, familiar | Manual steps | Developers, version control |
|
| 213 |
+
| Web Interface | Simple, no setup | Manual, one file at a time | Single files, quick uploads |
|
| 214 |
+
|
| 215 |
+
## π Testing & Validation
|
| 216 |
+
|
| 217 |
+
### Local Testing:
|
| 218 |
+
```bash
|
| 219 |
+
# Test file structure
|
| 220 |
+
python test_demo.py
|
| 221 |
+
|
| 222 |
+
# Test app locally
|
| 223 |
+
python app.py
|
| 224 |
+
```
|
| 225 |
+
|
| 226 |
+
### Space Testing:
|
| 227 |
+
1. Check build logs for errors
|
| 228 |
+
2. Upload sample image
|
| 229 |
+
3. Verify quality score output
|
| 230 |
+
4. Test all sample images
|
| 231 |
+
|
| 232 |
+
## π Dependencies & Versions
|
| 233 |
+
|
| 234 |
+
### Python Dependencies:
|
| 235 |
+
- `gradio>=4.0.0` - Web interface framework
|
| 236 |
+
- `torch>=1.8.0` - PyTorch deep learning
|
| 237 |
+
- `torchvision>=0.9.0` - Computer vision utilities
|
| 238 |
+
- `timm>=0.6.0` - Model architectures
|
| 239 |
+
- `pillow>=8.0.0` - Image processing
|
| 240 |
+
- `numpy>=1.19.0` - Numerical computing
|
| 241 |
+
- `scikit-learn>=0.24.0` - Machine learning
|
| 242 |
+
|
| 243 |
+
### System Requirements:
|
| 244 |
+
- Python 3.8+
|
| 245 |
+
- CUDA GPU (recommended) or CPU
|
| 246 |
+
- 4GB+ RAM (for model loading)
|
| 247 |
+
|
| 248 |
+
## π¨ Common Pitfalls & Solutions
|
| 249 |
+
|
| 250 |
+
### 1. File Size Limits
|
| 251 |
+
- **Issue**: Model files too large for regular upload
|
| 252 |
+
- **Solution**: Use Git LFS or upload via web interface
|
| 253 |
+
|
| 254 |
+
### 2. Build Timeouts
|
| 255 |
+
- **Issue**: Space build fails due to timeout
|
| 256 |
+
- **Solution**: Optimize requirements, use CPU hardware
|
| 257 |
+
|
| 258 |
+
### 3. Memory Issues
|
| 259 |
+
- **Issue**: Out of memory during model loading
|
| 260 |
+
- **Solution**: Use CPU hardware, optimize model loading
|
| 261 |
+
|
| 262 |
+
### 4. Path Issues
|
| 263 |
+
- **Issue**: File not found errors
|
| 264 |
+
- **Solution**: Check file paths, verify directory structure
|
| 265 |
+
|
| 266 |
+
## π Performance Optimization
|
| 267 |
+
|
| 268 |
+
### Model Loading:
|
| 269 |
+
- Load models once at startup
|
| 270 |
+
- Use `torch.no_grad()` for inference
|
| 271 |
+
- Clear GPU cache if needed
|
| 272 |
+
|
| 273 |
+
### Memory Management:
|
| 274 |
+
- Process images in batches
|
| 275 |
+
- Use appropriate image sizes
|
| 276 |
+
- Monitor memory usage
|
| 277 |
+
|
| 278 |
+
## π Maintenance & Updates
|
| 279 |
+
|
| 280 |
+
### Regular Updates:
|
| 281 |
+
1. Check for dependency updates
|
| 282 |
+
2. Test with new sample images
|
| 283 |
+
3. Update documentation
|
| 284 |
+
4. Monitor space performance
|
| 285 |
+
|
| 286 |
+
### Version Control:
|
| 287 |
+
- Keep track of model file versions
|
| 288 |
+
- Document changes in commit messages
|
| 289 |
+
- Test thoroughly before updates
|
| 290 |
+
|
| 291 |
+
## π Support & Resources
|
| 292 |
+
|
| 293 |
+
### Documentation:
|
| 294 |
+
- This guide: `COMPLETE_SETUP_GUIDE.md`
|
| 295 |
+
- Quick start: `QUICK_START.md`
|
| 296 |
+
- Upload methods: `UPLOAD_METHODS.md`
|
| 297 |
+
|
| 298 |
+
### External Resources:
|
| 299 |
+
- Hugging Face Spaces: https://huggingface.co/spaces
|
| 300 |
+
- Gradio Documentation: https://gradio.app/docs/
|
| 301 |
+
- PyTorch Documentation: https://pytorch.org/docs/
|
| 302 |
+
|
| 303 |
+
### Contact:
|
| 304 |
+
- GitHub: https://github.com/rajeshsureddi/triqa
|
| 305 |
+
- Paper: https://arxiv.org/pdf/2507.12687
|
| 306 |
+
|
| 307 |
+
## β
Success Checklist
|
| 308 |
+
|
| 309 |
+
- [ ] Space created on Hugging Face
|
| 310 |
+
- [ ] All files uploaded successfully
|
| 311 |
+
- [ ] Model files uploaded to correct directories
|
| 312 |
+
- [ ] Build completed without errors
|
| 313 |
+
- [ ] Demo loads and displays interface
|
| 314 |
+
- [ ] Sample images work correctly
|
| 315 |
+
- [ ] Quality prediction works
|
| 316 |
+
- [ ] Paper links are accessible
|
| 317 |
+
- [ ] Citation is properly formatted
|
| 318 |
+
|
| 319 |
+
## π Final Result
|
| 320 |
+
|
| 321 |
+
Your TRIQA demo is now live at: **https://huggingface.co/spaces/S-Rajesh/triqa-iqa**
|
| 322 |
+
|
| 323 |
+
The demo provides:
|
| 324 |
+
- Interactive image quality assessment
|
| 325 |
+
- Professional web interface
|
| 326 |
+
- Academic paper integration
|
| 327 |
+
- Easy-to-use sample images
|
| 328 |
+
- Proper citation and documentation
|
| 329 |
+
|
| 330 |
+
This complete setup guide ensures that anyone can recreate and maintain the TRIQA Hugging Face demo successfully! π
|