Technical Overview
SegFormer B2 fine‑tuned for clothes segmentation (model id mattmdjaga/segformer_b2_clothes) is a vision‑transformer based semantic‑segmentation model that predicts pixel‑wise class labels for a wide range of clothing and human‑body parts. It builds on the original SegFormer architecture (B2 backbone) and has been further trained on the ATR (human‑parsing) dataset that contains 18 fine‑grained categories such as “Upper‑clothes”, “Skirt”, “Pants”, “Dress”, “Hat”, “Sunglasses”, “Bag”, “Scarf”, etc.
Key features & capabilities:
- Pixel‑level classification for 18 clothing‑related classes + background.
- Fast inference thanks to the lightweight B2 transformer and a pure‑CNN decoder.
- Compatible with the Hugging Face
image‑segmentationpipeline,torch,onnxandsafetensorsformats. - Works out‑of‑the‑box on arbitrary RGB images – no additional preprocessing required beyond the built‑in
SegformerImageProcessor.
Architecture highlights:
- Backbone: SegFormer‑B2 – a hierarchical transformer that mixes multi‑scale attention with lightweight MLP blocks, delivering a good trade‑off between accuracy and FLOPs.
- Decoder: Simple linear projection head that upsamples the low‑resolution token map to the original image size using bilinear interpolation.
- Training head: 18‑way softmax for semantic segmentation.
Intended use cases:
- Virtual try‑on and fashion recommendation systems.
- Retail analytics (e.g., detecting clothing types on store‑floor cameras).
- Human‑computer interaction where precise garment detection is required (AR filters, motion capture).
- Any downstream task that benefits from fine‑grained human parsing, such as pose‑aware pose estimation or body‑shape modeling.
Benchmark Performance
The model is evaluated on the same ATR parsing benchmark used for training. Metrics are reported per class (Category Accuracy and Category IoU) as well as overall scores.
| Label | Accuracy | IoU |
|---|---|---|
| Background | 0.99 | 0.99 |
| Hat | 0.73 | 0.68 |
| Hair | 0.91 | 0.82 |
| Sunglasses | 0.73 | 0.63 |
| Upper‑clothes | 0.87 | 0.78 |
| Skirt | 0.76 | 0.65 |
| Pants | 0.90 | 0.84 |
| Dress | 0.74 | 0.55 |
| Belt | 0.35 | 0.30 |
| Left‑shoe | 0.74 | 0.58 |
| Right‑shoe | 0.75 | 0.60 |
| Face | 0.92 | 0.85 |
| Left‑leg | 0.90 | 0.82 |
| Right‑leg | 0.90 | 0.81 |
| Left‑arm | 0.86 | 0.74 |
| Right‑arm | 0.82 | 0.73 |
| Bag | 0.91 | 0.84 |
| Scarf | 0.63 | 0.29 |
Overall, the model achieves an evaluation loss of 0.15, Mean Accuracy ≈ 0.80 and Mean IoU ≈ 0.69. These numbers are competitive with other lightweight human‑parsing models (e.g., DeepLab‑V3+ with a MobileNet backbone) while offering a smaller memory footprint and faster inference thanks to the transformer‑based encoder.
Hardware Requirements
VRAM for inference: The B2 backbone with a 384‑dimensional token space occupies roughly 1.2 GB of GPU memory when processing a 512 × 512 image. For typical 1024 × 1024 inputs, a 4 GB GPU (e.g., RTX 3050) is sufficient if batch size = 1.
Recommended GPU: Any CUDA‑compatible GPU with ≥ 6 GB VRAM (RTX 2060, RTX 3060, GTX 1660 Super, etc.) will comfortably run the model at 15‑30 FPS on a single image. For batch processing or higher resolutions, a 12 GB GPU (RTX 3070/3080) is advisable.
CPU: The model can be executed on CPU‑only environments via ONNX Runtime, but expect a 5‑10× slowdown compared to GPU. A modern multi‑core CPU (e.g., Intel i7‑10700K or AMD Ryzen 7 3700X) is recommended for reasonable latency.
Storage: The model files (weights + processor config) total ~ 300 MB when stored as safetensors. The Hugging Face repository also contains ONX exports (~ 250 MB) for edge deployment.
Performance characteristics: Inference time per 512 × 512 image on a RTX 3060 is ~ 30 ms (≈ 33 FPS). Upsampling and post‑processing add ~ 5 ms, keeping the end‑to‑end pipeline under 40 ms per frame.
Use Cases
Primary applications revolve around fine‑grained clothing detection:
- Virtual try‑on platforms: Segment each garment piece to overlay new clothing items in real time.
- Retail analytics: Count and classify apparel types from in‑store camera feeds for inventory and layout optimization.
- Fashion recommendation engines: Extract garment attributes (e.g., upper‑clothes, skirt, dress) to power similarity search.
- AR/VR filters: Apply makeup, accessories, or style effects only on the relevant body parts.
- Human‑computer interaction: Enable pose‑aware gestures that depend on whether a user is wearing a hat, glasses, or a bag.
These scenarios span industries such as e‑commerce, advertising, entertainment, security, and sports analytics. The model can be integrated via the Hugging Face pipeline API, exported to ONNX for mobile/edge devices, or wrapped in a REST micro‑service for cloud deployment.
Training Details
The model was fine‑tuned on the mattmdjaga/human_parsing_dataset, a Hugging Face mirror of the ATR human‑parsing dataset. The dataset contains thousands of annotated images with the 18 clothing/body classes listed in the README.
Methodology:
- Base model:
SegFormer‑B2pre‑trained on ImageNet‑1K. - Training script: available at github.com/mattmdjaga/segformer_b2_clothes.
- Loss: standard cross‑entropy with class‑balanced weighting to mitigate the rarity of items like “Scarf” or “Belt”.
- Optimizer: AdamW with a learning‑rate schedule (linear warm‑up → cosine decay).
- Batch size: 8–16 images (depending on GPU memory).
- Training epochs: 30–40, converging to the reported loss of 0.15.
Compute: Fine‑tuning was performed on a single NVIDIA RTX 3090 (24 GB VRAM) in roughly 6 hours. The model can be further fine‑tuned on custom apparel datasets using the same pipeline, which makes it adaptable to niche fashion domains (e.g., sportswear, cultural garments).
Licensing Information
The model card lists the license as “other”. The accompanying README points to the original SegFormer repository license, which is an MIT‑style license. In practice, this means:
- Source code and model weights can be used, modified, and redistributed.
- Commercial use is permitted, provided the original copyright notice and license text are retained.
- No warranty is offered; the user assumes all risk.
Because the license is not explicitly declared on the Hugging Face hub, you should verify the terms before integrating the model into a product. If you plan to distribute a derivative work, include the original SegFormer license and a citation to the paper (see “Related Papers” below). No additional attribution beyond the standard mattmdjaga/segformer_b2_clothes credit is required by the “other” label, but best practice is to acknowledge the author and dataset.