Spaces:
Runtime error
Runtime error
raymondlo84
commited on
Commit
•
b83cf36
1
Parent(s):
6883502
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
3 |
-
x = st.slider('Select a value')
|
4 |
-
st.write(x, 'squared is', x * x)
|
5 |
-
|
6 |
from openvino.runtime import Core
|
7 |
|
8 |
ie = Core()
|
@@ -14,3 +11,32 @@ for device in devices:
|
|
14 |
st.write("Device", device)
|
15 |
st.write("Device Name", device_name)
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import cv2
|
|
|
|
|
|
|
3 |
from openvino.runtime import Core
|
4 |
|
5 |
ie = Core()
|
|
|
11 |
st.write("Device", device)
|
12 |
st.write("Device Name", device_name)
|
13 |
|
14 |
+
|
15 |
+
model = ie.read_model(model="v3-small_224_1.0_float.xml")
|
16 |
+
compiled_model = ie.compile_model(model=model, device_name="CPU")
|
17 |
+
|
18 |
+
output_layer = compiled_model.output(0)
|
19 |
+
|
20 |
+
# The MobileNet model expects images in RGB format.
|
21 |
+
image = cv2.cvtColor(cv2.imread(filename="coco.jpg"), code=cv2.COLOR_BGR2RGB)
|
22 |
+
|
23 |
+
# Resize to MobileNet image shape.
|
24 |
+
input_image = cv2.resize(src=image, dsize=(224, 224))
|
25 |
+
|
26 |
+
# Reshape to model input shape.
|
27 |
+
input_image = np.expand_dims(input_image, 0)
|
28 |
+
st.image(image, caption='Input Image')
|
29 |
+
|
30 |
+
result_infer = compiled_model([input_image])[output_layer]
|
31 |
+
result_index = np.argmax(result_infer)
|
32 |
+
|
33 |
+
# Convert the inference result to a class name.
|
34 |
+
imagenet_classes = open("imagenet_2012.txt").read().splitlines()
|
35 |
+
|
36 |
+
# The model description states that for this model, class 0 is a background.
|
37 |
+
# Therefore, a background must be added at the beginning of imagenet_classes.
|
38 |
+
imagenet_classes = ['background'] + imagenet_classes
|
39 |
+
|
40 |
+
final_result=imagenet_classes[result_index]
|
41 |
+
|
42 |
+
st.write("Inference Result:", final_result)
|