Spaces:
Runtime error
Runtime error
stable version of the deepforest demo
Browse files- app.py +26 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from deepforest import main
|
| 4 |
+
from deepforest import get_data
|
| 5 |
+
import os
|
| 6 |
+
import matplotlib.pyplot as plt
|
| 7 |
+
import rasterio
|
| 8 |
+
from PIL import Image
|
| 9 |
+
|
| 10 |
+
#img = model.predict_image(path="/Users/benweinstein/Documents/NeonTreeEvaluation/evaluation/RGB/TEAK_049_2019.tif",return_plot=True)
|
| 11 |
+
|
| 12 |
+
#predict_image returns plot in BlueGreenRed (opencv style), but matplotlib likes RedGreenBlue, switch the channel order.
|
| 13 |
+
def predictDeepForest(input_img):
|
| 14 |
+
model = main.deepforest()
|
| 15 |
+
model.use_release()
|
| 16 |
+
#print(input_img.shape)
|
| 17 |
+
im = Image.open(input_img)
|
| 18 |
+
im = np.array(im)
|
| 19 |
+
img = model.predict_image(im, return_plot=True)
|
| 20 |
+
img.shape
|
| 21 |
+
plt.imshow(img[:,:,::-1])
|
| 22 |
+
return img
|
| 23 |
+
#gr.Image(type="filepath", shape=...)
|
| 24 |
+
|
| 25 |
+
demo = gr.Interface(predictDeepForest, gr.Image(type="filepath"), "image")
|
| 26 |
+
demo.launch(debug = True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
deepforest
|
| 2 |
+
gradio
|
| 3 |
+
rasterio
|
| 4 |
+
matplotlib
|
| 5 |
+
PIL
|