This SegFormer model has undergone specialized fine-tuning on the
REFUGE challenge dataset,
a public benchmark for semantic segmentation of anatomical structures in retinal fundus images.
The fine-tuning enables expert-level segmentation of the optic disc and optic cup, two critical structures for ophthalmological diagnosis.
This pretrained model enables semantic segmentation of key anatomical structures, namely, the optic disc and optic cup, in retinal fundus images.
It takes fundus images as input and outputs the segmentation results.
The model has undergone specialized training and fine-tuning exclusively using retinal fundus images,
with the objective to perform semantic segmentation of anatomical structures including the optic disc and optic cup.
Therefore, in order to derive optimal segmentation performance, it is imperative to ensure that only fundus images are entered as inputs to this model.
Use the code below to get started with the model.
1import cv2
2import torch
3import numpy as np
4
5from torch import nn
6from transformers import AutoImageProcessor, SegformerForSemanticSegmentation
7
8image = cv2.imread('./example.jpg')
9image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
10
11processor = AutoImageProcessor.from_pretrained("pamixsun/segformer_for_optic_disc_cup_segmentation")
12model = SegformerForSemanticSegmentation.from_pretrained("pamixsun/segformer_for_optic_disc_cup_segmentation")
13
14inputs = processor(image, return_tensors="pt")
15
16with torch.no_grad():
17 outputs = model(**inputs)
18 logits = outputs.logits.cpu()
19
20upsampled_logits = nn.functional.interpolate(
21 logits,
22 size=image.shape[:2],
23 mode="bilinear",
24 align_corners=False,
25)
26
27pred_disc_cup = upsampled_logits.argmax(dim=1)[0].numpy().astype(np.uint8)
28