normalize logits
Browse files
run.py
CHANGED
@@ -3,7 +3,7 @@ import numpy as np
|
|
3 |
from time import sleep
|
4 |
import torch
|
5 |
from transformers import SegformerImageProcessor, SegformerForSemanticSegmentation
|
6 |
-
from torchvision import transforms
|
7 |
|
8 |
weights2load = 'segformer_ep15_loss0.00.pth'
|
9 |
id2label = {0: 'seal', 255: 'bck'}
|
@@ -32,12 +32,13 @@ def flip_periodically(im, interval_ms=0):
|
|
32 |
The flipped image.
|
33 |
"""
|
34 |
|
35 |
-
transforms.ToTensor()(im)
|
36 |
pixel_values = image_processor(im, return_tensors="pt").pixel_values.to(device)
|
37 |
outputs = model(pixel_values=pixel_values)
|
38 |
logits = outputs.logits.cpu().detach().numpy()
|
39 |
sleep(interval_ms / 1000) # Convert milliseconds to seconds
|
40 |
-
|
|
|
41 |
|
42 |
with gr.Blocks() as demo:
|
43 |
inp = gr.Image(sources=["webcam"], streaming=True)
|
|
|
3 |
from time import sleep
|
4 |
import torch
|
5 |
from transformers import SegformerImageProcessor, SegformerForSemanticSegmentation
|
6 |
+
# from torchvision import transforms
|
7 |
|
8 |
weights2load = 'segformer_ep15_loss0.00.pth'
|
9 |
id2label = {0: 'seal', 255: 'bck'}
|
|
|
32 |
The flipped image.
|
33 |
"""
|
34 |
|
35 |
+
# transforms.ToTensor()(im)
|
36 |
pixel_values = image_processor(im, return_tensors="pt").pixel_values.to(device)
|
37 |
outputs = model(pixel_values=pixel_values)
|
38 |
logits = outputs.logits.cpu().detach().numpy()
|
39 |
sleep(interval_ms / 1000) # Convert milliseconds to seconds
|
40 |
+
imout = (logits[0, 0] - logits[0, 0].min()) / (logits[0, 0].max() - logits[0, 0].min())
|
41 |
+
return imout #np.flipud(im)
|
42 |
|
43 |
with gr.Blocks() as demo:
|
44 |
inp = gr.Image(sources=["webcam"], streaming=True)
|