File size: 872 Bytes
86e57da
cd89577
86e57da
 
 
 
 
94c4f04
 
 
 
 
 
aa4b58f
b20fee7
53dc852
 
b20fee7
53dc852
 
8cc8d3d
53dc852
 
10395db
56fb5c0
10395db
10637e2
94c4f04
86e57da
 
 
 
 
b70ebda
86e57da
 
 
 
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
38
39
import numpy as np
from PIL import Image
import gradio as gr
from onnx import hub
import onnxruntime as ort
import onnx



onnx_model = onnx.load("M-Raw.onnx")
text = onnx.checker.check_model(onnx_model)
print("The model is checked")

def snap(image):
    image = Image.fromarray(image) # np to pil
    print(image)
    print("-----------")
    image = image.resize((640, 640))
    print(image)
    print("-----------")
    image = np.asarray(image, dtype=np.float32)/255
    print(image)
    print("-----------")
    image = image[np.newaxis, ...].transpose((0,3,1,2))
    ort_sess = ort.InferenceSession("M-Raw.onnx")
    output = ort_sess.run(["output0"], {"images": image})
    print(output)
    return [output]


demo = gr.Interface(
    snap,
    [gr.Image(source="webcam", tool=None, streaming=True)],
    ["image"],
)

if __name__ == "__main__":
    demo.launch()