File size: 8,079 Bytes
ea130a2
 
 
 
 
 
 
 
 
 
 
 
cfc4b6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0e3f01
cfc4b6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0e3f01
cfc4b6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
799ffc9
 
 
 
 
cfc4b6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0e3f01
 
 
cfc4b6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
799ffc9
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
---
license: openrail
base_model: runwayml/stable-diffusion-v1-5
tags:
- stable-diffusion
- controlnet
- image-inpainting
- fashion
- pose-conditioning
pipeline_tag: image-to-image
library_name: diffusers
---
# Fashion Inpainting System

🎨 **Advanced AI-powered fashion transformation system that preserves body pose and facial identity while generating new clothing styles.**

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
[![Python](https://img.shields.io/badge/Python-3.8%2B-blue.svg)](https://python.org)
[![Hugging Face](https://img.shields.io/badge/πŸ€—-Hugging%20Face-yellow.svg)](https://huggingface.co)

## πŸš€ Key Features

- **Pose Preservation**: Advanced 25.3% pose coverage system maintains body structure and proportions
- **Facial Identity Protection**: Preserves original facial features and expressions
- **Safety-First Design**: Built-in content filtering and safety checks
- **Multiple Checkpoint Support**: Compatible with various Stable Diffusion checkpoints
- **Production Ready**: Comprehensive error handling and fallback systems

## 🎯 What This System Does

**Input**: Person wearing any outfit  
**Output**: Same person in a completely different outfit while maintaining:
- βœ… Exact facial identity
- βœ… Original body pose and proportions  
- βœ… Natural fabric draping and fit
- βœ… Appropriate content generation

## πŸ›‘οΈ Safety & Ethical Use

### ⚠️ IMPORTANT USAGE RESTRICTIONS

This system is designed for **creative and artistic purposes only**. By using this software, you agree to:

**βœ… ALLOWED USES:**
- Fashion design and visualization
- Creative artwork and artistic expression
- Educational and research purposes  
- Personal style exploration
- Commercial fashion applications (with proper licensing)

**❌ PROHIBITED USES:**
- Creating deceptive or misleading content
- Non-consensual image manipulation
- Identity theft or impersonation
- Harassment or bullying
- Creation of inappropriate content
- Any illegal or harmful activities

### πŸ”’ Built-in Safety Features

- **Content Filtering**: Automatic detection and prevention of inappropriate outputs
- **Identity Preservation**: System designed to change clothing only, not faces
- **Pose Validation**: Ensures generated content maintains appropriate poses
- **Quality Thresholds**: Filters out low-quality or distorted results

## πŸ—οΈ System Architecture

### Core Components

1. **Pose Extraction System** (25.3% coverage)
   - OpenPose-based pose detection via controlnet_aux
   - 5-channel pose vectors (Body, Hands, Face, Feet, Skeleton)
   - Dilated regions for enhanced coverage

2. **Hand Exclusion Logic**
   - Prevents generation of extra hands/limbs
   - Conservative mask erosion with exclusion zones
   - Optimized for natural results

3. **Safety-Aware Generation**
   - Content filtering for appropriate results
   - Coverage analysis for generation scope
   - Adaptive prompting based on input analysis

4. **Checkpoint Compatibility**
   - Supports custom Stable Diffusion models
   - Automatic parameter optimization
   - Fashion-specific model recommendations

## πŸ“‹ Requirements

```bash
Python 3.8+
torch>=1.13.0
diffusers>=0.21.0
transformers>=4.21.0
controlnet_aux>=0.4.0
opencv-python>=4.6.0
pillow>=9.0.0
numpy>=1.21.0
```

## πŸš€ Quick Start

### Installation

```bash
# Clone the repository
git clone https://github.com/mlworks90/fashion-inpainting-system.git
cd fashion-inpainting-system

# Install dependencies
pip install -r requirements.txt

# Optional: Install with CUDA support
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118
```

### Basic Usage

```python
from fashion_safety_checker import create_fashion_safety_pipeline
pipeline = create_fashion_safety_pipeline()

# Transform outfit
result = pipeline.safe_fashion_transformation(
    source_image_path="person_in_casual_wear.jpg",
    checkpoint_path="fashion_checkpoint.safetensors",
    outfit_prompt="elegant red evening dress",
    output_path="person_in_evening_dress.jpg",
    face_scale=0.90  # Manual face to body ratio adjustment
)

if result['success']:
    print("βœ… Fashion transformation completed")
else:    
    print(f"Blocking reason: {result['blocking_reason']}")
    print(f"User message: {result['user_message']}")
```

## πŸ“Š Performance & Quality

- **Pose Preservation**: 25.3% coverage ensures accurate body structure
- **Face Identity**: >95% facial feature preservation
- **Generation Speed**: ~30-60 seconds per image (depending on hardware)
- **Memory Usage**: 8-12GB VRAM recommended
- **Success Rate**: >85% for well-posed input images

## πŸ”§ Configuration

### Safety Settings

```python
pipeline = create_fashion_safety_pipeline(safety_mode="legacy_strict") 
 # legacy_strict - highest safety restrictions
 # fashion_strict - conservative outfits only
 # fashion_moderate - default level. Suitable for most garment types except some swimwear.
 # fashion_permissive - most permissive mode. Be aware of inappropriate outputs possibility!
            

```



## πŸ§ͺ Examples

### Fashion Transformations

| Input | Target Prompt | Output |
|-------|---------------|--------|
| Casual wear | "elegant evening dress" | ![Alt text](examples/Woman_Evening_Dress_comparison.png) |
| Casual wear | "Business suit" | ![Alt text](examples/Man_Business_Suit_comparison.png)  |
| Casual wear | "Business Costume" |  ![Alt text](examples/Woman_Business_Suit_comparison.png) |

## 🏒 Commercial Use & Support

### Open Source License
This project is licensed under **Apache License 2.0**, allowing:
- βœ… Commercial use
- βœ… Modification and distribution
- βœ… Private use
- βœ… Patent grant

### Professional Services Available

For commercial deployments, we offer:
- **Custom model training** for specific fashion domains
- **API integration** and cloud deployment
- **Performance optimization** for production environments
- **Priority support** and SLA guarantees
- **Custom safety filtering** for brand-specific requirements

Contact: [mlworks90@gmail.com](mailto:mlworks90@gmail.com)

## πŸ“š Documentation

- [Installation Guide](docs/installation.md)
- [API Reference](docs/api_reference.md)  
- [Safety Guidelines](docs/safety_guidelines.md)
- [Troubleshooting](docs/troubleshooting.md)
- [Commercial Licensing](docs/commercial_licensing.md)

## 🀝 Contributing

We welcome contributions! Please read our [Contributing Guidelines](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md).

### Development Setup

```bash
# Clone repository
git clone https://github.com/mlworks90/fashion-inpainting-system.git
cd fashion-inpainting-system

# Install in development mode
pip install -e .

# Run tests
python -m pytest tests/
```

## πŸ™ Acknowledgments

This system builds upon excellent open-source projects:
- [Stable Diffusion](https://github.com/CompVis/stable-diffusion) by CompVis
- [ControlNet](https://github.com/lllyasviel/ControlNet) by lllyasviel
- [Diffusers](https://github.com/huggingface/diffusers) by Hugging Face
- [controlnet_aux](https://github.com/patrickvonplaten/controlnet_aux) for OpenPose processing

## πŸ“„ License

Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for details.

## βš–οΈ Legal & Safety Disclaimers

- Users are responsible for ensuring appropriate use and obtaining necessary consents
- This software is provided "as is" without warranty
- Not intended for creating deceptive or harmful content
- Users must comply with applicable laws and regulations
- Commercial users should review terms and consider professional support

## πŸ“ž Support & Contact

- **Issues**: [GitHub Issues](https://github.com/mlworks90/fashion-inpainting-system/issues)
- **Discussions**: [GitHub Discussions](https://github.com/mlworks90/fashion-inpainting-system/discussions)
- **Commercial Inquiries**: [your-email@domain.com](mailto:mlworks90@gmailo.com)
- **Documentation**: [Project Wiki](https://github.com/mlworks90/fashion-inpainting-system/wiki)

---

**Made with ❀️ for the AI and Fashion communities**