Views
No views yet
1from transformers import SegformerImageProcessor, AutoModelForSemanticSegmentation
2from PIL import Image
3import requests
4import matplotlib.pyplot as plt
5import torch.nn as nn
6
7processor = SegformerImageProcessor.from_pretrained("mattmdjaga/segformer_b2_clothes")
8model = AutoModelForSemanticSegmentation.from_pretrained("mattmdjaga/segformer_b2_clothes")
9
10url = "https://plus.unsplash.com/premium_photo-1673210886161-bfcc40f54d1f?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8cGVyc29uJTIwc3RhbmRpbmd8ZW58MHx8MHx8&w=1000&q=80"
11
12image = Image.open(requests.get(url, stream=True).raw)
13inputs = processor(images=image, return_tensors="pt")
14
15outputs = model(**inputs)
16logits = outputs.logits.cpu()
17
18upsampled_logits = nn.functional.interpolate(
19 logits,
20 size=image.size[::-1],
21 mode="bilinear",
22 align_corners=False,
23)
24
25pred_seg = upsampled_logits.argmax(dim=1)[0]
26plt.imshow(pred_seg)| Label Index | Label Name | Category Accuracy | Category IoU |
|---|---|---|---|
| 0 | Background | 0.99 | 0.99 |
| 1 | Hat | 0.73 | 0.68 |
| 2 | Hair | 0.91 | 0.82 |
| 3 | Sunglasses | 0.73 | 0.63 |
| 4 | Upper-clothes | 0.87 | 0.78 |
| 5 | Skirt | 0.76 | 0.65 |
| 6 | Pants | 0.90 | 0.84 |
| 7 | Dress | 0.74 | 0.55 |
| 8 | Belt | 0.35 | 0.30 |
| 9 | Left-shoe | 0.74 | 0.58 |
| 10 | Right-shoe | 0.75 | 0.60 |
| 11 | Face | 0.92 | 0.85 |
| 12 | Left-leg | 0.90 | 0.82 |
| 13 | Right-leg | 0.90 | 0.81 |
| 14 | Left-arm | 0.86 | 0.74 |
| 15 | Right-arm | 0.82 | 0.73 |
| 16 | Bag | 0.91 | 0.84 |
| 17 | Scarf | 0.63 | 0.29 |
1@article{DBLP:journals/corr/abs-2105-15203,
2 author = {Enze Xie and
3 Wenhai Wang and
4 Zhiding Yu and
5 Anima Anandkumar and
6 Jose M. Alvarez and
7 Ping Luo},
8 title = {SegFormer: Simple and Efficient Design for Semantic Segmentation with
9 Transformers},
10 journal = {CoRR},
11 volume = {abs/2105.15203},
12 year = {2021},
13 url = {https://arxiv.org/abs/2105.15203},
14 eprinttype = {arXiv},
15 eprint = {2105.15203},
16 timestamp = {Wed, 02 Jun 2021 11:46:42 +0200},
17 biburl = {https://dblp.org/rec/journals/corr/abs-2105-15203.bib},
18 bibsource = {dblp computer science bibliography, https://dblp.org}
19}