Spaces:
Running
Running
alibidaran
commited on
Commit
·
dd78cef
1
Parent(s):
1bfda52
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from openvino.runtime import Core
|
2 |
+
import gradio as gr
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
def normalize(img):
|
7 |
+
img=img.astype(np.float32)
|
8 |
+
mean=(0.485, 0.456, 0.406)
|
9 |
+
std=(0.229, 0.224, 0.225)
|
10 |
+
img/=255.0
|
11 |
+
img-=mean
|
12 |
+
img/std
|
13 |
+
return img
|
14 |
+
def segment_image(filepath):
|
15 |
+
image=cv2.imread(filepath)
|
16 |
+
image=cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
|
17 |
+
image = cv2.resize(image, (512,512))
|
18 |
+
x=tfms(image.copy()/255.)
|
19 |
+
#ort_input={ort_session.get_inputs()[0].name:x.cpu().unsqueeze(0).float().numpy()}
|
20 |
+
#out=ort_session.run(None,ort_input)
|
21 |
+
out = compiled_model_onnx([x.unsqueeze(0).float().cpu().numpy()])
|
22 |
+
pred_mask=np.squeeze(np.argmax(out[0],1)).astype(np.uint8)
|
23 |
+
color_mask=cv2.applyColorMap(pred_mask,cv2.COLORMAP_MAGMA)*10
|
24 |
+
masked_image=cv2.addWeighted(image,0.6,color_mask,0.4,0.1)
|
25 |
+
return Image.fromarray(masked_image),Image.fromarray((color_mask))
|
26 |
+
|
27 |
+
demo=gr.Interface(fn=segment_image,inputs=gr.Image(type='filepath'),
|
28 |
+
outputs=[gr.Image(type="pil"),gr.Image(type="pil")],
|
29 |
+
examples=['/content/miccai2022_sisvse_dataset/images/real/R002_ch1_video_01_01-07-25-19.jpg',
|
30 |
+
"/content/miccai2022_sisvse_dataset/images/real/R003_ch1_video_01_01-14-13-15.jpg",
|
31 |
+
"/content/miccai2022_sisvse_dataset/images/real/R013_ch1_video_01_00-50-27-19.jpg",
|
32 |
+
"/content/miccai2022_sisvse_dataset/images/real/R010_ch1_video_03_00-26-28-05.jpg",
|
33 |
+
"/content/miccai2022_sisvse_dataset/images/real/R007_ch1_video_04_00-15-54-18.jpg",
|
34 |
+
"/content/miccai2022_sisvse_dataset/images/real/R013_ch1_video_03_00-55-16-10.jpg",
|
35 |
+
"/content/miccai2022_sisvse_dataset/images/real/R006_ch1_video_01_00-49-32-01.jpg",
|
36 |
+
"/content/miccai2022_sisvse_dataset/images/real/R005_ch1_video_03_00-18-54-00.jpg"],
|
37 |
+
themes=gr.themes.Soft(primary_hue=gr.themes.colors.amber,secondary_hue=gr.themes.colors.blue),
|
38 |
+
title="Davinci Eye(CPU version)")
|
39 |
+
demo.launch()
|