Update README.md
Browse files
README.md
CHANGED
@@ -58,22 +58,29 @@ Use the code below to get started with the model.
|
|
58 |
import cv2
|
59 |
import torch
|
60 |
|
61 |
-
from transformers import AutoImageProcessor,
|
62 |
|
63 |
image = cv2.imread('./example.jpg')
|
64 |
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
65 |
|
66 |
-
processor = AutoImageProcessor.from_pretrained("pamixsun/
|
67 |
-
model =
|
68 |
|
69 |
inputs = processor(image, return_tensors="pt")
|
70 |
|
71 |
with torch.no_grad():
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
```
|
79 |
|
|
|
58 |
import cv2
|
59 |
import torch
|
60 |
|
61 |
+
from transformers import AutoImageProcessor, SegformerForSemanticSegmentation
|
62 |
|
63 |
image = cv2.imread('./example.jpg')
|
64 |
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
65 |
|
66 |
+
processor = AutoImageProcessor.from_pretrained("pamixsun/segformer_for_optic_disc_cup_segmentation")
|
67 |
+
model = SegformerForSemanticSegmentation.from_pretrained("pamixsun/segformer_for_optic_disc_cup_segmentation")
|
68 |
|
69 |
inputs = processor(image, return_tensors="pt")
|
70 |
|
71 |
with torch.no_grad():
|
72 |
+
inputs.to(self.device)
|
73 |
+
outputs = self.seg_model(**inputs)
|
74 |
+
logits = outputs.logits.cpu()
|
75 |
+
|
76 |
+
upsampled_logits = nn.functional.interpolate(
|
77 |
+
logits,
|
78 |
+
size=image.shape[:2],
|
79 |
+
mode="bilinear",
|
80 |
+
align_corners=False,
|
81 |
+
)
|
82 |
+
|
83 |
+
pred_disc_cup = upsampled_logits.argmax(dim=1)[0].numpy().astype(np.uint8)
|
84 |
|
85 |
```
|
86 |
|