File size: 5,960 Bytes
b9a3037 | 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 | # π― START HERE - CIFAR-100 Classifier Deployment
## π¦ What You Have
Your **CIFAR-100 Image Classifier** is ready for deployment! This is a complete Gradio web application that:
β
Classifies images into **100 categories**
β
Shows **confidence scores** and **probabilities**
β
Has a **beautiful, interactive UI**
β
Works on **CPU or GPU**
β
Ready for **Hugging Face Spaces**
---
## π¦ Two Options: Choose Your Path
### Option A: π Test Locally First (RECOMMENDED)
**Windows Users:**
1. Double-click `run_local.bat`
2. Wait for browser to open at `http://localhost:7860`
3. Upload an image and test the classifier!
**Alternative (any OS):**
```bash
python app.py
```
### Option B: βοΈ Deploy Directly to Hugging Face
Skip to the "Deploy to Hugging Face" section below.
---
## π§ͺ Testing Your App Locally
### Quick Test (Automated)
```bash
python test_app_locally.py
```
This script will:
1. β
Check all dependencies are installed
2. β
Verify model file exists (cifar100_model.pth)
3. β
Test model loading
4. β
Offer to run the app
### Manual Test
```bash
# Install dependencies
pip install -r requirements.txt
# Run the app
python app.py
```
Then:
1. Open `http://localhost:7860` in your browser
2. Upload a test image (any JPG, PNG, etc.)
3. Verify you see predictions with probabilities
4. Check top predictions and charts work
---
## βοΈ Deploy to Hugging Face Spaces
### Step-by-Step Deployment
#### 1. Create a Hugging Face Space
1. Go to [huggingface.co/new-space](https://huggingface.co/new-space)
2. Fill in:
- **Owner**: Your username
- **Space name**: `cifar100-classifier` (or any name you like)
- **License**: MIT
- **Select SDK**: **Gradio**
- **SDK version**: 4.0.0
- **Hardware**: CPU (Basic - Free) or upgrade for GPU
3. Click **"Create Space"**
#### 2. Upload Files to Your Space
**Method 1: Web Interface (Easiest)**
1. Click "Files" tab in your new space
2. Click "Add file" β "Upload files"
3. Upload all files from `CIFAR100HFS` folder:
- app.py
- model.py
- cifar100_model.pth
- requirements.txt
- README.md
- .gitattributes
4. Click "Commit changes to main"
**Method 2: Git CLI (Recommended for large models)**
```bash
# Clone your space
git clone https://huggingface.co/spaces/YOUR_USERNAME/cifar100-classifier
cd cifar100-classifier
# Copy files
# (Copy all files from CIFAR100HFS to this directory)
# Setup Git LFS for large files
git lfs install
git lfs track "*.pth"
# Add and commit
git add .
git commit -m "Deploy CIFAR-100 classifier"
# Push to Hugging Face
git push
```
#### 3. Wait for Build
- Your space will automatically build (2-5 minutes)
- Check the "Logs" tab if there are issues
- Once built, your app will be live!
#### 4. Access Your App
Your app will be available at:
```
https://huggingface.co/spaces/YOUR_USERNAME/cifar100-classifier
```
---
## π What Your Users Will See
1. **Landing Page**:
- Title: "CIFAR-100 Image Classifier"
- Upload button
- Settings sidebar
2. **After Upload**:
- Original image displayed
- **Predicted class** in large text
- **Confidence percentage** with color coding
- Top-K predictions table
- Interactive probability bar chart
3. **Advanced Options**:
- Adjust number of top predictions (slider)
- View all 100 class probabilities (checkbox)
- Download results as text file
---
## π¨ Customization (Optional)
### Change App Title
Edit `app.py` line 34:
```python
page_title="Your Custom Title"
```
### Change Color Theme
Edit `README.md` lines 3-4:
```yaml
colorFrom: blue # Change to: red, green, yellow, etc.
colorTo: purple # Change to: pink, indigo, teal, etc.
```
### Add Your Logo
Add to sidebar in `app.py`:
```python
st.sidebar.image("your_logo.png")
```
---
## π Troubleshooting
### Local Testing Issues
**"ModuleNotFoundError"**
```bash
pip install -r requirements.txt
```
**"Model file not found"**
- Ensure `cifar100_model.pth` is in the same folder as `app.py`
**"Port already in use"**
```bash
streamlit run app.py --server.port 8502
```
### Hugging Face Deployment Issues
**"Build failed"**
- Check Logs tab in your space
- Verify `requirements.txt` is correct
- Ensure all files uploaded successfully
**"Model too large"**
- Model file is 92MB - should work fine
- Git LFS is tracking it (check `.gitattributes`)
**"App crashes on inference"**
- Check if model architecture matches checkpoint
- Verify CIFAR-100 classes list is correct
---
## π Performance Optimization
### For Faster Inference
1. **Use GPU hardware** on Hugging Face (paid)
2. **Reduce image size** if needed
3. **Batch predictions** for multiple images
### For Better UX
1. Add **loading spinners** (already included)
2. Add **progress bars** for long operations
3. **Cache results** to avoid re-computation
---
## π Learn More
- **Streamlit Docs**: [docs.streamlit.io](https://docs.streamlit.io)
- **Hugging Face Spaces**: [huggingface.co/docs/hub/spaces](https://huggingface.co/docs/hub/spaces)
- **PyTorch**: [pytorch.org/docs](https://pytorch.org/docs)
---
## β¨ What's Next?
After successful deployment:
1. **Share your space** with friends and colleagues
2. **Collect feedback** from users
3. **Monitor performance** in HF analytics
4. **Iterate and improve** based on usage
5. **Add to your portfolio** or resume!
---
## π Quick Command Reference
```bash
# Test locally
python test_app_locally.py
# Run app locally
streamlit run app.py
# Deploy to HF (from your space directory)
git add .
git commit -m "Update app"
git push
# Check model file size
# Windows PowerShell:
(Get-Item cifar100_model.pth).length / 1MB
```
---
## π You're Ready!
Everything is set up and ready to go. Your next step:
**β Run `python test_app_locally.py` to test**
**β Or jump straight to deployment following steps above!**
Good luck! π
---
*Created: October 10, 2025*
*Author: Krishnakanth*
|