🚀 用於衣物分割的微調Segformer B2模型
本項目是基於SegFormer模型,在ATR數據集上進行微調,用於衣物分割,同時也可用於人體分割。Hugging Face上的數據集名為 "mattmdjaga/human_parsing_dataset"。
🚀 快速開始
安裝依賴
確保你已經安裝了必要的庫,如transformers
、PIL
、requests
、matplotlib
和torch
。
運行代碼示例
from transformers import SegformerImageProcessor, AutoModelForSemanticSegmentation
from PIL import Image
import requests
import matplotlib.pyplot as plt
import torch.nn as nn
processor = SegformerImageProcessor.from_pretrained("mattmdjaga/segformer_b2_clothes")
model = AutoModelForSemanticSegmentation.from_pretrained("mattmdjaga/segformer_b2_clothes")
url = "https://plus.unsplash.com/premium_photo-1673210886161-bfcc40f54d1f?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8cGVyc29uJTIwc3RhbmRpbmd8ZW58MHx8MHx8&w=1000&q=80"
image = Image.open(requests.get(url, stream=True).raw)
inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)
logits = outputs.logits.cpu()
upsampled_logits = nn.functional.interpolate(
logits,
size=image.size[::-1],
mode="bilinear",
align_corners=False,
)
pred_seg = upsampled_logits.argmax(dim=1)[0]
plt.imshow(pred_seg)
標籤說明
- 0: "背景"
- 1: "帽子"
- 2: "頭髮"
- 3: "太陽鏡"
- 4: "上裝"
- 5: "裙子"
- 6: "褲子"
- 7: "連衣裙"
- 8: "腰帶"
- 9: "左腳鞋"
- 10: "右腳鞋"
- 11: "臉部"
- 12: "左腿"
- 13: "右腿"
- 14: "左臂"
- 15: "右臂"
- 16: "包"
- 17: "圍巾"
✨ 主要特性
- 多用途分割:不僅可以用於衣物分割,還能進行人體分割。
- 微調模型:基於SegFormer B2模型在特定數據集上進行微調,提高分割效果。
💻 使用示例
基礎用法
上述代碼示例展示瞭如何使用該模型進行衣物分割。你可以將代碼中的圖片鏈接替換為你自己的圖片鏈接,即可對不同圖片進行分割。
高級用法
你可以根據實際需求對模型進行進一步的調整,例如修改processor
的參數,或者對輸出的分割結果進行後處理。
📚 詳細文檔
評估指標
標籤索引 |
標籤名稱 |
類別準確率 |
類別IoU |
0 |
背景 |
0.99 |
0.99 |
1 |
帽子 |
0.73 |
0.68 |
2 |
頭髮 |
0.91 |
0.82 |
3 |
太陽鏡 |
0.73 |
0.63 |
4 |
上裝 |
0.87 |
0.78 |
5 |
裙子 |
0.76 |
0.65 |
6 |
褲子 |
0.90 |
0.84 |
7 |
連衣裙 |
0.74 |
0.55 |
8 |
腰帶 |
0.35 |
0.30 |
9 |
左腳鞋 |
0.74 |
0.58 |
10 |
右腳鞋 |
0.75 |
0.60 |
11 |
臉部 |
0.92 |
0.85 |
12 |
左腿 |
0.90 |
0.82 |
13 |
右腿 |
0.90 |
0.81 |
14 |
左臂 |
0.86 |
0.74 |
15 |
右臂 |
0.82 |
0.73 |
16 |
包 |
0.91 |
0.84 |
17 |
圍巾 |
0.63 |
0.29 |
整體評估指標:
- 評估損失:0.15
- 平均準確率:0.80
- 平均IoU:0.69
訓練代碼
你可以在這裡找到訓練代碼。
📄 許可證
該模型的許可證信息可以在這裡找到。
📖 引用信息
@article{DBLP:journals/corr/abs-2105-15203,
author = {Enze Xie and
Wenhai Wang and
Zhiding Yu and
Anima Anandkumar and
Jose M. Alvarez and
Ping Luo},
title = {SegFormer: Simple and Efficient Design for Semantic Segmentation with
Transformers},
journal = {CoRR},
volume = {abs/2105.15203},
year = {2021},
url = {https://arxiv.org/abs/2105.15203},
eprinttype = {arXiv},
eprint = {2105.15203},
timestamp = {Wed, 02 Jun 2021 11:46:42 +0200},
biburl = {https://dblp.org/rec/journals/corr/abs-2105-15203.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}