Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -25,59 +25,59 @@ import glob
|
|
25 |
# from intake_zenodo_fetcher import download_zenodo_files_for_entry
|
26 |
|
27 |
# geospatial libraries
|
28 |
-
import geopandas as gpd
|
29 |
|
30 |
-
from rasterio.transform import from_origin
|
31 |
-
import rasterio.features
|
32 |
|
33 |
-
import fiona
|
34 |
|
35 |
-
from shapely.geometry import shape, mapping, box
|
36 |
-
from shapely.geometry.multipolygon import MultiPolygon
|
37 |
|
38 |
-
# machine learning libraries
|
39 |
-
from detectron2 import model_zoo
|
40 |
-
from detectron2.engine import DefaultPredictor
|
41 |
-
from detectron2.utils.visualizer import Visualizer, ColorMode
|
42 |
-
from detectron2.config import get_cfg
|
43 |
-
from detectron2.engine import DefaultTrainer
|
44 |
-
# define the URL to retrieve the model
|
45 |
-
fn = 'model_final.pth'
|
46 |
-
url = f'https://zenodo.org/record/5515408/files/{fn}?download=1'
|
47 |
|
48 |
-
urllib.request.urlretrieve(url, config['model'] + '/' + fn)
|
49 |
|
50 |
# import geoviews.tile_sources as gts
|
51 |
|
52 |
# import hvplot.pandas
|
53 |
# import hvplot.xarray
|
54 |
|
55 |
-
# hv.extension('bokeh', width=100)
|
56 |
-
cfg = get_cfg()
|
57 |
|
58 |
-
# if you want to make predictions using a CPU, run the following line. If using GPU, hash it out.
|
59 |
-
cfg.MODEL.DEVICE='cuda'
|
60 |
|
61 |
-
# model and hyperparameter selection
|
62 |
-
cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml"))
|
63 |
-
cfg.DATALOADER.NUM_WORKERS = 2
|
64 |
-
cfg.SOLVER.IMS_PER_BATCH = 2
|
65 |
-
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 1
|
66 |
|
67 |
-
### path to the saved pre-trained model weights
|
68 |
-
cfg.MODEL.WEIGHTS = config['model'] + '/model_final.pth'
|
69 |
|
70 |
-
# set confidence threshold at which we predict
|
71 |
-
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.15
|
72 |
|
73 |
-
#### Settings for predictions using detectron config
|
74 |
|
75 |
-
predictor = DefaultPredictor(cfg)
|
76 |
-
outputs = predictor(im)
|
77 |
-
v = Visualizer(im[:, :, ::-1], scale=1.5, instance_mode=ColorMode.IMAGE_BW) # remove the colors of unsegmented pixels
|
78 |
-
v = v.draw_instance_predictions(outputs["instances"].to("cpu"))
|
79 |
-
image = cv2.cvtColor(v.get_image()[:, :, :], cv2.COLOR_BGR2RGB)
|
80 |
-
st.image(image, caption='Segmented Panoramic Image Detecttree', channels ='RGB', use_column_width=True)
|
81 |
|
82 |
|
83 |
model = main.deepforest()
|
|
|
25 |
# from intake_zenodo_fetcher import download_zenodo_files_for_entry
|
26 |
|
27 |
# geospatial libraries
|
28 |
+
# import geopandas as gpd
|
29 |
|
30 |
+
# from rasterio.transform import from_origin
|
31 |
+
# import rasterio.features
|
32 |
|
33 |
+
# import fiona
|
34 |
|
35 |
+
# from shapely.geometry import shape, mapping, box
|
36 |
+
# from shapely.geometry.multipolygon import MultiPolygon
|
37 |
|
38 |
+
# # machine learning libraries
|
39 |
+
# from detectron2 import model_zoo
|
40 |
+
# from detectron2.engine import DefaultPredictor
|
41 |
+
# from detectron2.utils.visualizer import Visualizer, ColorMode
|
42 |
+
# from detectron2.config import get_cfg
|
43 |
+
# from detectron2.engine import DefaultTrainer
|
44 |
+
# # define the URL to retrieve the model
|
45 |
+
# fn = 'model_final.pth'
|
46 |
+
# url = f'https://zenodo.org/record/5515408/files/{fn}?download=1'
|
47 |
|
48 |
+
# urllib.request.urlretrieve(url, config['model'] + '/' + fn)
|
49 |
|
50 |
# import geoviews.tile_sources as gts
|
51 |
|
52 |
# import hvplot.pandas
|
53 |
# import hvplot.xarray
|
54 |
|
55 |
+
# # hv.extension('bokeh', width=100)
|
56 |
+
# cfg = get_cfg()
|
57 |
|
58 |
+
# # if you want to make predictions using a CPU, run the following line. If using GPU, hash it out.
|
59 |
+
# cfg.MODEL.DEVICE='cuda'
|
60 |
|
61 |
+
# # model and hyperparameter selection
|
62 |
+
# cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rcnn_R_101_FPN_3x.yaml"))
|
63 |
+
# cfg.DATALOADER.NUM_WORKERS = 2
|
64 |
+
# cfg.SOLVER.IMS_PER_BATCH = 2
|
65 |
+
# cfg.MODEL.ROI_HEADS.NUM_CLASSES = 1
|
66 |
|
67 |
+
# ### path to the saved pre-trained model weights
|
68 |
+
# cfg.MODEL.WEIGHTS = config['model'] + '/model_final.pth'
|
69 |
|
70 |
+
# # set confidence threshold at which we predict
|
71 |
+
# cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.15
|
72 |
|
73 |
+
# #### Settings for predictions using detectron config
|
74 |
|
75 |
+
# predictor = DefaultPredictor(cfg)
|
76 |
+
# outputs = predictor(im)
|
77 |
+
# v = Visualizer(im[:, :, ::-1], scale=1.5, instance_mode=ColorMode.IMAGE_BW) # remove the colors of unsegmented pixels
|
78 |
+
# v = v.draw_instance_predictions(outputs["instances"].to("cpu"))
|
79 |
+
# image = cv2.cvtColor(v.get_image()[:, :, :], cv2.COLOR_BGR2RGB)
|
80 |
+
# st.image(image, caption='Segmented Panoramic Image Detecttree', channels ='RGB', use_column_width=True)
|
81 |
|
82 |
|
83 |
model = main.deepforest()
|