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", dtype="auto") - Notebooks
- Google Colab
- Kaggle
Fix: Remove Pipeline inheritance for standalone usage
Browse files- pipeline.py +17 -31
pipeline.py
CHANGED
|
@@ -25,21 +25,24 @@ if HF_AVAILABLE:
|
|
| 25 |
|
| 26 |
class GarmentMaskPipeline:
|
| 27 |
"""
|
| 28 |
-
|
| 29 |
|
| 30 |
This pipeline combines DensePose and SCHP models to detect human body parts
|
| 31 |
and garment regions, then generates variable-shaped masks suitable for inpainting.
|
| 32 |
|
| 33 |
Example:
|
| 34 |
```python
|
| 35 |
-
from
|
|
|
|
| 36 |
|
| 37 |
-
#
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
trust_remote_code=True)
|
| 41 |
|
| 42 |
-
#
|
|
|
|
|
|
|
|
|
|
| 43 |
results = pipe("person.jpg", garment_types=["upper", "lower"])
|
| 44 |
|
| 45 |
# Access masks
|
|
@@ -79,9 +82,6 @@ class GarmentMaskPipeline:
|
|
| 79 |
allowed_strategies: List of allowed mask strategies ["ellipse", "box", "poly"]
|
| 80 |
save_images: Whether to save intermediate images (default: False)
|
| 81 |
"""
|
| 82 |
-
if HF_AVAILABLE:
|
| 83 |
-
super().__init__(model=model, **kwargs)
|
| 84 |
-
|
| 85 |
# Store config
|
| 86 |
self.device = device
|
| 87 |
self.output_height = output_height
|
|
@@ -243,26 +243,12 @@ class GarmentMaskPipeline:
|
|
| 243 |
Returns:
|
| 244 |
List of results with masks for each image
|
| 245 |
"""
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
model_inputs = self.preprocess(inputs)
|
| 252 |
-
model_outputs = self._forward(model_inputs, **forward_params)
|
| 253 |
-
return self.postprocess(model_outputs)
|
| 254 |
|
| 255 |
|
| 256 |
-
#
|
| 257 |
-
|
| 258 |
-
try:
|
| 259 |
-
from transformers.pipelines import PIPELINE_REGISTRY
|
| 260 |
-
|
| 261 |
-
PIPELINE_REGISTRY.register_pipeline(
|
| 262 |
-
"garment-mask-generation",
|
| 263 |
-
pipeline_class=GarmentMaskPipeline,
|
| 264 |
-
pt_model=None, # Custom pipeline without standard model
|
| 265 |
-
)
|
| 266 |
-
except Exception as e:
|
| 267 |
-
if HF_AVAILABLE:
|
| 268 |
-
logger.warning(f"Could not register pipeline: {e}")
|
|
|
|
| 25 |
|
| 26 |
class GarmentMaskPipeline:
|
| 27 |
"""
|
| 28 |
+
Standalone Pipeline for generating garment masks for image inpainting.
|
| 29 |
|
| 30 |
This pipeline combines DensePose and SCHP models to detect human body parts
|
| 31 |
and garment regions, then generates variable-shaped masks suitable for inpainting.
|
| 32 |
|
| 33 |
Example:
|
| 34 |
```python
|
| 35 |
+
from huggingface_hub import snapshot_download
|
| 36 |
+
import sys
|
| 37 |
|
| 38 |
+
# Download from HF Hub
|
| 39 |
+
repo_path = snapshot_download("your-username/wearit-garment-mask")
|
| 40 |
+
sys.path.insert(0, repo_path)
|
|
|
|
| 41 |
|
| 42 |
+
# Import and use
|
| 43 |
+
from pipeline import GarmentMaskPipeline
|
| 44 |
+
|
| 45 |
+
pipe = GarmentMaskPipeline(model=repo_path, device="cuda")
|
| 46 |
results = pipe("person.jpg", garment_types=["upper", "lower"])
|
| 47 |
|
| 48 |
# Access masks
|
|
|
|
| 82 |
allowed_strategies: List of allowed mask strategies ["ellipse", "box", "poly"]
|
| 83 |
save_images: Whether to save intermediate images (default: False)
|
| 84 |
"""
|
|
|
|
|
|
|
|
|
|
| 85 |
# Store config
|
| 86 |
self.device = device
|
| 87 |
self.output_height = output_height
|
|
|
|
| 243 |
Returns:
|
| 244 |
List of results with masks for each image
|
| 245 |
"""
|
| 246 |
+
# Direct processing without Pipeline inheritance
|
| 247 |
+
preprocess_params, forward_params, postprocess_params = self._sanitize_parameters(**kwargs)
|
| 248 |
+
model_inputs = self.preprocess(inputs)
|
| 249 |
+
model_outputs = self._forward(model_inputs, **forward_params)
|
| 250 |
+
return self.postprocess(model_outputs)
|
|
|
|
|
|
|
|
|
|
| 251 |
|
| 252 |
|
| 253 |
+
# Note: This pipeline is standalone and does not inherit from transformers.Pipeline
|
| 254 |
+
# Use it directly: pipe = GarmentMaskPipeline(model="repo_path", device="cuda")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|