corrected minor things such that everything works well together. Still two existing problems in output/map
Browse files- detectree2model/predictions/predict.py +3 -3
- main.py +5 -3
- output/map.ipynb +2 -2
- polygons_processing/postpprocess_detectree2.py +2 -2
detectree2model/predictions/predict.py
CHANGED
@@ -25,7 +25,7 @@ def create_tiles(input_path, tile_width, tile_height, tile_buffer):
|
|
25 |
img_path = input_path
|
26 |
|
27 |
current_directory = os.getcwd()
|
28 |
-
tiles_directory = os.path.join(current_directory, "tiles")
|
29 |
if not os.path.exists(tiles_directory):
|
30 |
os.makedirs(tiles_directory)
|
31 |
|
@@ -52,7 +52,7 @@ def predict(tile_path, overlap_threshold, confidence_threshold, simplify_value,
|
|
52 |
|
53 |
download_file(url=url, local_filename=trained_model)
|
54 |
|
55 |
-
cfg = setup_cfg(update_model=trained_model)
|
56 |
|
57 |
# hash the following line if you have gpu support
|
58 |
cfg.MODEL.DEVICE = "cpu"
|
@@ -62,7 +62,7 @@ def predict(tile_path, overlap_threshold, confidence_threshold, simplify_value,
|
|
62 |
crowns = stitch_crowns(tile_path + "predictions_geo/", 1)
|
63 |
clean = clean_crowns(crowns, overlap_threshold, confidence=confidence_threshold)
|
64 |
clean = clean.set_geometry(clean.simplify(simplify_value))
|
65 |
-
clean.to_file(store_path + "detectree2_delin.geojson")
|
66 |
|
67 |
def run_detectree2(tif_input_path, store_path, tile_width=20, tile_height=20, tile_buffer=20, overlap_threshold=0.35, confidence_threshold=0.2, simplify_value=0.2):
|
68 |
tile_path = create_tiles(input_path=tif_input_path, tile_width=tile_width, tile_height=tile_height, tile_buffer=tile_buffer)
|
|
|
25 |
img_path = input_path
|
26 |
|
27 |
current_directory = os.getcwd()
|
28 |
+
tiles_directory = os.path.join(current_directory, "tiles/")
|
29 |
if not os.path.exists(tiles_directory):
|
30 |
os.makedirs(tiles_directory)
|
31 |
|
|
|
52 |
|
53 |
download_file(url=url, local_filename=trained_model)
|
54 |
|
55 |
+
cfg = setup_cfg(update_model=trained_model, out_dir=store_path)
|
56 |
|
57 |
# hash the following line if you have gpu support
|
58 |
cfg.MODEL.DEVICE = "cpu"
|
|
|
62 |
crowns = stitch_crowns(tile_path + "predictions_geo/", 1)
|
63 |
clean = clean_crowns(crowns, overlap_threshold, confidence=confidence_threshold)
|
64 |
clean = clean.set_geometry(clean.simplify(simplify_value))
|
65 |
+
clean.to_file(store_path + "/detectree2_delin.geojson")
|
66 |
|
67 |
def run_detectree2(tif_input_path, store_path, tile_width=20, tile_height=20, tile_buffer=20, overlap_threshold=0.35, confidence_threshold=0.2, simplify_value=0.2):
|
68 |
tile_path = create_tiles(input_path=tif_input_path, tile_width=tile_width, tile_height=tile_height, tile_buffer=tile_buffer)
|
main.py
CHANGED
@@ -42,17 +42,19 @@ output_directory: the directory were all in-between and final files are stored
|
|
42 |
generate_tree_images stores the cutout tree images in a separate folder
|
43 |
"""
|
44 |
|
45 |
-
|
46 |
-
|
47 |
|
48 |
current_directory = os.getcwd()
|
|
|
49 |
output_directory = os.path.join(current_directory, "outputs")
|
50 |
if not os.path.exists(output_directory):
|
51 |
os.makedirs(output_directory)
|
52 |
|
53 |
run_detectree2(tif_input, store_path=output_directory)
|
54 |
|
55 |
-
processed_output_df = postprocess(output_directory + '/detectree2_delin.geojson')
|
|
|
56 |
processed_geojson = output_directory + '/processed_delin.geojson'
|
57 |
|
58 |
generate_tree_images(processed_geojson, tif_input)
|
|
|
42 |
generate_tree_images stores the cutout tree images in a separate folder
|
43 |
"""
|
44 |
|
45 |
+
tif_file_name = "TreeCrownVectorDataset_761588_9673769_20_20_32720.tif"
|
46 |
+
tif_input = "/Users/jonathanseele/ETH/Hackathons/EcoHackathon/WeCanopy/test/" + tif_file_name
|
47 |
|
48 |
current_directory = os.getcwd()
|
49 |
+
|
50 |
output_directory = os.path.join(current_directory, "outputs")
|
51 |
if not os.path.exists(output_directory):
|
52 |
os.makedirs(output_directory)
|
53 |
|
54 |
run_detectree2(tif_input, store_path=output_directory)
|
55 |
|
56 |
+
processed_output_df = postprocess(output_directory + '/detectree2_delin.geojson', output_directory + '/processed_delin')
|
57 |
+
|
58 |
processed_geojson = output_directory + '/processed_delin.geojson'
|
59 |
|
60 |
generate_tree_images(processed_geojson, tif_input)
|
output/map.ipynb
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8e257f2bdd28c0df4561a4695a82fc4ee69796d358d0f0d51b3ed407ab3893aa
|
3 |
+
size 12819
|
polygons_processing/postpprocess_detectree2.py
CHANGED
@@ -334,7 +334,7 @@ def export_df_as_geojson(df, filename="output"):
|
|
334 |
def convert_id_to_string(prefix, x):
|
335 |
return prefix + str(x)
|
336 |
|
337 |
-
def postprocess(prediction_geojson_path):
|
338 |
with open(prediction_geojson_path,"r",) as file:
|
339 |
prediction_data = json.load(file)
|
340 |
|
@@ -351,6 +351,6 @@ def postprocess(prediction_geojson_path):
|
|
351 |
|
352 |
df_res = process([df])
|
353 |
|
354 |
-
export_df_as_geojson(df=df_res, filename=
|
355 |
|
356 |
return df_res
|
|
|
334 |
def convert_id_to_string(prefix, x):
|
335 |
return prefix + str(x)
|
336 |
|
337 |
+
def postprocess(prediction_geojson_path, store_path):
|
338 |
with open(prediction_geojson_path,"r",) as file:
|
339 |
prediction_data = json.load(file)
|
340 |
|
|
|
351 |
|
352 |
df_res = process([df])
|
353 |
|
354 |
+
export_df_as_geojson(df=df_res, filename=store_path)
|
355 |
|
356 |
return df_res
|