Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -77,6 +77,27 @@ def inference(image_url, image, min_score, model_name):
|
|
| 77 |
|
| 78 |
return out.get_image()
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
title = "# DBMDZ Detectron2 Model Demo"
|
| 82 |
description = """
|
|
@@ -107,7 +128,7 @@ with gr.Blocks() as demo:
|
|
| 107 |
|
| 108 |
inference_button = gr.Button("Submit")
|
| 109 |
|
| 110 |
-
inference_button.click(fn=
|
| 111 |
|
| 112 |
gr.Markdown(footer)
|
| 113 |
|
|
|
|
| 77 |
|
| 78 |
return out.get_image()
|
| 79 |
|
| 80 |
+
def inferenceScore(image_url, image, min_score, model_name):
|
| 81 |
+
if image_url:
|
| 82 |
+
r = requests.get(image_url)
|
| 83 |
+
if r:
|
| 84 |
+
im = np.frombuffer(r.content, dtype="uint8")
|
| 85 |
+
im = cv2.imdecode(im, cv2.IMREAD_COLOR)
|
| 86 |
+
else:
|
| 87 |
+
# Model expect BGR!
|
| 88 |
+
im = image[:,:,::-1]
|
| 89 |
+
|
| 90 |
+
model_id = model_name_to_id[model_name]
|
| 91 |
+
|
| 92 |
+
models[model_id]["cfg"].MODEL.ROI_HEADS.SCORE_THRESH_TEST = min_score
|
| 93 |
+
predictor = DefaultPredictor(models[model_id]["cfg"])
|
| 94 |
+
|
| 95 |
+
outputs = predictor(im)
|
| 96 |
+
|
| 97 |
+
v = Visualizer(im, models[model_id]["metadata"], scale=1.2)
|
| 98 |
+
out = v.draw_instance_predictions(outputs["instances"]..scores[1])
|
| 99 |
+
|
| 100 |
+
return out
|
| 101 |
|
| 102 |
title = "# DBMDZ Detectron2 Model Demo"
|
| 103 |
description = """
|
|
|
|
| 128 |
|
| 129 |
inference_button = gr.Button("Submit")
|
| 130 |
|
| 131 |
+
inference_button.click(fn=inferenceScore, inputs=[url_input, image_input, min_score, model_name], outputs=output_image)
|
| 132 |
|
| 133 |
gr.Markdown(footer)
|
| 134 |
|