CoolFace
Apppublic

Prabhat9801/Skin-Lesion-Segmentation

sourceHugging Facemitupdated 10mo agoView on Hugging Face
0likes
App README

๐Ÿฅ 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

  1. 1.Go to Google Drive: https://drive.google.com/drive/folders/14-wNH4hWoinkh1I1blsrmf_f9gXcwjyr
  2. 2.Navigate to: unetpp_experiments/unetpp_100pct_20251206_183240/
  3. 3.Download best_model.pt (~105MB)
  4. 4.Place it in this deployment/ folder

๐Ÿ–ผ๏ธ Add Example Images

  1. 1.Create examples/ folder in this directory
  2. 2.Add 3-5 sample dermoscopic images:
  3. 3.example1.jpg
  4. 4.example2.jpg
  5. 5.example3.jpg
  6. 6.You can get these from the ISIC dataset or use test images from your experiments

๐Ÿงช Test Locally

Before deploying, test the app locally:

bash
cd deployment
python app.py

This 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

  1. 1.Go to https://huggingface.co/
  2. 2.Sign up for free account

Step 2: Create New Space

  1. 1.Click "New" โ†’ "Space"
  2. 2.Name: skin-lesion-segmentation
  3. 3.License: MIT
  4. 4.SDK: Gradio
  5. 5.Hardware: CPU basic (free)
  6. 6.Click "Create Space"

Step 3: Upload Files

Upload these files to your Space:

  • โ€”app.py
  • โ€”unetpp.py
  • โ€”requirements.txt
  • โ€”best_model.pt
  • โ€”examples/ 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:

python
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:

python
colored_mask[mask > 0] = [255, 0, 0]  # Red

Try: [0, 255, 0] (Green), [255, 255, 0] (Yellow)

โšก Performance Tips

For Faster Inference:

  1. 1.Use GPU (if available on Hugging Face):
  • โ€”Upgrade to GPU hardware in Space settings
  • โ€”Free tier has limited GPU hours
  • โ€”Model Quantization:
python
   model = torch.quantization.quantize_dynamic(
       model, {torch.nn.Linear}, dtype=torch.qint8
   )
  1. 1.Reduce Image Size:
  • โ€”Change resize from 256x256 to 128x128
  • โ€”Faster but slightly less accurate

๐Ÿ› Troubleshooting

"Model file not found"

  • โ€”Make sure best_model.pt is in the same folder as app.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.txt has 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

HardwareInference TimeCost
CPU (free)2-3 secondsFREE
GPU (T4)<1 secondLimited free hours

๐ŸŽฏ Next Steps

After deployment:

  1. 1.โœ… Test with various images
  2. 2.โœ… Share link with friends/colleagues
  3. 3.โœ… Add to your portfolio/resume
  4. 4.โœ… Include in GitHub README
  5. 5.โœ… 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