Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,9 +30,9 @@ cfg.MODEL.DEVICE='cpu'
|
|
| 30 |
cfg.MODEL.WEIGHTS = "model_weights/treev1_best.pth"
|
| 31 |
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 2
|
| 32 |
|
| 33 |
-
def segment_image(im):
|
| 34 |
-
|
| 35 |
-
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST =
|
| 36 |
predictor = DefaultPredictor(cfg)
|
| 37 |
im = np.array(im)
|
| 38 |
outputs = predictor(im)
|
|
@@ -46,10 +46,10 @@ def segment_image(im):
|
|
| 46 |
return Image.fromarray(out.get_image()[:, :, ::-1])
|
| 47 |
|
| 48 |
# gradio components
|
| 49 |
-
|
| 50 |
gr_slider_confidence = gr.inputs.Slider(0,1,.1,.7,
|
| 51 |
label='Set confidence threshold % for masks')
|
| 52 |
-
|
| 53 |
# gradio outputs
|
| 54 |
inputs = gr.inputs.Image(type="pil", label="Input Image")
|
| 55 |
outputs = gr.outputs.Image(type="pil", label="Output Image")
|
|
@@ -59,7 +59,7 @@ description = "An instance segmentation demo for identifying trees in aerial ima
|
|
| 59 |
|
| 60 |
# Create user interface and launch
|
| 61 |
gr.Interface(segment_image,
|
| 62 |
-
inputs = inputs,
|
| 63 |
outputs = outputs,
|
| 64 |
title = title,
|
| 65 |
description = description).launch(debug=True)
|
|
|
|
| 30 |
cfg.MODEL.WEIGHTS = "model_weights/treev1_best.pth"
|
| 31 |
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 2
|
| 32 |
|
| 33 |
+
def segment_image(im, confidence_threshold):
|
| 34 |
+
# cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.25
|
| 35 |
+
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = confidence_threshold
|
| 36 |
predictor = DefaultPredictor(cfg)
|
| 37 |
im = np.array(im)
|
| 38 |
outputs = predictor(im)
|
|
|
|
| 46 |
return Image.fromarray(out.get_image()[:, :, ::-1])
|
| 47 |
|
| 48 |
# gradio components
|
| 49 |
+
|
| 50 |
gr_slider_confidence = gr.inputs.Slider(0,1,.1,.7,
|
| 51 |
label='Set confidence threshold % for masks')
|
| 52 |
+
|
| 53 |
# gradio outputs
|
| 54 |
inputs = gr.inputs.Image(type="pil", label="Input Image")
|
| 55 |
outputs = gr.outputs.Image(type="pil", label="Output Image")
|
|
|
|
| 59 |
|
| 60 |
# Create user interface and launch
|
| 61 |
gr.Interface(segment_image,
|
| 62 |
+
inputs = [inputs, gr_slider_confidence],
|
| 63 |
outputs = outputs,
|
| 64 |
title = title,
|
| 65 |
description = description).launch(debug=True)
|