Spaces:
Running
Running
readme file updates
Browse files
README.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
| 1 |
-
# stable-diffusion
|
| 2 |
-
|
| 3 |
# π¨ Stable Diffusion & CatVTON Implementation
|
| 4 |
|
| 5 |
<div align="center">
|
| 6 |
|
| 7 |
-

|
| 9 |
-

|
| 105 |
-
- Git
|
| 106 |
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
```bash
|
| 109 |
git clone https://github.com/Harsh-Kesharwani/stable-diffusion.git
|
| 110 |
cd stable-diffusion
|
| 111 |
-
git checkout CatVTON #
|
| 112 |
```
|
| 113 |
|
| 114 |
-
###
|
|
|
|
| 115 |
```bash
|
| 116 |
conda create -n stable-diffusion python=3.10.9
|
| 117 |
conda activate stable-diffusion
|
| 118 |
```
|
| 119 |
|
| 120 |
-
###
|
|
|
|
| 121 |
```bash
|
| 122 |
pip install -r requirements.txt
|
| 123 |
```
|
| 124 |
|
| 125 |
-
###
|
|
|
|
| 126 |
```bash
|
| 127 |
-
python -c "import torch; print(
|
| 128 |
-
python -c "import torch; print(
|
| 129 |
```
|
| 130 |
|
| 131 |
---
|
| 132 |
|
| 133 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
-
|
| 136 |
|
| 137 |
-
|
| 138 |
-
Download from [Stable Diffusion v1.4 Tokenizer](https://huggingface.co/CompVis/stable-diffusion-v1-4/tree/main/tokenizer):
|
| 139 |
-
- `vocab.json`
|
| 140 |
-
- `merges.txt`
|
| 141 |
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
- **Inpainting Model**: Download from [Stable Diffusion v1.5 Inpainting](https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-inpainting)
|
| 145 |
|
| 146 |
### Download Script
|
|
|
|
| 147 |
```bash
|
| 148 |
-
# Create data directory if it doesn't exist
|
| 149 |
mkdir -p data
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
wget -O vocab.json "https://huggingface.co/CompVis/stable-diffusion-v1-4/resolve/main/tokenizer/vocab.json"
|
| 153 |
-
wget -O merges.txt "https://huggingface.co/CompVis/stable-diffusion-v1-4/resolve/main/tokenizer/merges.txt"
|
| 154 |
-
|
| 155 |
-
# Note: Large model files need to be downloaded manually from HuggingFace
|
| 156 |
```
|
| 157 |
|
| 158 |
---
|
| 159 |
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
```bash
|
| 162 |
python interface.py
|
| 163 |
```
|
| 164 |
|
| 165 |
---
|
| 166 |
|
| 167 |
-
##
|
| 168 |
|
| 169 |
-
|
| 170 |
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
2. **Garment Alignment**: Automatic alignment of garments to person pose
|
| 174 |
-
3. **Mask Generation**: Automated or manual mask creation for try-on regions
|
| 175 |
-
---
|
| 176 |
|
| 177 |
-
|
| 178 |
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
|
| 183 |
-
###
|
| 184 |
-
- [Diffusers: Adapt a Model](https://huggingface.co/docs/diffusers/training/adapt_a_model)
|
| 185 |
-
- [Stable Diffusion v1.5 Inpainting](https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-inpainting)
|
| 186 |
-
- [CompVis Stable Diffusion v1.4](https://huggingface.co/CompVis/stable-diffusion-v1-4)
|
| 187 |
-
- [Inkpunk Diffusion](https://huggingface.co/Envvi/Inkpunk-Diffusion)
|
| 188 |
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
- CatVTON: Category-aware Virtual Try-On Network
|
| 193 |
|
| 194 |
---
|
| 195 |
|
| 196 |
-
##
|
| 197 |
|
| 198 |
<div align="center">
|
| 199 |
|
| 200 |
**Harsh Kesharwani**
|
| 201 |
|
| 202 |
-
[
|
| 219 |
-
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
| 220 |
-
4. Push to the branch (`git push origin feature/amazing-feature`)
|
| 221 |
-
5. Open a Pull Request
|
| 222 |
-
|
| 223 |
-
---
|
| 224 |
-
|
| 225 |
-
## π License
|
| 226 |
|
| 227 |
-
This project is licensed under the MIT License
|
| 228 |
|
| 229 |
---
|
| 230 |
|
| 231 |
-
##
|
| 232 |
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
-
|
| 237 |
|
| 238 |
---
|
| 239 |
|
| 240 |
<div align="center">
|
| 241 |
|
| 242 |
-
**β Star this
|
| 243 |
|
| 244 |
*Built with β€οΈ by [Harsh Kesharwani](https://www.linkedin.com/in/harsh-kesharwani/)*
|
| 245 |
|
| 246 |
</div>
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
<!-- 1. Download `vocab.json` and `merges.txt` from https://huggingface.co/CompVis/stable-diffusion-v1-4/tree/main/tokenizer and save them in the `data` folder
|
| 250 |
-
1. Download `inkpunk-diffusion-v1.ckpt` from https://huggingface.co/Envvi/Inkpunk-Diffusion/tree/main and save it in the `data` folder -->
|
| 251 |
-
|
| 252 |
-
<!-- IMPORTANT REFRRENCE
|
| 253 |
-
3. https://huggingface.co/docs/diffusers/training/adapt_a_model -->
|
| 254 |
-
<!-- 4. https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-inpainting -->
|
|
|
|
|
|
|
|
|
|
| 1 |
# π¨ Stable Diffusion & CatVTON Implementation
|
| 2 |
|
| 3 |
<div align="center">
|
| 4 |
|
| 5 |
+
 <br>
|
| 6 |

|
| 7 |
+

|
| 8 |
+

|
| 9 |
|
| 10 |
*A comprehensive implementation of Stable Diffusion from scratch with CatVTON virtual try-on capabilities*
|
| 11 |
|
|
|
|
| 13 |
|
| 14 |
---
|
| 15 |
|
| 16 |
+
## Table of Contents
|
| 17 |
|
| 18 |
+
* [Overview](#overview)
|
| 19 |
+
* [Project Structure](#project-structure)
|
| 20 |
+
* [Features](#features)
|
| 21 |
+
* [Setup & Installation](#setup--installation)
|
| 22 |
+
* [Model Downloads](#model-downloads)
|
| 23 |
+
* [CatVTON Integration](#catvton-integration)
|
| 24 |
+
* [References](#references)
|
| 25 |
+
* [Author](#author)
|
| 26 |
+
* [License](#license)
|
| 27 |
|
| 28 |
---
|
| 29 |
|
| 30 |
+
## Overview
|
| 31 |
|
| 32 |
+
This project implements **Stable Diffusion from scratch** using PyTorch, extended with **CatVTON (Virtual Cloth Try-On)** for realistic fashion try-on.
|
| 33 |
|
| 34 |
+
* Complete Stable Diffusion pipeline (Branch: `main`)
|
| 35 |
+
* CatVTON virtual try-on extension (Branch: `CatVTON`)
|
| 36 |
+
* DDPM-based denoising, VAE, and custom attention
|
| 37 |
+
* Inpainting and text-to-image capabilities
|
|
|
|
| 38 |
|
| 39 |
---
|
| 40 |
|
| 41 |
+
## Project Structure
|
| 42 |
|
| 43 |
+
```text
|
| 44 |
stable-diffusion/
|
| 45 |
+
βββ Core Components
|
| 46 |
β βββ attention.py # Attention mechanisms
|
| 47 |
+
β βββ clip.py # CLIP model
|
| 48 |
+
β βββ ddpm.py # DDPM sampler
|
| 49 |
+
β βββ decoder.py # VAE decoder
|
| 50 |
+
β βββ encoder.py # VAE encoder
|
| 51 |
+
β βββ diffusion.py # Diffusion logic
|
| 52 |
+
β βββ model.py # Weight loading
|
| 53 |
+
β βββ pipeline.py # Main pipeline logic
|
| 54 |
β
|
| 55 |
+
βββ Utilities & Interface
|
| 56 |
+
β βββ interface.py # Interactive script
|
| 57 |
+
β βββ model_converter.py # Weight conversion utilities
|
| 58 |
+
β βββ requirements.txt # Python dependencies
|
| 59 |
β
|
| 60 |
+
βββ Data & Models
|
| 61 |
+
β βββ vocab.json
|
| 62 |
+
β βββ merges.txt
|
| 63 |
+
β βββ inkpunk-diffusion-v1.ckpt
|
| 64 |
+
β βββ sd-v1-5-inpainting.ckpt
|
| 65 |
β
|
| 66 |
+
βββ Sample Data
|
| 67 |
+
β βββ person.jpg
|
| 68 |
+
β βββ garment.jpg
|
| 69 |
+
β βββ agnostic_mask.png
|
| 70 |
+
β βββ dog.jpg
|
| 71 |
+
β βββ image.png
|
| 72 |
+
β βββ zalando-hd-resized.zip
|
| 73 |
β
|
| 74 |
+
βββ Notebooks & Docs
|
| 75 |
+
βββ test.ipynb
|
| 76 |
+
βββ README.md
|
| 77 |
```
|
| 78 |
|
| 79 |
---
|
| 80 |
|
| 81 |
+
## Features
|
| 82 |
+
|
| 83 |
+
### Stable Diffusion Core
|
| 84 |
+
|
| 85 |
+
* From-scratch implementation with modular architecture
|
| 86 |
+
* Custom CLIP encoder integration
|
| 87 |
+
* Latent space generation using VAE
|
| 88 |
+
* DDPM sampling process
|
| 89 |
+
* Self-attention mechanisms for denoising
|
| 90 |
|
| 91 |
+
### CatVTON Capabilities
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
+
* Virtual try-on using inpainting
|
| 94 |
+
* Pose-aligned garment fitting
|
| 95 |
+
* Segmentation mask based garment overlay
|
|
|
|
| 96 |
|
| 97 |
---
|
| 98 |
|
| 99 |
+
## Setup & Installation
|
| 100 |
|
| 101 |
### Prerequisites
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
* Python 3.10.9
|
| 104 |
+
* CUDA-compatible GPU
|
| 105 |
+
* Git, Conda or venv
|
| 106 |
+
|
| 107 |
+
### Clone Repository
|
| 108 |
+
|
| 109 |
```bash
|
| 110 |
git clone https://github.com/Harsh-Kesharwani/stable-diffusion.git
|
| 111 |
cd stable-diffusion
|
| 112 |
+
git checkout CatVTON # for try-on features
|
| 113 |
```
|
| 114 |
|
| 115 |
+
### Create Environment
|
| 116 |
+
|
| 117 |
```bash
|
| 118 |
conda create -n stable-diffusion python=3.10.9
|
| 119 |
conda activate stable-diffusion
|
| 120 |
```
|
| 121 |
|
| 122 |
+
### Install Requirements
|
| 123 |
+
|
| 124 |
```bash
|
| 125 |
pip install -r requirements.txt
|
| 126 |
```
|
| 127 |
|
| 128 |
+
### Test Installation
|
| 129 |
+
|
| 130 |
```bash
|
| 131 |
+
python -c "import torch; print(torch.__version__)"
|
| 132 |
+
python -c "import torch; print(torch.cuda.is_available())"
|
| 133 |
```
|
| 134 |
|
| 135 |
---
|
| 136 |
|
| 137 |
+
## Model Downloads
|
| 138 |
+
|
| 139 |
+
### Tokenizer Files (from SD v1.4)
|
| 140 |
+
|
| 141 |
+
* `vocab.json`
|
| 142 |
+
* `merges.txt`
|
| 143 |
|
| 144 |
+
Download from: [CompVis/stable-diffusion-v1-4](https://huggingface.co/CompVis/stable-diffusion-v1-4/tree/main/tokenizer)
|
| 145 |
|
| 146 |
+
### Model Checkpoints
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
+
* `inkpunk-diffusion-v1.ckpt`: [Inkpunk Model](https://huggingface.co/Envvi/Inkpunk-Diffusion/tree/main)
|
| 149 |
+
* `sd-v1-5-inpainting.ckpt`: [Inpainting Weights](https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-inpainting)
|
|
|
|
| 150 |
|
| 151 |
### Download Script
|
| 152 |
+
|
| 153 |
```bash
|
|
|
|
| 154 |
mkdir -p data
|
| 155 |
+
wget -O data/vocab.json "https://huggingface.co/CompVis/stable-diffusion-v1-4/resolve/main/tokenizer/vocab.json"
|
| 156 |
+
wget -O data/merges.txt "https://huggingface.co/CompVis/stable-diffusion-v1-4/resolve/main/tokenizer/merges.txt"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
```
|
| 158 |
|
| 159 |
---
|
| 160 |
|
| 161 |
+
## CatVTON Integration
|
| 162 |
+
|
| 163 |
+
The CatVTON extension allows realistic cloth try-on using Stable Diffusion inpainting.
|
| 164 |
+
|
| 165 |
+
### Highlights
|
| 166 |
+
|
| 167 |
+
* `sd-v1-5-inpainting.ckpt` for image completion
|
| 168 |
+
* Garment alignment to human pose
|
| 169 |
+
* Agnostic segmentation mask usage
|
| 170 |
+
|
| 171 |
+
Run the interface:
|
| 172 |
+
|
| 173 |
```bash
|
| 174 |
python interface.py
|
| 175 |
```
|
| 176 |
|
| 177 |
---
|
| 178 |
|
| 179 |
+
## References
|
| 180 |
|
| 181 |
+
### Articles & Guides
|
| 182 |
|
| 183 |
+
* [Stable Diffusion from Scratch (Medium)](https://medium.com/@sayedebad.777/implementing-stable-diffusion-from-scratch-using-pytorch-f07d50efcd97)
|
| 184 |
+
* [YouTube: Diffusion Implementation](https://www.youtube.com/watch?v=ZBKpAp_6TGI)
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
+
### HuggingFace Resources
|
| 187 |
|
| 188 |
+
* [Stable Diffusion v1.5 Inpainting](https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-inpainting)
|
| 189 |
+
* [CompVis/stable-diffusion-v1-4](https://huggingface.co/CompVis/stable-diffusion-v1-4)
|
| 190 |
+
* [Inkpunk Diffusion](https://huggingface.co/Envvi/Inkpunk-Diffusion)
|
| 191 |
|
| 192 |
+
### Papers
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
+
* Stable Diffusion: Latent Diffusion Models
|
| 195 |
+
* DDPM: Denoising Diffusion Probabilistic Models
|
| 196 |
+
* CatVTON: Category-aware Try-On Network
|
|
|
|
| 197 |
|
| 198 |
---
|
| 199 |
|
| 200 |
+
## Author
|
| 201 |
|
| 202 |
<div align="center">
|
| 203 |
|
| 204 |
**Harsh Kesharwani**
|
| 205 |
|
| 206 |
+
[](https://github.com/Harsh-Kesharwani)
|
| 207 |
+
[](https://www.linkedin.com/in/harsh-kesharwani/)
|
| 208 |
+
[](mailto:harshkesharwani777@gmail.com)
|
| 209 |
|
| 210 |
*Passionate about AI, Computer Vision, and Generative Models*
|
| 211 |
|
|
|
|
| 213 |
|
| 214 |
---
|
| 215 |
|
| 216 |
+
## License
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
| 219 |
|
| 220 |
---
|
| 221 |
|
| 222 |
+
## Acknowledgments
|
| 223 |
|
| 224 |
+
* CompVis team for Stable Diffusion
|
| 225 |
+
* HuggingFace for models and APIs
|
| 226 |
+
* Zalando Research for dataset
|
| 227 |
+
* Open-source contributors and educators
|
| 228 |
|
| 229 |
---
|
| 230 |
|
| 231 |
<div align="center">
|
| 232 |
|
| 233 |
+
**β Star this repo if you found it helpful!**
|
| 234 |
|
| 235 |
*Built with β€οΈ by [Harsh Kesharwani](https://www.linkedin.com/in/harsh-kesharwani/)*
|
| 236 |
|
| 237 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|