Spaces:
Runtime error
Runtime error
File size: 1,147 Bytes
5cc6f9a b83cf36 2e66bad e2b5c2b efacc5b e2b5c2b b83cf36 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import streamlit as st
import cv2
import numpy as np
from openvino.runtime import Core
ie = Core()
devices = ie.available_devices
model = ie.read_model(model="v3-small_224_1.0_float.xml")
compiled_model = ie.compile_model(model=model, device_name="CPU")
output_layer = compiled_model.output(0)
# The MobileNet model expects images in RGB format.
image = cv2.cvtColor(cv2.imread(filename="coco.jpg"), code=cv2.COLOR_BGR2RGB)
# Resize to MobileNet image shape.
input_image = cv2.resize(src=image, dsize=(224, 224))
# Reshape to model input shape.
input_image = np.expand_dims(input_image, 0)
st.image(image, caption='Input Image')
result_infer = compiled_model([input_image])[output_layer]
result_index = np.argmax(result_infer)
# Convert the inference result to a class name.
imagenet_classes = open("imagenet_2012.txt").read().splitlines()
# The model description states that for this model, class 0 is a background.
# Therefore, a background must be added at the beginning of imagenet_classes.
imagenet_classes = ['background'] + imagenet_classes
final_result=imagenet_classes[result_index]
st.write("Inference Result:", final_result)
|