Spaces:
Running
Running
Commit
·
a9d197e
1
Parent(s):
b056abb
Update app.py
Browse files
app.py
CHANGED
@@ -7,21 +7,14 @@ from torchvision import models,transforms
|
|
7 |
core = Core()
|
8 |
|
9 |
# Read model to OpenVINO Runtime
|
10 |
-
|
11 |
-
|
12 |
|
13 |
tfms = transforms.Compose([
|
14 |
transforms.ToTensor(),
|
15 |
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]) # imagenet
|
16 |
])
|
17 |
-
|
18 |
-
img=img.astype(np.float32)
|
19 |
-
mean=(0.485, 0.456, 0.406)
|
20 |
-
std=(0.229, 0.224, 0.225)
|
21 |
-
img/=255.0
|
22 |
-
img-=mean
|
23 |
-
img/std
|
24 |
-
return img
|
25 |
def segment_image(filepath):
|
26 |
image=cv2.imread(filepath)
|
27 |
image=cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
|
@@ -29,7 +22,7 @@ def segment_image(filepath):
|
|
29 |
x=tfms(image.copy()/255.)
|
30 |
#ort_input={ort_session.get_inputs()[0].name:x.cpu().unsqueeze(0).float().numpy()}
|
31 |
#out=ort_session.run(None,ort_input)
|
32 |
-
out =
|
33 |
pred_mask=np.squeeze(np.argmax(out[0],1)).astype(np.uint8)
|
34 |
color_mask=cv2.applyColorMap(pred_mask,cv2.COLORMAP_MAGMA)*10
|
35 |
masked_image=cv2.addWeighted(image,0.6,color_mask,0.4,0.1)
|
|
|
7 |
core = Core()
|
8 |
|
9 |
# Read model to OpenVINO Runtime
|
10 |
+
model_ir = core.read_model(model="Davinci_eye.xml")
|
11 |
+
compiled_model_ir = core.compile_model(model=model_ir, device_name='CPU')
|
12 |
|
13 |
tfms = transforms.Compose([
|
14 |
transforms.ToTensor(),
|
15 |
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]) # imagenet
|
16 |
])
|
17 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
def segment_image(filepath):
|
19 |
image=cv2.imread(filepath)
|
20 |
image=cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
|
|
|
22 |
x=tfms(image.copy()/255.)
|
23 |
#ort_input={ort_session.get_inputs()[0].name:x.cpu().unsqueeze(0).float().numpy()}
|
24 |
#out=ort_session.run(None,ort_input)
|
25 |
+
out = compiled_model_ir([x.unsqueeze(0).float().cpu().numpy()])
|
26 |
pred_mask=np.squeeze(np.argmax(out[0],1)).astype(np.uint8)
|
27 |
color_mask=cv2.applyColorMap(pred_mask,cv2.COLORMAP_MAGMA)*10
|
28 |
masked_image=cv2.addWeighted(image,0.6,color_mask,0.4,0.1)
|