Spaces:
Sleeping
Sleeping
example for Shirley
Browse files- README.md +1 -1
- app.py +39 -0
- example.jpg +0 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: DeepForest
|
3 |
-
emoji:
|
4 |
colorFrom: pink
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
|
|
1 |
---
|
2 |
title: DeepForest
|
3 |
+
emoji: 🌴
|
4 |
colorFrom: pink
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from deepforest import main
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
|
5 |
+
# Initialize the deepforest model and use the released version
|
6 |
+
model = main.deepforest()
|
7 |
+
model.use_release()
|
8 |
+
|
9 |
+
def predict_and_visualize(image):
|
10 |
+
"""
|
11 |
+
Function to predict and visualize the image using deepforest model.
|
12 |
+
|
13 |
+
Args:
|
14 |
+
- image: An image array.
|
15 |
+
|
16 |
+
Returns:
|
17 |
+
- An image with predictions visualized.
|
18 |
+
"""
|
19 |
+
# Predict image and return plot. Since Gradio passes image as array, save it temporarily.
|
20 |
+
temp_path = "/tmp/uploaded_image.png"
|
21 |
+
plt.imsave(temp_path, image)
|
22 |
+
img = model.predict_image(path=temp_path, return_plot=True)
|
23 |
+
|
24 |
+
# Since the output is BGR and matplotlib (and hence Gradio) needs RGB, we convert the color scheme
|
25 |
+
img_rgb = img[:, :, ::-1]
|
26 |
+
|
27 |
+
# Return the RGB image
|
28 |
+
return img_rgb
|
29 |
+
|
30 |
+
# Define the Gradio interface
|
31 |
+
iface = gr.Interface(fn=predict_and_visualize,
|
32 |
+
inputs=gr.Image(type="numpy", label="Upload Image"),
|
33 |
+
outputs=gr.Image(label="Predicted Image"),
|
34 |
+
title="DeepForest Tree Detection",
|
35 |
+
examples=["./example.jpg"]
|
36 |
+
description="Upload an image to detect trees using the DeepForest model.")
|
37 |
+
|
38 |
+
# Launch the Gradio app
|
39 |
+
iface.launch()
|
example.jpg
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
deepforest
|
3 |
+
matplotlib
|