added segformer inference
Browse files
run.py
CHANGED
@@ -2,8 +2,15 @@ import gradio as gr
|
|
2 |
import numpy as np
|
3 |
from time import sleep
|
4 |
import torch
|
5 |
-
from transformers import SegformerImageProcessor
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
image_processor = SegformerImageProcessor(reduce_labels=True)
|
8 |
|
9 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
2 |
import numpy as np
|
3 |
from time import sleep
|
4 |
import torch
|
5 |
+
from transformers import SegformerImageProcessor, SegformerForSemanticSegmentation
|
6 |
+
|
7 |
+
id2label = {0: 'seal', 255: 'bck'}
|
8 |
+
label2id = {'seal': 0, 'bck': 255}
|
9 |
+
model = SegformerForSemanticSegmentation.from_pretrained("nvidia/mit-b0",
|
10 |
+
num_labels=2,
|
11 |
+
id2label=id2label,
|
12 |
+
label2id=label2id,
|
13 |
+
)
|
14 |
image_processor = SegformerImageProcessor(reduce_labels=True)
|
15 |
|
16 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|