Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,7 @@ class InferenceConfig(Config):
|
|
18 |
|
19 |
config = InferenceConfig()
|
20 |
|
21 |
-
#
|
22 |
model = modellib.MaskRCNN(mode="inference", config=config, model_dir=os.getcwd())
|
23 |
|
24 |
# Load the Mask R-CNN model weights
|
@@ -34,7 +34,7 @@ def apply_mask_rcnn(image):
|
|
34 |
image = cv2.cvtColor(image, cv2.COLOR_RGBA2RGB)
|
35 |
|
36 |
# Resize the image to match the model input size (for inference)
|
37 |
-
resized_image = cv2.resize(image, (1024, 1024)) # Adjust based on
|
38 |
input_image = np.expand_dims(resized_image, axis=0)
|
39 |
|
40 |
# Use Mask R-CNN to predict
|
@@ -62,27 +62,25 @@ def apply_mask_rcnn(image):
|
|
62 |
return image # Return original image if segmentation fails
|
63 |
|
64 |
# Gradio interface definition
|
65 |
-
inputs = gr.Image(source="upload", tool="editor", type="numpy", label="Upload an image")
|
66 |
-
outputs = gr.Image(type="numpy", label="Segmented Image")
|
67 |
-
|
68 |
-
# Gradio app layout
|
69 |
with gr.Blocks() as demo:
|
70 |
gr.Markdown("<h1 style='text-align: center;'>Image Segmentation with Mask R-CNN</h1>")
|
71 |
gr.Markdown("Upload an image to see segmentation results using the Mask R-CNN model.")
|
72 |
-
|
73 |
# Input and output layout
|
74 |
with gr.Row():
|
75 |
with gr.Column():
|
76 |
gr.Markdown("### Upload an Image")
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
gr.Button("Submit").click(fn=apply_mask_rcnn, inputs=inputs, outputs=outputs)
|
81 |
-
gr.Button("Clear").click(fn=lambda: None)
|
82 |
|
83 |
with gr.Column():
|
84 |
gr.Markdown("### Segmented Image Output")
|
85 |
-
|
|
|
|
|
|
|
|
|
86 |
|
87 |
# Launch the Gradio app
|
88 |
demo.launch()
|
|
|
18 |
|
19 |
config = InferenceConfig()
|
20 |
|
21 |
+
# Initialize the Mask R-CNN model
|
22 |
model = modellib.MaskRCNN(mode="inference", config=config, model_dir=os.getcwd())
|
23 |
|
24 |
# Load the Mask R-CNN model weights
|
|
|
34 |
image = cv2.cvtColor(image, cv2.COLOR_RGBA2RGB)
|
35 |
|
36 |
# Resize the image to match the model input size (for inference)
|
37 |
+
resized_image = cv2.resize(image, (1024, 1024)) # Adjust based on model input requirements
|
38 |
input_image = np.expand_dims(resized_image, axis=0)
|
39 |
|
40 |
# Use Mask R-CNN to predict
|
|
|
62 |
return image # Return original image if segmentation fails
|
63 |
|
64 |
# Gradio interface definition
|
|
|
|
|
|
|
|
|
65 |
with gr.Blocks() as demo:
|
66 |
gr.Markdown("<h1 style='text-align: center;'>Image Segmentation with Mask R-CNN</h1>")
|
67 |
gr.Markdown("Upload an image to see segmentation results using the Mask R-CNN model.")
|
68 |
+
|
69 |
# Input and output layout
|
70 |
with gr.Row():
|
71 |
with gr.Column():
|
72 |
gr.Markdown("### Upload an Image")
|
73 |
+
input_image = gr.Image(source="upload", tool="editor", type="numpy", label="Upload an image")
|
74 |
+
submit_btn = gr.Button("Submit")
|
75 |
+
clear_btn = gr.Button("Clear")
|
|
|
|
|
76 |
|
77 |
with gr.Column():
|
78 |
gr.Markdown("### Segmented Image Output")
|
79 |
+
output_image = gr.Image(type="numpy", label="Segmented Image")
|
80 |
+
|
81 |
+
# Set up button functionality
|
82 |
+
submit_btn.click(fn=apply_mask_rcnn, inputs=input_image, outputs=output_image)
|
83 |
+
clear_btn.click(fn=lambda: None)
|
84 |
|
85 |
# Launch the Gradio app
|
86 |
demo.launch()
|