Update app.py
Browse filesTrying to get confidences from image.
app.py
CHANGED
@@ -42,7 +42,7 @@ def visualize_prediction(pil_img, output_dict, threshold=0.7, id2label=None):
|
|
42 |
if id2label is not None:
|
43 |
labels = [id2label[x] for x in labels]
|
44 |
|
45 |
-
print("Labels " + str(labels))
|
46 |
|
47 |
plt.figure(figsize=(16, 10))
|
48 |
plt.imshow(pil_img)
|
@@ -81,7 +81,7 @@ def detect_objects(model_name,url_input,image_input,threshold):
|
|
81 |
#Visualize prediction
|
82 |
viz_img = visualize_prediction(image, processed_outputs, threshold, model.config.id2label)
|
83 |
|
84 |
-
return viz_img
|
85 |
|
86 |
def set_example_image(example: list) -> dict:
|
87 |
return gr.Image.update(value=example[0])
|
@@ -122,6 +122,9 @@ with demo:
|
|
122 |
# gr.Markdown(twitter_link)
|
123 |
options = gr.Dropdown(choices=models,label='Select Object Detection Model',show_label=True)
|
124 |
slider_input = gr.Slider(minimum=0.2,maximum=1,value=0.7,label='Prediction Threshold')
|
|
|
|
|
|
|
125 |
|
126 |
with gr.Tabs():
|
127 |
with gr.TabItem('Image URL'):
|
@@ -147,13 +150,13 @@ with demo:
|
|
147 |
img_but = gr.Button('Detect')
|
148 |
|
149 |
|
150 |
-
url_but.click(detect_objects,inputs=[options,url_input,img_input,slider_input],outputs=img_output_from_url,queue=True)
|
151 |
-
img_but.click(detect_objects,inputs=[options,url_input,img_input,slider_input],outputs=img_output_from_upload,queue=True)
|
152 |
example_images.click(fn=set_example_image,inputs=[example_images],outputs=[img_input])
|
153 |
example_url.click(fn=set_example_url,inputs=[example_url],outputs=[url_input])
|
154 |
|
155 |
|
156 |
-
gr.Markdown("![visitor badge](https://visitor-badge.glitch.me/badge?page_id=nickmuchi-object-detection-with-detr-and-yolos)")
|
157 |
|
158 |
|
159 |
demo.launch(enable_queue=True)
|
|
|
42 |
if id2label is not None:
|
43 |
labels = [id2label[x] for x in labels]
|
44 |
|
45 |
+
# print("Labels " + str(labels))
|
46 |
|
47 |
plt.figure(figsize=(16, 10))
|
48 |
plt.imshow(pil_img)
|
|
|
81 |
#Visualize prediction
|
82 |
viz_img = visualize_prediction(image, processed_outputs, threshold, model.config.id2label)
|
83 |
|
84 |
+
return viz_img, processed_outputs
|
85 |
|
86 |
def set_example_image(example: list) -> dict:
|
87 |
return gr.Image.update(value=example[0])
|
|
|
122 |
# gr.Markdown(twitter_link)
|
123 |
options = gr.Dropdown(choices=models,label='Select Object Detection Model',show_label=True)
|
124 |
slider_input = gr.Slider(minimum=0.2,maximum=1,value=0.7,label='Prediction Threshold')
|
125 |
+
|
126 |
+
output_text1 = gr.Textbox(value="", label="Confidence Values URL")
|
127 |
+
output_text2 = gr.Textbox(value="", label="Confidence Values Upload")
|
128 |
|
129 |
with gr.Tabs():
|
130 |
with gr.TabItem('Image URL'):
|
|
|
150 |
img_but = gr.Button('Detect')
|
151 |
|
152 |
|
153 |
+
url_but.click(detect_objects,inputs=[options,url_input,img_input,slider_input],outputs=[img_output_from_url, output_text1],queue=True)
|
154 |
+
img_but.click(detect_objects,inputs=[options,url_input,img_input,slider_input],outputs=[img_output_from_upload, output_text2],queue=True)
|
155 |
example_images.click(fn=set_example_image,inputs=[example_images],outputs=[img_input])
|
156 |
example_url.click(fn=set_example_url,inputs=[example_url],outputs=[url_input])
|
157 |
|
158 |
|
159 |
+
# gr.Markdown("![visitor badge](https://visitor-badge.glitch.me/badge?page_id=nickmuchi-object-detection-with-detr-and-yolos)")
|
160 |
|
161 |
|
162 |
demo.launch(enable_queue=True)
|