Commit
·
9b0311c
1
Parent(s):
0c2191b
Update README.md
Browse files
README.md
CHANGED
@@ -1,26 +0,0 @@
|
|
1 |
-
from transformers import SegformerImageProcessor, AutoModelForSemanticSegmentation
|
2 |
-
from PIL import Image
|
3 |
-
import requests
|
4 |
-
import matplotlib.pyplot as plt
|
5 |
-
import torch.nn as nn
|
6 |
-
|
7 |
-
processor = SegformerImageProcessor.from_pretrained("mattmdjaga/segformer_b2_clothes")
|
8 |
-
model = AutoModelForSemanticSegmentation.from_pretrained("mattmdjaga/segformer_b2_clothes")
|
9 |
-
|
10 |
-
url = "https://plus.unsplash.com/premium_photo-1673210886161-bfcc40f54d1f?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8MXx8cGVyc29uJTIwc3RhbmRpbmd8ZW58MHx8MHx8&w=1000&q=80"
|
11 |
-
|
12 |
-
image = Image.open(requests.get(url, stream=True).raw)
|
13 |
-
inputs = processor(images=image, return_tensors="pt")
|
14 |
-
|
15 |
-
outputs = model(**inputs)
|
16 |
-
logits = outputs.logits.cpu()
|
17 |
-
|
18 |
-
upsampled_logits = nn.functional.interpolate(
|
19 |
-
logits,
|
20 |
-
size=image.size[::-1],
|
21 |
-
mode="bilinear",
|
22 |
-
align_corners=False,
|
23 |
-
)
|
24 |
-
|
25 |
-
pred_seg = upsampled_logits.argmax(dim=1)[0]
|
26 |
-
plt.imshow(pred_seg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|