Prabhat9801/Skin-Lesion-Segmentation
0
๐ฅ Skin Lesion Segmentation - Deployment Guide
This folder contains everything needed to deploy the UNet++ model to Hugging Face Spaces.
๐ Files Needed
Required Files:
- โ
app.py- Gradio web application - โ
unetpp.py- Model architecture - โ
requirements.txt- Python dependencies - โ ๏ธ
best_model.pt- YOU NEED TO DOWNLOAD THIS - โ ๏ธ
examples/folder - YOU NEED TO ADD EXAMPLE IMAGES
๐ฅ Download the Model
- Go to Google Drive: https://drive.google.com/drive/folders/14-wNH4hWoinkh1I1blsrmf_f9gXcwjyr
- Navigate to:
unetpp_experiments/unetpp_100pct_20251206_183240/ - Download
best_model.pt(~105MB) - Place it in this
deployment/folder
๐ผ๏ธ Add Example Images
- Create
examples/folder in this directory - Add 3-5 sample dermoscopic images:
example1.jpgexample2.jpgexample3.jpg- You can get these from the ISIC dataset or use test images from your experiments
๐งช Test Locally
Before deploying, test the app locally:
cd deployment
python app.pyThis will:
- Load the model
- Start Gradio server
- Open in browser at http://localhost:7860
Test by uploading an image and checking if segmentation works!
๐ Deploy to Hugging Face Spaces
Step 1: Create Account
- Go to https://huggingface.co/
- Sign up for free account
Step 2: Create New Space
- Click "New" โ "Space"
- Name:
skin-lesion-segmentation - License: MIT
- SDK: Gradio
- Hardware: CPU basic (free)
- Click "Create Space"
Step 3: Upload Files
Upload these files to your Space:
app.pyunetpp.pyrequirements.txtbest_model.ptexamples/folder with images
Step 4: Wait for Build
- Hugging Face will automatically install dependencies
- Build takes ~5-10 minutes
- Watch the logs for any errors
Step 5: Test & Share!
- Your app will be live at:
https://huggingface.co/spaces/YOUR_USERNAME/skin-lesion-segmentation - Test it with different images
- Share the link!
๐จ Customization
Change UI Theme:
In app.py, line 132:
with gr.Blocks(theme=gr.themes.Soft(), ...):Try: gr.themes.Base(), gr.themes.Monochrome(), gr.themes.Glass()
Add More Metrics:
In calculate_metrics() function, add:
- Circularity
- Asymmetry index
- Border irregularity
Change Colors:
In create_overlay(), line 67:
colored_mask[mask > 0] = [255, 0, 0] # RedTry: [0, 255, 0] (Green), [255, 255, 0] (Yellow)
โก Performance Tips
For Faster Inference:
- Use GPU (if available on Hugging Face):
- Upgrade to GPU hardware in Space settings
- Free tier has limited GPU hours
- Model Quantization:
model = torch.quantization.quantize_dynamic(
model, {torch.nn.Linear}, dtype=torch.qint8
)- Reduce Image Size:
- Change resize from 256x256 to 128x128
- Faster but slightly less accurate
๐ Troubleshooting
"Model file not found"
- Make sure
best_model.ptis in the same folder asapp.py - Check file name is exactly
best_model.pt
"CUDA out of memory"
- You're on CPU-only tier (this is normal)
- Model will use CPU automatically
- Inference takes 2-3 seconds instead of <1 second
"Module not found"
- Check
requirements.txthas all dependencies - Hugging Face will auto-install on build
"Image upload fails"
- Check image format (JPG, PNG supported)
- Max size: 10MB
- Try resizing large images
๐ Expected Performance
๐ฏ Next Steps
After deployment:
- โ Test with various images
- โ Share link with friends/colleagues
- โ Add to your portfolio/resume
- โ Include in GitHub README
- โ Get feedback and improve!
๐ Notes
- Medical Disclaimer: Always included in the app
- Privacy: Images are not stored, processed in memory only
- Updates: Push new files to Space to update
- Monitoring: Check Space logs for errors
๐ Useful Links
- Hugging Face Spaces Docs: https://huggingface.co/docs/hub/spaces
- Gradio Docs: https://www.gradio.app/docs
- Your GitHub Repo: https://github.com/Prabhat9801/Medical-Image-Segmentation
Ready to deploy? Follow the steps above and you'll have a live demo in ~1 hour! ๐ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
