Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,122 +1,133 @@
|
|
| 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 |
- Person Face Sketches dataset: [Kaggle](https://www.kaggle.com/datasets/almightyj/person-face-sketches)
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: CycleGAN Face-Sketch Converter
|
| 3 |
+
emoji: π¨
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: "1.28.0"
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# π¨ CycleGAN Face-Sketch Converter
|
| 13 |
+
|
| 14 |
+
Convert face photos to sketches and vice versa using CycleGAN.
|
| 15 |
+
|
| 16 |
+
## π Deployment on Hugging Face Spaces
|
| 17 |
+
|
| 18 |
+
### Step 1: Prepare Your Models
|
| 19 |
+
|
| 20 |
+
After training, run this cell in your notebook:
|
| 21 |
+
|
| 22 |
+
```python
|
| 23 |
+
# Run this in your training notebook
|
| 24 |
+
export_for_huggingface(checkpoint_epoch=100) # Replace 100 with your best epoch
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
This creates two files in `deployment_models/`:
|
| 28 |
+
- `photo_to_sketch.pth` (~44 MB)
|
| 29 |
+
- `sketch_to_photo.pth` (~44 MB)
|
| 30 |
+
|
| 31 |
+
### Step 2: Create Hugging Face Space
|
| 32 |
+
|
| 33 |
+
1. Go to [Hugging Face Spaces](https://huggingface.co/spaces)
|
| 34 |
+
2. Click **"Create new Space"**
|
| 35 |
+
3. Configure:
|
| 36 |
+
- **Space name**: `cyclegan-face-sketch`
|
| 37 |
+
- **License**: Choose appropriate license
|
| 38 |
+
- **Select SDK**: **Streamlit**
|
| 39 |
+
- **Space hardware**: CPU Basic (free) or GPU for faster inference
|
| 40 |
+
|
| 41 |
+
### Step 3: Upload Files
|
| 42 |
+
|
| 43 |
+
Upload these files to your Space:
|
| 44 |
+
|
| 45 |
+
```
|
| 46 |
+
your-space/
|
| 47 |
+
βββ app.py # Streamlit application
|
| 48 |
+
βββ requirements.txt # Python dependencies
|
| 49 |
+
βββ photo_to_sketch.pth # Model file (Photo β Sketch)
|
| 50 |
+
βββ sketch_to_photo.pth # Model file (Sketch β Photo)
|
| 51 |
+
βββ README.md # This file (optional)
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
### Step 4: Your Space will Auto-Build
|
| 55 |
+
|
| 56 |
+
Hugging Face will automatically:
|
| 57 |
+
1. Install dependencies from `requirements.txt`
|
| 58 |
+
2. Run your Streamlit app
|
| 59 |
+
3. Provide a public URL
|
| 60 |
+
|
| 61 |
+
## π¦ File Sizes
|
| 62 |
+
|
| 63 |
+
- `photo_to_sketch.pth`: ~44 MB
|
| 64 |
+
- `sketch_to_photo.pth`: ~44 MB
|
| 65 |
+
- **Total**: ~88 MB (well within free tier limits)
|
| 66 |
+
|
| 67 |
+
## π― Features
|
| 68 |
+
|
| 69 |
+
- β
Photo to Sketch conversion
|
| 70 |
+
- β
Sketch to Photo conversion
|
| 71 |
+
- β
Auto-detection of input type
|
| 72 |
+
- β
Camera input support
|
| 73 |
+
- β
Download results
|
| 74 |
+
- β
Responsive UI
|
| 75 |
+
|
| 76 |
+
## π‘ Usage Tips
|
| 77 |
+
|
| 78 |
+
### For Best Results:
|
| 79 |
+
- Use clear, front-facing photos
|
| 80 |
+
- Ensure good lighting
|
| 81 |
+
- Images are automatically resized to 256x256
|
| 82 |
+
|
| 83 |
+
### Hardware:
|
| 84 |
+
- **CPU Basic (Free)**: ~3-5 seconds per image
|
| 85 |
+
- **GPU T4 (Paid)**: ~0.5 seconds per image
|
| 86 |
+
|
| 87 |
+
## π§ Local Testing
|
| 88 |
+
|
| 89 |
+
Before deploying, test locally:
|
| 90 |
+
|
| 91 |
+
```bash
|
| 92 |
+
# Install dependencies
|
| 93 |
+
pip install -r requirements.txt
|
| 94 |
+
|
| 95 |
+
# Run Streamlit app
|
| 96 |
+
streamlit run app.py
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
Then open http://localhost:8501
|
| 100 |
+
|
| 101 |
+
## π Model Details
|
| 102 |
+
|
| 103 |
+
- **Architecture**: CycleGAN with ResNet-based generators
|
| 104 |
+
- **Input Size**: 256x256 RGB images
|
| 105 |
+
- **Training**: Unpaired face-sketch dataset
|
| 106 |
+
- **Loss Functions**:
|
| 107 |
+
- Adversarial loss (LSGAN)
|
| 108 |
+
- Cycle consistency loss
|
| 109 |
+
- Identity loss
|
| 110 |
+
|
| 111 |
+
## π Troubleshooting
|
| 112 |
+
|
| 113 |
+
### Space doesn't start:
|
| 114 |
+
- Check all files are uploaded correctly
|
| 115 |
+
- Verify file names match exactly in `app.py`
|
| 116 |
+
- Check Space logs for errors
|
| 117 |
+
|
| 118 |
+
### Out of memory:
|
| 119 |
+
- Use CPU Basic hardware
|
| 120 |
+
- Models are optimized for CPU inference
|
| 121 |
+
|
| 122 |
+
### Slow inference:
|
| 123 |
+
- Upgrade to GPU hardware in Space settings
|
| 124 |
+
- Or use batch processing
|
| 125 |
+
|
| 126 |
+
## π License
|
| 127 |
+
|
| 128 |
+
[Your License Here]
|
| 129 |
+
|
| 130 |
+
## π Acknowledgments
|
| 131 |
+
|
| 132 |
+
- CycleGAN paper: [Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks](https://arxiv.org/abs/1703.10593)
|
| 133 |
- Person Face Sketches dataset: [Kaggle](https://www.kaggle.com/datasets/almightyj/person-face-sketches)
|