Ekliipce commited on
Commit
e1f4ba1
·
verified ·
1 Parent(s): c6880f7

Fix: Remove Pipeline inheritance for standalone usage

Browse files
Files changed (1) hide show
  1. pipeline.py +17 -31
pipeline.py CHANGED
@@ -25,21 +25,24 @@ if HF_AVAILABLE:
25
 
26
  class GarmentMaskPipeline:
27
  """
28
- Hugging Face 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 transformers import pipeline
 
36
 
37
- # Load the pipeline
38
- pipe = pipeline("image-segmentation",
39
- model="your-username/wearit-garment-mask",
40
- trust_remote_code=True)
41
 
42
- # Generate masks
 
 
 
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
- if HF_AVAILABLE:
247
- return super().__call__(inputs, **kwargs)
248
- else:
249
- # Fallback for non-HF usage
250
- preprocess_params, forward_params, postprocess_params = self._sanitize_parameters(**kwargs)
251
- model_inputs = self.preprocess(inputs)
252
- model_outputs = self._forward(model_inputs, **forward_params)
253
- return self.postprocess(model_outputs)
254
 
255
 
256
- # Register the pipeline if transformers is available
257
- if HF_AVAILABLE:
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")