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