Spaces:
Runtime error
Runtime error
new OV-API
Browse files
app.py
CHANGED
@@ -11,8 +11,9 @@ core = Core()
|
|
11 |
|
12 |
# Get the available devices
|
13 |
devices = core.available_devices
|
14 |
-
|
15 |
inferencer = None
|
|
|
|
|
16 |
|
17 |
example_list = [["bottle/examples/000.png", "anomaly_map", "bottle", "CPU"],
|
18 |
["pill/examples/014.png", "heat_map", "pill", "CPU"],
|
@@ -57,27 +58,49 @@ def OV_inference(input_img, operation, category_choice, device):
|
|
57 |
output_img1 = predictions.image
|
58 |
return output_img1, round(inference_time*1000), round(confidence*100,2)
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
with gr.Blocks() as demo:
|
|
|
61 |
gr.Markdown(
|
62 |
"""
|
63 |
<img align="left" width="150" src= "https://github.com/openvinotoolkit/anomalib/assets/10940214/7e61a627-d1b0-4ad4-b602-da9b348c0cbe">
|
64 |
<img align="right" width="150" src= "https://github.com/openvinotoolkit/anomalib/assets/10940214/5d6dd038-b40c-441f-ad38-1cf526137de2">
|
65 |
|
66 |
<h1 align="center"> π Anomaly detection π </h1>
|
67 |
-
|
68 |
-
Experience the power of the state-of-the-art anomaly detection with Anomalib-OpenVINO Anomaly detection toolbox. This interactive APP leverages the robust capabilities of Anomalib and OpenVINO.
|
69 |
-
|
70 |
-
All model are FP32 precision, if you select GPU it will automatically change precision to FP16. Using Anomalib you can also quantize your model in INT8 using NNCF.
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-

|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
"""
|
79 |
)
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
gr.Markdown("## 1. Select the category over you want to detect anormalities.")
|
82 |
category_choice = gr.Radio(["bottle", "grid", "pill", "zipper", "cubes"], label="Choose the category")
|
83 |
|
@@ -92,23 +115,19 @@ with gr.Blocks() as demo:
|
|
92 |
"""
|
93 |
)
|
94 |
device_choice = gr.Dropdown(devices, label="Choose the device")
|
95 |
-
|
96 |
-
gr.Markdown("## 3. Compile the model")
|
97 |
-
compile_btn = gr.Button("Compile Model")
|
98 |
|
99 |
-
gr.Markdown("##
|
100 |
output_choice = gr.Radio(["original", "anomaly_map", "heat_map", "pred_mask", "segmentations"], label="Choose the output")
|
101 |
|
102 |
-
gr.Markdown("##
|
103 |
with gr.Row():
|
104 |
with gr.Column():
|
105 |
-
image = gr.Image(type="numpy", label= "Input image")
|
106 |
-
|
107 |
|
108 |
with gr.Column():
|
109 |
output_img = gr.outputs.Image(type="numpy", label="Anomalib Output")
|
110 |
|
111 |
-
|
112 |
|
113 |
with gr.Row():
|
114 |
# Create your output components
|
@@ -116,17 +135,16 @@ with gr.Blocks() as demo:
|
|
116 |
output_confidence = gr.Textbox(label="Confidence [%]")
|
117 |
output_time = gr.Textbox(label="Inference Time [ms]")
|
118 |
|
119 |
-
gr.Markdown("
|
120 |
-
|
121 |
-
|
122 |
gr.Examples(
|
123 |
examples=example_list,
|
124 |
inputs=[image, output_choice, category_choice, device_choice],
|
125 |
outputs=[output_img, output_time, output_confidence],
|
126 |
-
fn=
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
inference_btn.click(OV_inference, inputs=[image, output_choice], outputs=[output_img, output_time, output_confidence])
|
131 |
|
132 |
demo.launch(enable_queue=True)
|
|
|
11 |
|
12 |
# Get the available devices
|
13 |
devices = core.available_devices
|
|
|
14 |
inferencer = None
|
15 |
+
prev_category_selection = None
|
16 |
+
prev_device_selection = None
|
17 |
|
18 |
example_list = [["bottle/examples/000.png", "anomaly_map", "bottle", "CPU"],
|
19 |
["pill/examples/014.png", "heat_map", "pill", "CPU"],
|
|
|
58 |
output_img1 = predictions.image
|
59 |
return output_img1, round(inference_time*1000), round(confidence*100,2)
|
60 |
|
61 |
+
#Run + Compile the model
|
62 |
+
def OV_compile_run_model(category_choice, device_choice, image, output_choice):
|
63 |
+
#If a different category or device are selected, compile/re-compile the model
|
64 |
+
global prev_category_selection
|
65 |
+
global prev_device_selection
|
66 |
+
if device_choice != prev_device_selection or category_choice != prev_category_selection:
|
67 |
+
OV_compilemodel(category_choice, device_choice)
|
68 |
+
prev_category_selection = category_choice
|
69 |
+
prev_device_selection = device_choice
|
70 |
+
#Run model
|
71 |
+
print("Running model")
|
72 |
+
output_img, output_time, output_confidence = OV_inference(image, output_choice, category_choice, device_choice)
|
73 |
+
return output_img, output_time, output_confidence
|
74 |
+
|
75 |
with gr.Blocks() as demo:
|
76 |
+
|
77 |
gr.Markdown(
|
78 |
"""
|
79 |
<img align="left" width="150" src= "https://github.com/openvinotoolkit/anomalib/assets/10940214/7e61a627-d1b0-4ad4-b602-da9b348c0cbe">
|
80 |
<img align="right" width="150" src= "https://github.com/openvinotoolkit/anomalib/assets/10940214/5d6dd038-b40c-441f-ad38-1cf526137de2">
|
81 |
|
82 |
<h1 align="center"> π Anomaly detection π </h1>
|
83 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
"""
|
85 |
)
|
86 |
|
87 |
+
with gr.Row():
|
88 |
+
with gr.Column():
|
89 |
+
gr.Markdown(
|
90 |
+
"""
|
91 |
+
Experience the power of the state-of-the-art anomaly detection with Anomalib-OpenVINO Anomaly detection toolbox. This interactive APP leverages the robust capabilities of Anomalib and OpenVINO.
|
92 |
+
|
93 |
+
All model are FP32 precision, if you select GPU it will automatically change precision to FP16. Using Anomalib you can also quantize your model in INT8 using NNCF.
|
94 |
+
"""
|
95 |
+
)
|
96 |
+
|
97 |
+
with gr.Column():
|
98 |
+
gr.Markdown(
|
99 |
+
"""
|
100 |
+

|
101 |
+
"""
|
102 |
+
)
|
103 |
+
|
104 |
gr.Markdown("## 1. Select the category over you want to detect anormalities.")
|
105 |
category_choice = gr.Radio(["bottle", "grid", "pill", "zipper", "cubes"], label="Choose the category")
|
106 |
|
|
|
115 |
"""
|
116 |
)
|
117 |
device_choice = gr.Dropdown(devices, label="Choose the device")
|
|
|
|
|
|
|
118 |
|
119 |
+
gr.Markdown("## 3. Choose the output you want to visualize.")
|
120 |
output_choice = gr.Radio(["original", "anomaly_map", "heat_map", "pred_mask", "segmentations"], label="Choose the output")
|
121 |
|
122 |
+
gr.Markdown("## 4. Drop the image in the input image box and run the inference")
|
123 |
with gr.Row():
|
124 |
with gr.Column():
|
125 |
+
image = gr.Image(type="numpy", label= "Input image")
|
|
|
126 |
|
127 |
with gr.Column():
|
128 |
output_img = gr.outputs.Image(type="numpy", label="Anomalib Output")
|
129 |
|
130 |
+
compile_inference_btn = gr.Button("Compile Model + Run Inference")
|
131 |
|
132 |
with gr.Row():
|
133 |
# Create your output components
|
|
|
135 |
output_confidence = gr.Textbox(label="Confidence [%]")
|
136 |
output_time = gr.Textbox(label="Inference Time [ms]")
|
137 |
|
138 |
+
gr.Markdown("Changing your choice of category or device will recompile the model.")
|
139 |
+
|
140 |
+
gr.Markdown("## OR use our image examples for a quick start")
|
141 |
gr.Examples(
|
142 |
examples=example_list,
|
143 |
inputs=[image, output_choice, category_choice, device_choice],
|
144 |
outputs=[output_img, output_time, output_confidence],
|
145 |
+
fn=OV_compile_run_model)
|
146 |
+
|
147 |
+
compile_inference_btn.click(OV_compile_run_model, inputs=[category_choice, device_choice, image, output_choice],
|
148 |
+
outputs=[output_img, output_time, output_confidence])
|
|
|
149 |
|
150 |
demo.launch(enable_queue=True)
|