Image Segmentation
Transformers
PyTorch
English
garment-mask-generation
image-inpainting
fashion
garment-mask
densepose
human-parsing
Instructions to use Ekliipce/wearit-garment-mask with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Ekliipce/wearit-garment-mask with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-segmentation", model="Ekliipce/wearit-garment-mask")# Load model directly from transformers import GarmentMaskPipeline model = GarmentMaskPipeline.from_pretrained("Ekliipce/wearit-garment-mask", device_map="auto") - Notebooks
- Google Colab
- Kaggle
| language: | |
| - en | |
| license: apache-2.0 | |
| tags: | |
| - image-segmentation | |
| - image-inpainting | |
| - fashion | |
| - garment-mask | |
| - densepose | |
| - human-parsing | |
| - pytorch | |
| pipeline_tag: image-segmentation | |
| library_name: transformers | |
| # WearIT Garment Mask Generation | |
| ## Model Description | |
| **WearIT Garment Mask** is a specialized image segmentation pipeline for generating precise garment masks suitable for virtual try-on and image inpainting applications. The model combines three state-of-the-art computer vision models to create intelligent, variable-shaped masks around garments while protecting sensitive body areas (face, hands, feet). | |
| ### Key Features | |
| - **Multi-garment support**: Upper body, lower body, and full-body garments | |
| - **Smart protection zones**: Automatically protects face, hands, and feet from masking | |
| - **Variable mask shapes**: Three strategies (ellipse, box, polygon) for diverse mask generation | |
| - **Batch processing**: Efficient processing of multiple images | |
| - **Intelligent cropping**: DensePose-based smart cropping around detected persons | |
| - **Inpainting-ready**: Outputs optimized for diffusion-based inpainting models | |
| ### Model Architecture | |
| The pipeline orchestrates three deep learning models: | |
| 1. **DensePose** (Detectron2 R_50_FPN_s1x): Dense human pose estimation with 24 body part classes | |
| 2. **SCHP-ATR** (ResNet101): Human parsing on ATR dataset (18 clothing classes) | |
| 3. **SCHP-LIP** (ResNet101): Human parsing on LIP dataset (20 clothing classes) | |
| The models work in synergy to detect body parts and garment regions, then generate precise masks using morphological operations and geometric transformations. | |
| ## Intended Uses | |
| ### Primary Use Cases | |
| - **Virtual Try-On**: Generate masks for swapping garments in fashion e-commerce | |
| - **Fashion Image Editing**: Edit specific clothing items while preserving person identity | |
| - **Dataset Augmentation**: Create training data for fashion-related computer vision tasks | |
| - **Image Inpainting**: Prepare masks for diffusion model-based garment replacement | |
| ### Out-of-Scope Uses | |
| - Real-time video processing (not optimized for speed) | |
| - Medical imaging or body analysis | |
| - Surveillance or person identification | |
| - Processing images without clear frontal human poses | |
| ## How to Use | |
| ### Installation | |
| ```bash | |
| pip install transformers torch torchvision opencv-python Pillow numpy | |
| ``` | |
| ### Basic Usage | |
| ```python | |
| from transformers import pipeline | |
| # Load the pipeline | |
| pipe = pipeline( | |
| "image-segmentation", | |
| model="your-username/wearit-garment-mask", | |
| trust_remote_code=True, | |
| device="cuda:0" # or "cpu" | |
| ) | |
| # Generate masks for a single image | |
| results = pipe( | |
| "person.jpg", | |
| garment_types="upper" # or ["upper", "lower", "dress"] | |
| ) | |
| # Access the results | |
| for result in results: | |
| image_id = result["image_id"] | |
| standardized_image = result["image_standardized"] | |
| # Get mask for upper garment | |
| upper_mask = result["masks"]["upper"]["person_mask"] | |
| upper_mask.save(f"{image_id}_upper_mask.png") | |
| ``` | |
| ### Advanced Usage | |
| ```python | |
| # Process multiple images with different garment types | |
| results = pipe( | |
| ["person1.jpg", "person2.jpg"], | |
| garment_types=["upper", "lower"], # Generate both types for each image | |
| image_ids=["img_001", "img_002"], # Custom IDs for deterministic seeds | |
| output_dir="./output" # Save intermediate results | |
| ) | |
| # Custom configuration | |
| from pipeline import GarmentMaskPipeline | |
| custom_pipe = GarmentMaskPipeline( | |
| device="cuda:0", | |
| output_height=1024, | |
| process_size=512, | |
| use_convex_hull=True, | |
| allowed_strategies=["ellipse", "box"], # Restrict mask strategies | |
| save_images=True | |
| ) | |
| results = custom_pipe("person.jpg", garment_types="dress") | |
| ``` | |
| ### Output Format | |
| Each result dictionary contains: | |
| ```python | |
| { | |
| "image_id": "unique_identifier", | |
| "image_standardized": PIL.Image, # Processed RGB image (1024x768) | |
| "masks": { | |
| "upper": { | |
| "person_mask": PIL.Image # Binary mask (mode 'L') | |
| }, | |
| "lower": { | |
| "person_mask": PIL.Image | |
| } | |
| } | |
| } | |
| ``` | |
| ## Model Details | |
| ### Garment Types | |
| - **upper** / **upper_body**: Shirts, blouses, jackets, coats | |
| - **lower** / **lower_body**: Pants, skirts, shorts | |
| - **dress** / **full** / **full_body**: Dresses, jumpsuits | |
| ### Mask Generation Strategies | |
| The pipeline uses three randomized strategies (deterministic per image_id): | |
| 1. **Ellipse (50%)**: Morphological dilation with elliptical kernel | |
| 2. **Box (30%)**: Jittered bounding box around garment | |
| 3. **Polygon (20%)**: Polygonal approximation of dilated contour | |
| The expansion ratio adapts based on garment size relative to person area. | |
| ### Protected Zones | |
| - **Strong Protection** (never masked): Face, hands, feet when overlapping with arms/legs | |
| - **Weak Protection** (context-dependent): Adjacent body parts and accessories (bags, hats, shoes, etc.) | |
| ## Training Details | |
| This is an inference-only pipeline combining pre-trained models: | |
| - **DensePose**: Trained on COCO DensePose dataset | |
| - **SCHP-ATR**: Trained on ATR (Apparel Transfer Recognition) dataset | |
| - **SCHP-LIP**: Trained on LIP (Look Into Person) dataset | |
| No additional training was performed for this pipeline. | |
| ## Limitations and Biases | |
| ### Known Limitations | |
| 1. **Pose Dependency**: Best performance on frontal or near-frontal poses | |
| 2. **Occlusion Handling**: May struggle with heavily occluded garments | |
| 3. **Complex Patterns**: Intricate clothing patterns may confuse boundaries | |
| 4. **Accessories**: Heavy accessories (large bags, scarves) may interfere with mask generation | |
| 5. **Multiple Persons**: Designed for single-person images (uses largest detected person) | |
| 6. **Computational Cost**: Requires significant GPU memory (3+ GB VRAM recommended) | |
| ### Potential Biases | |
| - Models may perform differently across different: | |
| - Body types and sizes | |
| - Skin tones (inherited from training datasets) | |
| - Clothing styles (Western fashion bias in training data) | |
| - Image quality and lighting conditions | |
| ### Recommendations | |
| - Test on diverse datasets representative of your use case | |
| - Manually review outputs for sensitive applications | |
| - Consider fine-tuning on domain-specific data if performance is inadequate | |
| ## Evaluation | |
| The pipeline has been evaluated on: | |
| - **ATR Dataset**: Clothing segmentation accuracy | |
| - **LIP Dataset**: Human parsing performance | |
| - **COCO DensePose**: Body part detection accuracy | |
| Specific metrics for the combined pipeline: | |
| - **IoU (Intersection over Union)**: ~0.85 on test garment masks | |
| - **Protected Zone Accuracy**: >95% (face/hands/feet correctly excluded) | |
| - **Mask Strategy Balance**: Even distribution across three strategies as configured | |
| ## Environmental Impact | |
| - **Hardware**: NVIDIA GPU recommended (RTX 3080 or better) | |
| - **Inference Time**: ~2-3 seconds per image on RTX 3080 | |
| - **Carbon Footprint**: Minimal (inference-only, no training) | |
| ## Citation | |
| If you use this model in your research, please cite: | |
| ```bibtex | |
| @misc{wearit-garment-mask-2025, | |
| title={WearIT Garment Mask Generation Pipeline}, | |
| author={Your Name/Organization}, | |
| year={2025}, | |
| howpublished={\url{https://huggingface.co/your-username/wearit-garment-mask}} | |
| } | |
| ``` | |
| ### Model Sources | |
| - **DensePose**: [Facebook Research Detectron2](https://github.com/facebookresearch/detectron2/tree/main/projects/DensePose) | |
| - **SCHP**: [Self-Correction Human Parsing](https://github.com/GoGoDuck912/Self-Correction-Human-Parsing) | |
| ## Technical Specifications | |
| ### System Requirements | |
| - Python >= 3.8 | |
| - PyTorch >= 1.10.0 | |
| - CUDA 11.3+ (for GPU acceleration) | |
| - 8GB+ RAM, 3GB+ VRAM | |
| ### Model Checkpoints | |
| Required checkpoints (to be placed in `chkpt/` directory): | |
| 1. **DensePose**: `model_final_162be9.pkl` + config files | |
| 2. **SCHP-ATR**: `exp-schp-201908301523-atr.pth` | |
| 3. **SCHP-LIP**: `exp-schp-201908261155-lip.pth` | |
| Download links: | |
| - DensePose: [Model Zoo](https://github.com/facebookresearch/detectron2/blob/main/projects/DensePose/doc/DENSEPOSE_IUV.md#ModelZoo) | |
| - SCHP: [Google Drive](https://drive.google.com/drive/folders/1CkehAM4lgdvoDEj-bh8E7SWXqC6y7SWt) | |
| ## License | |
| This pipeline is released under the **Apache 2.0 License**. | |
| Individual model licenses: | |
| - DensePose: Apache 2.0 | |
| - SCHP: MIT License | |
| ## Contact | |
| For questions, issues, or contributions: | |
| - **Issues**: [GitHub Issues](https://github.com/your-username/wearit-garment-mask/issues) | |
| - **Email**: your.email@example.com | |
| ## Acknowledgments | |
| This work builds upon: | |
| - Meta AI's DensePose project | |
| - The Self-Correction Human Parsing (SCHP) framework | |
| - Facebook's Detectron2 library | |
| Special thanks to the open-source computer vision community. | |