Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -31,14 +31,15 @@ cfg.MODEL.WEIGHTS = "model_weights/chatswood_buildings_poc.pth"
|
|
31 |
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 8
|
32 |
predictor = DefaultPredictor(cfg)
|
33 |
|
34 |
-
def segment_buildings(
|
35 |
|
36 |
-
im =
|
37 |
outputs = predictor(im)
|
38 |
v = Visualizer(im[:, :, ::-1],
|
39 |
scale=0.5,
|
40 |
instance_mode=ColorMode.IMAGE_BW
|
41 |
)
|
|
|
42 |
out = v.draw_instance_predictions(outputs["instances"].to("cpu"))
|
43 |
|
44 |
return Image.fromarray(out.get_image()[:, :, ::-1])
|
@@ -49,16 +50,14 @@ gr_slider_confidence = gr.inputs.Slider(0,1,.1,.7,
|
|
49 |
label='Set confidence threshold % for masks')
|
50 |
"""
|
51 |
# gradio outputs
|
52 |
-
|
53 |
-
|
54 |
|
55 |
title = "Building Segmentation"
|
56 |
description = "An instance segmentation demo for identifying boundaries of buildings in aerial images using DETR (End-to-End Object Detection) model with MaskRCNN-101 backbone"
|
57 |
|
58 |
# Create user interface and launch
|
59 |
gr.Interface(segment_buildings,
|
60 |
-
inputs =
|
61 |
-
outputs =
|
62 |
-
|
63 |
-
enable_queue = True,
|
64 |
-
description = description).launch()
|
|
|
31 |
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 8
|
32 |
predictor = DefaultPredictor(cfg)
|
33 |
|
34 |
+
def segment_buildings(im):
|
35 |
|
36 |
+
im = np.array(im)
|
37 |
outputs = predictor(im)
|
38 |
v = Visualizer(im[:, :, ::-1],
|
39 |
scale=0.5,
|
40 |
instance_mode=ColorMode.IMAGE_BW
|
41 |
)
|
42 |
+
print(len(outputs["instances"])," buildings detected.")
|
43 |
out = v.draw_instance_predictions(outputs["instances"].to("cpu"))
|
44 |
|
45 |
return Image.fromarray(out.get_image()[:, :, ::-1])
|
|
|
50 |
label='Set confidence threshold % for masks')
|
51 |
"""
|
52 |
# gradio outputs
|
53 |
+
inputs = gr.inputs.Image(type="pil", label="Input Image")
|
54 |
+
outputs = gr.outputs.Image(type="pil", label="Output Image")
|
55 |
|
56 |
title = "Building Segmentation"
|
57 |
description = "An instance segmentation demo for identifying boundaries of buildings in aerial images using DETR (End-to-End Object Detection) model with MaskRCNN-101 backbone"
|
58 |
|
59 |
# Create user interface and launch
|
60 |
gr.Interface(segment_buildings,
|
61 |
+
inputs = inputs,
|
62 |
+
outputs = outputs,
|
63 |
+
description = description).launch(debug=True)
|
|
|
|