Views
No views yet

1from transformers import pipeline
2
3pipe = pipeline("image-segmentation", model="fashn-ai/fashn-human-parser")
4result = pipe("image.jpg")
5# result is a list of dicts with 'label', 'score', 'mask' for each detected class1from transformers import SegformerForSemanticSegmentation, SegformerImageProcessor
2from PIL import Image
3import torch
4
5# Load model and processor
6processor = SegformerImageProcessor.from_pretrained("fashn-ai/fashn-human-parser")
7model = SegformerForSemanticSegmentation.from_pretrained("fashn-ai/fashn-human-parser")
8
9# Load and preprocess image
10image = Image.open("path/to/image.jpg")
11inputs = processor(images=image, return_tensors="pt")
12
13# Inference
14with torch.no_grad():
15 outputs = model(**inputs)
16 logits = outputs.logits # (1, 18, H/4, W/4)
17
18# Upsample to original size and get predictions
19upsampled = torch.nn.functional.interpolate(
20 logits, size=image.size[::-1], mode="bilinear", align_corners=False
21)
22predictions = upsampled.argmax(dim=1).squeeze().numpy()pip install fashn-human-parser1from fashn_human_parser import FashnHumanParser
2
3parser = FashnHumanParser() # auto-detects GPU
4segmentation = parser.predict("image.jpg")
5# segmentation is a numpy array of shape (H, W) with class IDs 0-17cv2.INTER_AREA for resizing (matching training), while the HuggingFace pipeline uses PIL LANCZOS.| ID | Label |
|---|---|
| 0 | background |
| 1 | face |
| 2 | hair |
| 3 | top |
| 4 | dress |
| 5 | skirt |
| 6 | pants |
| 7 | belt |
| 8 | bag |
| 9 | hat |
| 10 | scarf |
| 11 | glasses |
| 12 | arms |
| 13 | hands |
| 14 | legs |
| 15 | feet |
| 16 | torso |
| 17 | jewelry |
| Category | Body Coverage | Relevant Labels |
|---|---|---|
| Tops | Upper body | top, dress, scarf |
| Bottoms | Lower body | skirt, pants, belt |
| One-pieces | Full body | top, dress, scarf, skirt, pants, belt |
face, hair, jewelry, bag, glasses, hat1@misc{fashn-human-parser,
2 author = {FASHN AI},
3 title = {FASHN Human Parser: SegFormer for Fashion Human Parsing},
4 year = {2024},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/fashn-ai/fashn-human-parser}
7}