from openvino.runtime import Core import gradio as gr import numpy as np from PIL import Image def normalize(img): img=img.astype(np.float32) mean=(0.485, 0.456, 0.406) std=(0.229, 0.224, 0.225) img/=255.0 img-=mean img/std return img def segment_image(filepath): image=cv2.imread(filepath) image=cv2.cvtColor(image,cv2.COLOR_BGR2RGB) image = cv2.resize(image, (512,512)) x=tfms(image.copy()/255.) #ort_input={ort_session.get_inputs()[0].name:x.cpu().unsqueeze(0).float().numpy()} #out=ort_session.run(None,ort_input) out = compiled_model_onnx([x.unsqueeze(0).float().cpu().numpy()]) pred_mask=np.squeeze(np.argmax(out[0],1)).astype(np.uint8) color_mask=cv2.applyColorMap(pred_mask,cv2.COLORMAP_MAGMA)*10 masked_image=cv2.addWeighted(image,0.6,color_mask,0.4,0.1) return Image.fromarray(masked_image),Image.fromarray((color_mask)) demo=gr.Interface(fn=segment_image,inputs=gr.Image(type='filepath'), outputs=[gr.Image(type="pil"),gr.Image(type="pil")], examples=['/content/miccai2022_sisvse_dataset/images/real/R002_ch1_video_01_01-07-25-19.jpg', "/content/miccai2022_sisvse_dataset/images/real/R003_ch1_video_01_01-14-13-15.jpg", "/content/miccai2022_sisvse_dataset/images/real/R013_ch1_video_01_00-50-27-19.jpg", "/content/miccai2022_sisvse_dataset/images/real/R010_ch1_video_03_00-26-28-05.jpg", "/content/miccai2022_sisvse_dataset/images/real/R007_ch1_video_04_00-15-54-18.jpg", "/content/miccai2022_sisvse_dataset/images/real/R013_ch1_video_03_00-55-16-10.jpg", "/content/miccai2022_sisvse_dataset/images/real/R006_ch1_video_01_00-49-32-01.jpg", "/content/miccai2022_sisvse_dataset/images/real/R005_ch1_video_03_00-18-54-00.jpg"], themes=gr.themes.Soft(primary_hue=gr.themes.colors.amber,secondary_hue=gr.themes.colors.blue), title="Davinci Eye(CPU version)") demo.launch()