From 803d2f9a873fb61f06fb97a453c7cc0c7835a120 Mon Sep 17 00:00:00 2001 From: "Puming (Oscar) Jiang" <105928971+0scarJ1ang@users.noreply.github.com> Date: Sun, 20 Aug 2023 03:36:29 +0100 Subject: [PATCH 1/7] Update project_to_geojson check the format of crowns --- detectree2/models/outputs.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/detectree2/models/outputs.py b/detectree2/models/outputs.py index 1b98b66d..89d5c71f 100644 --- a/detectree2/models/outputs.py +++ b/detectree2/models/outputs.py @@ -142,7 +142,7 @@ def to_eval_geojson(directory=None): # noqa:N803 json.dump(geofile, dest) -def project_to_geojson(tiles_path, pred_fold=None, output_fold=None): # noqa:N803 +def project_to_geojson(tiles_path, pred_fold=None, output_fold=None, Multi_class = False): # noqa:N803 """Projects json predictions back in geographic space. Takes a json and changes it to a geojson so it can overlay with orthomosaic. Another copy is produced to overlay @@ -189,6 +189,8 @@ def project_to_geojson(tiles_path, pred_fold=None, output_fold=None): # noqa:N8 # json file is formated as a list of segmentation polygons so cycle through each one for crown_data in datajson: + if Multi_class == True: + print(crown_data) crown = crown_data["segmentation"] confidence_score = crown_data["score"] From d4592e88e4ec75e0c35f8092f201e41af99e0fd4 Mon Sep 17 00:00:00 2001 From: "Puming (Oscar) Jiang" <105928971+0scarJ1ang@users.noreply.github.com> Date: Sun, 20 Aug 2023 03:58:16 +0100 Subject: [PATCH 2/7] Update function project_to_geojson To let the class information be saved as well --- detectree2/models/outputs.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/detectree2/models/outputs.py b/detectree2/models/outputs.py index 61b5150e..be8247a5 100644 --- a/detectree2/models/outputs.py +++ b/detectree2/models/outputs.py @@ -191,7 +191,7 @@ def project_to_geojson(tiles_path, pred_fold=None, output_fold=None, Multi_class # json file is formated as a list of segmentation polygons so cycle through each one for crown_data in datajson: if Multi_class == True: - print(crown_data) + category = crown_data["category_id"] crown = crown_data["segmentation"] confidence_score = crown_data["score"] @@ -218,6 +218,13 @@ def project_to_geojson(tiles_path, pred_fold=None, output_fold=None, Multi_class "coordinates": [moved_coords], }, }) + if Multi_class= True: + geofile["features"].append({ + "type": "Feature", + "properties": { + "category": category + }, + }) output_geo_file = os.path.join(output_fold, filename.with_suffix(".geojson").name) From 43751cb77a8592da33002d7072beddeb024e4307 Mon Sep 17 00:00:00 2001 From: "Puming (Oscar) Jiang" <105928971+0scarJ1ang@users.noreply.github.com> Date: Sun, 20 Aug 2023 04:04:21 +0100 Subject: [PATCH 3/7] Update outputs.py --- detectree2/models/outputs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detectree2/models/outputs.py b/detectree2/models/outputs.py index be8247a5..1414ad40 100644 --- a/detectree2/models/outputs.py +++ b/detectree2/models/outputs.py @@ -218,7 +218,7 @@ def project_to_geojson(tiles_path, pred_fold=None, output_fold=None, Multi_class "coordinates": [moved_coords], }, }) - if Multi_class= True: + if Multi_class == True: geofile["features"].append({ "type": "Feature", "properties": { From 6ca1f853b11656d93f1a33dbf8c3b0ef15ff9731 Mon Sep 17 00:00:00 2001 From: "Puming (Oscar) Jiang" <105928971+0scarJ1ang@users.noreply.github.com> Date: Sun, 20 Aug 2023 04:47:00 +0100 Subject: [PATCH 4/7] Update outputs.py debugging --- detectree2/models/outputs.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/detectree2/models/outputs.py b/detectree2/models/outputs.py index 1414ad40..572af92c 100644 --- a/detectree2/models/outputs.py +++ b/detectree2/models/outputs.py @@ -192,6 +192,7 @@ def project_to_geojson(tiles_path, pred_fold=None, output_fold=None, Multi_class for crown_data in datajson: if Multi_class == True: category = crown_data["category_id"] + print(category) crown = crown_data["segmentation"] confidence_score = crown_data["score"] @@ -225,6 +226,7 @@ def project_to_geojson(tiles_path, pred_fold=None, output_fold=None, Multi_class "category": category }, }) + print(geofile["features"]) output_geo_file = os.path.join(output_fold, filename.with_suffix(".geojson").name) From 8d847e5f43f135d0d0f8bcdbcef4c1173a4a7e43 Mon Sep 17 00:00:00 2001 From: "Puming (Oscar) Jiang" <105928971+0scarJ1ang@users.noreply.github.com> Date: Sun, 20 Aug 2023 04:56:48 +0100 Subject: [PATCH 5/7] Update outputs.py debug --- detectree2/models/outputs.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/detectree2/models/outputs.py b/detectree2/models/outputs.py index 572af92c..f61d1471 100644 --- a/detectree2/models/outputs.py +++ b/detectree2/models/outputs.py @@ -192,7 +192,7 @@ def project_to_geojson(tiles_path, pred_fold=None, output_fold=None, Multi_class for crown_data in datajson: if Multi_class == True: category = crown_data["category_id"] - print(category) + # print(category) crown = crown_data["segmentation"] confidence_score = crown_data["score"] @@ -208,25 +208,31 @@ def project_to_geojson(tiles_path, pred_fold=None, output_fold=None, Multi_class rows=crown_coords_array[:, 1], cols=crown_coords_array[:, 0]) moved_coords = list(zip(x_coords, y_coords)) - - geofile["features"].append({ - "type": "Feature", - "properties": { - "Confidence_score": confidence_score - }, - "geometry": { - "type": "Polygon", - "coordinates": [moved_coords], - }, - }) + if Multi_class == False: + geofile["features"].append({ + "type": "Feature", + "properties": { + "Confidence_score": confidence_score + "category": category + }, + "geometry": { + "type": "Polygon", + "coordinates": [moved_coords], + }, + }) if Multi_class == True: geofile["features"].append({ "type": "Feature", "properties": { + "Confidence_score": confidence_score "category": category }, + "geometry": { + "type": "Polygon", + "coordinates": [moved_coords], + }, }) - print(geofile["features"]) + # print(geofile["features"]) output_geo_file = os.path.join(output_fold, filename.with_suffix(".geojson").name) From ec1fa6709c0fa72e4d7d60915d6461817843fbc8 Mon Sep 17 00:00:00 2001 From: "Puming (Oscar) Jiang" <105928971+0scarJ1ang@users.noreply.github.com> Date: Sun, 20 Aug 2023 05:05:06 +0100 Subject: [PATCH 6/7] Update outputs.py --- detectree2/models/outputs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/detectree2/models/outputs.py b/detectree2/models/outputs.py index f61d1471..518e3055 100644 --- a/detectree2/models/outputs.py +++ b/detectree2/models/outputs.py @@ -213,7 +213,6 @@ def project_to_geojson(tiles_path, pred_fold=None, output_fold=None, Multi_class "type": "Feature", "properties": { "Confidence_score": confidence_score - "category": category }, "geometry": { "type": "Polygon", From e57647ef78183bf9e88d894e2eed5f18320bbf8f Mon Sep 17 00:00:00 2001 From: "Puming (Oscar) Jiang" <105928971+0scarJ1ang@users.noreply.github.com> Date: Sun, 20 Aug 2023 05:11:56 +0100 Subject: [PATCH 7/7] Update outputs.py --- detectree2/models/outputs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/detectree2/models/outputs.py b/detectree2/models/outputs.py index 518e3055..67f725ef 100644 --- a/detectree2/models/outputs.py +++ b/detectree2/models/outputs.py @@ -223,8 +223,8 @@ def project_to_geojson(tiles_path, pred_fold=None, output_fold=None, Multi_class geofile["features"].append({ "type": "Feature", "properties": { - "Confidence_score": confidence_score - "category": category + "Confidence_score": confidence_score, + "category": category, }, "geometry": { "type": "Polygon",