README.md
| 1 | --- |
| 2 | license: other |
| 3 | tags: |
| 4 | - vision |
| 5 | - image-segmentation |
| 6 | widget: |
| 7 | - src: >- |
| 8 | https://images.unsplash.com/photo-1643310325061-2beef64926a5?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Nnx8cmFjb29uc3xlbnwwfHwwfHw%3D&w=1000&q=80 |
| 9 | example_title: Person |
| 10 | - src: >- |
| 11 | https://freerangestock.com/sample/139043/young-man-standing-and-leaning-on-car.jpg |
| 12 | example_title: Person |
| 13 | datasets: |
| 14 | - mattmdjaga/human_parsing_dataset |
| 15 | --- |
| 16 | # Segformer B2 fine-tuned for clothes segmentation |
| 17 | |
| 18 | SegFormer model fine-tuned on [ATR dataset](https://github.com/lemondan/HumanParsing-Dataset) for clothes segmentation but can also be used for human segmentation. |
| 19 | The dataset on hugging face is called "mattmdjaga/human_parsing_dataset". |
| 20 | |
| 21 | **[Training code](https://github.com/mattmdjaga/segformer_b2_clothes)**. |
| 22 | ```python |
| 23 | from transformers import SegformerImageProcessor, AutoModelForSemanticSegmentation |
| 24 | from PIL import Image |
| 25 | import requests |
| 26 | import matplotlib.pyplot as plt |
| 27 | import torch.nn as nn |
| 28 | |
| 29 | processor = SegformerImageProcessor.from_pretrained("mattmdjaga/segformer_b2_clothes") |
| 30 | model = AutoModelForSemanticSegmentation.from_pretrained("mattmdjaga/segformer_b2_clothes") |
| 31 | |
| 32 | url = "https://plus.unsplash.com/premium_photo-1673210886161-bfcc40f54d1f?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8cGVyc29uJTIwc3RhbmRpbmd8ZW58MHx8MHx8&w=1000&q=80" |
| 33 | |
| 34 | image = Image.open(requests.get(url, stream=True).raw) |
| 35 | inputs = processor(images=image, return_tensors="pt") |
| 36 | |
| 37 | outputs = model(**inputs) |
| 38 | logits = outputs.logits.cpu() |
| 39 | |
| 40 | upsampled_logits = nn.functional.interpolate( |
| 41 | logits, |
| 42 | size=image.size[::-1], |
| 43 | mode="bilinear", |
| 44 | align_corners=False, |
| 45 | ) |
| 46 | |
| 47 | pred_seg = upsampled_logits.argmax(dim=1)[0] |
| 48 | plt.imshow(pred_seg) |
| 49 | ``` |
| 50 | |
| 51 | Labels: 0: "Background", 1: "Hat", 2: "Hair", 3: "Sunglasses", 4: "Upper-clothes", 5: "Skirt", 6: "Pants", 7: "Dress", 8: "Belt", 9: "Left-shoe", 10: "Right-shoe", 11: "Face", 12: "Left-leg", 13: "Right-leg", 14: "Left-arm", 15: "Right-arm", 16: "Bag", 17: "Scarf" |
| 52 | |
| 53 | ### Evaluation |
| 54 | |
| 55 | | Label Index | Label Name | Category Accuracy | Category IoU | |
| 56 | |:-------------:|:----------------:|:-----------------:|:------------:| |
| 57 | | 0 | Background | 0.99 | 0.99 | |
| 58 | | 1 | Hat | 0.73 | 0.68 | |
| 59 | | 2 | Hair | 0.91 | 0.82 | |
| 60 | | 3 | Sunglasses | 0.73 | 0.63 | |
| 61 | | 4 | Upper-clothes | 0.87 | 0.78 | |
| 62 | | 5 | Skirt | 0.76 | 0.65 | |
| 63 | | 6 | Pants | 0.90 | 0.84 | |
| 64 | | 7 | Dress | 0.74 | 0.55 | |
| 65 | | 8 | Belt | 0.35 | 0.30 | |
| 66 | | 9 | Left-shoe | 0.74 | 0.58 | |
| 67 | | 10 | Right-shoe | 0.75 | 0.60 | |
| 68 | | 11 | Face | 0.92 | 0.85 | |
| 69 | | 12 | Left-leg | 0.90 | 0.82 | |
| 70 | | 13 | Right-leg | 0.90 | 0.81 | |
| 71 | | 14 | Left-arm | 0.86 | 0.74 | |
| 72 | | 15 | Right-arm | 0.82 | 0.73 | |
| 73 | | 16 | Bag | 0.91 | 0.84 | |
| 74 | | 17 | Scarf | 0.63 | 0.29 | |
| 75 | |
| 76 | Overall Evaluation Metrics: |
| 77 | - Evaluation Loss: 0.15 |
| 78 | - Mean Accuracy: 0.80 |
| 79 | - Mean IoU: 0.69 |
| 80 | |
| 81 | ### License |
| 82 | |
| 83 | The license for this model can be found [here](https://github.com/NVlabs/SegFormer/blob/master/LICENSE). |
| 84 | |
| 85 | ### BibTeX entry and citation info |
| 86 | |
| 87 | ```bibtex |
| 88 | @article{DBLP:journals/corr/abs-2105-15203, |
| 89 | author = {Enze Xie and |
| 90 | Wenhai Wang and |
| 91 | Zhiding Yu and |
| 92 | Anima Anandkumar and |
| 93 | Jose M. Alvarez and |
| 94 | Ping Luo}, |
| 95 | title = {SegFormer: Simple and Efficient Design for Semantic Segmentation with |
| 96 | Transformers}, |
| 97 | journal = {CoRR}, |
| 98 | volume = {abs/2105.15203}, |
| 99 | year = {2021}, |
| 100 | url = {https://arxiv.org/abs/2105.15203}, |
| 101 | eprinttype = {arXiv}, |
| 102 | eprint = {2105.15203}, |
| 103 | timestamp = {Wed, 02 Jun 2021 11:46:42 +0200}, |
| 104 | biburl = {https://dblp.org/rec/journals/corr/abs-2105-15203.bib}, |
| 105 | bibsource = {dblp computer science bibliography, https://dblp.org} |
| 106 | } |
| 107 | ``` |