From ab54d365b7270200c85d36821632f101f75da5da Mon Sep 17 00:00:00 2001 From: Ariel Jassan Date: Sun, 27 Oct 2024 11:22:54 +0200 Subject: [PATCH 1/7] Update requirements.txt --- people-and-planet-ai/land-cover-classification/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/people-and-planet-ai/land-cover-classification/requirements.txt b/people-and-planet-ai/land-cover-classification/requirements.txt index ecf024c18c2..31fc458da41 100644 --- a/people-and-planet-ai/land-cover-classification/requirements.txt +++ b/people-and-planet-ai/land-cover-classification/requirements.txt @@ -1,5 +1,5 @@ # Requirements to run the notebooks. -apache-beam[gcp]==2.46.0 +apache-beam[gcp]==2.60.0 earthengine-api==0.1.395 folium==0.16.0 google-cloud-aiplatform==1.47.0 From 08fd53ed79f2aae0b3a157888a83802f1898686b Mon Sep 17 00:00:00 2001 From: Ariel Jassan Date: Sun, 27 Oct 2024 11:30:01 +0200 Subject: [PATCH 2/7] Update requirements.txt --- .../land-cover-classification/requirements.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/people-and-planet-ai/land-cover-classification/requirements.txt b/people-and-planet-ai/land-cover-classification/requirements.txt index 31fc458da41..ef5cd594103 100644 --- a/people-and-planet-ai/land-cover-classification/requirements.txt +++ b/people-and-planet-ai/land-cover-classification/requirements.txt @@ -3,6 +3,9 @@ apache-beam[gcp]==2.60.0 earthengine-api==0.1.395 folium==0.16.0 google-cloud-aiplatform==1.47.0 +google-cloud-bigtable>=2.24.0 imageio==2.34.2 +numpy>=1.24.0 plotly==5.15.0 +pyarrow>=10.0.1 tensorflow==2.12.0 From 97f30ed4cd6d13fae398c03f307d1d9d27188704 Mon Sep 17 00:00:00 2001 From: Ariel Jassan Date: Sun, 27 Oct 2024 11:30:52 +0200 Subject: [PATCH 3/7] Update requirements.txt --- people-and-planet-ai/land-cover-classification/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/people-and-planet-ai/land-cover-classification/requirements.txt b/people-and-planet-ai/land-cover-classification/requirements.txt index ef5cd594103..d5d4db530b7 100644 --- a/people-and-planet-ai/land-cover-classification/requirements.txt +++ b/people-and-planet-ai/land-cover-classification/requirements.txt @@ -5,7 +5,7 @@ folium==0.16.0 google-cloud-aiplatform==1.47.0 google-cloud-bigtable>=2.24.0 imageio==2.34.2 -numpy>=1.24.0 +numpy plotly==5.15.0 pyarrow>=10.0.1 tensorflow==2.12.0 From 386412b21007e7ab7c3b7b3ece0e58c1b665c311 Mon Sep 17 00:00:00 2001 From: Ariel Jassan Date: Sun, 27 Oct 2024 13:23:09 +0200 Subject: [PATCH 4/7] Update setup.py --- people-and-planet-ai/land-cover-classification/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/people-and-planet-ai/land-cover-classification/setup.py b/people-and-planet-ai/land-cover-classification/setup.py index 332fbc8be01..5f417484398 100644 --- a/people-and-planet-ai/land-cover-classification/setup.py +++ b/people-and-planet-ai/land-cover-classification/setup.py @@ -20,7 +20,7 @@ url="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/people-and-planet-ai/land-cover-classification", packages=["serving"], install_requires=[ - "apache-beam[gcp]==2.46.0", + "apache-beam[gcp]==2.60.0", "earthengine-api==0.1.395", "tensorflow==2.12.0", ], From 20d29f75f5c3ffa38a139ab7b464ddf71bb159b1 Mon Sep 17 00:00:00 2001 From: Ariel Jassan Date: Sun, 27 Oct 2024 14:43:59 +0200 Subject: [PATCH 5/7] Update setup.py --- people-and-planet-ai/land-cover-classification/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/people-and-planet-ai/land-cover-classification/setup.py b/people-and-planet-ai/land-cover-classification/setup.py index 5f417484398..17cf130f254 100644 --- a/people-and-planet-ai/land-cover-classification/setup.py +++ b/people-and-planet-ai/land-cover-classification/setup.py @@ -17,7 +17,7 @@ # Requirements for the Dataflow dataset creation pipeline. setup( name="ppai-landcover-classification", - url="https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/people-and-planet-ai/land-cover-classification", + url="https://github.com/arieljassan/python-docs-samples/tree/main/people-and-planet-ai/land-cover-classification", packages=["serving"], install_requires=[ "apache-beam[gcp]==2.60.0", From 97a8f62e47ef5a900b1dda3e69029649337c8890 Mon Sep 17 00:00:00 2001 From: Ariel Jassan Date: Tue, 29 Oct 2024 09:58:36 +0200 Subject: [PATCH 6/7] change get_label_function in data.py --- .../land-cover-classification/serving/data.py | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/people-and-planet-ai/land-cover-classification/serving/data.py b/people-and-planet-ai/land-cover-classification/serving/data.py index f9f969b30c7..848ca9182bf 100644 --- a/people-and-planet-ai/land-cover-classification/serving/data.py +++ b/people-and-planet-ai/land-cover-classification/serving/data.py @@ -86,28 +86,39 @@ def mask_sentinel2_clouds(image: ee.Image) -> ee.Image: ) -def get_label_image() -> ee.Image: - """Get the European Space Agency WorldCover image. +# def get_label_image() -> ee.Image: +# """Get the European Space Agency WorldCover image. + +# This remaps the ESA classifications with the Dynamic World classifications. +# Any missing value is filled with 0 (water). + +# For more information, see: +# https://developers.google.com/earth-engine/datasets/catalog/ESA_WorldCover_v100 +# https://developers.google.com/earth-engine/datasets/catalog/GOOGLE_DYNAMICWORLD_V1 + +# Returns: An Earth Engine image with land cover classification as indices. +# """ +# # Remap the ESA classifications into the Dynamic World classifications +# fromValues = [10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 100] +# toValues = [1, 5, 2, 4, 6, 7, 8, 0, 3, 3, 7] +# return ( +# ee.Image("ESA/WorldCover/v100/2020") +# .select("Map") +# .remap(fromValues, toValues) +# .rename("landcover") +# .unmask(0) +# .byte() # as unsinged 8-bit integer +# ) - This remaps the ESA classifications with the Dynamic World classifications. - Any missing value is filled with 0 (water). - For more information, see: - https://developers.google.com/earth-engine/datasets/catalog/ESA_WorldCover_v100 - https://developers.google.com/earth-engine/datasets/catalog/GOOGLE_DYNAMICWORLD_V1 +def get_label_image() -> ee.Image: + CORINE_DATASET = "COPERNICUS/CORINE/V20/100m/2012" + CORINE_BAND = "landcover" - Returns: An Earth Engine image with land cover classification as indices. - """ - # Remap the ESA classifications into the Dynamic World classifications - fromValues = [10, 20, 30, 40, 50, 60, 70, 80, 90, 95, 100] - toValues = [1, 5, 2, 4, 6, 7, 8, 0, 3, 3, 7] return ( - ee.Image("ESA/WorldCover/v100/2020") - .select("Map") - .remap(fromValues, toValues) - .rename("landcover") - .unmask(0) - .byte() # as unsinged 8-bit integer + ee.Image(CORINE_DATASET) + .select(CORINE_BAND) + .unmask(0) # fill missing values with 0 (water) ) From bb56fa72564d7f7cf7e753f8439d14dfa6f722ca Mon Sep 17 00:00:00 2001 From: Ariel Jassan Date: Tue, 29 Oct 2024 10:00:25 +0200 Subject: [PATCH 7/7] update corine polygon in create_dataset.py --- .../create_dataset.py | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/people-and-planet-ai/land-cover-classification/create_dataset.py b/people-and-planet-ai/land-cover-classification/create_dataset.py index 6753502afab..0512e827e33 100644 --- a/people-and-planet-ai/land-cover-classification/create_dataset.py +++ b/people-and-planet-ai/land-cover-classification/create_dataset.py @@ -41,23 +41,37 @@ MAX_REQUESTS = 20 # default EE request quota # Simplified polygons covering most land areas in the world. -WORLD_POLYGONS = [ - # Americas - [(-33.0, -7.0), (-55.0, 53.0), (-166.0, 65.0), (-68.0, -56.0)], - # Africa, Asia, Europe +# WORLD_POLYGONS = [ +# # Americas +# [(-33.0, -7.0), (-55.0, 53.0), (-166.0, 65.0), (-68.0, -56.0)], +# # Africa, Asia, Europe +# [ +# (74.0, 71.0), +# (166.0, 55.0), +# (115.0, -11.0), +# (74.0, -4.0), +# (20.0, -38.0), +# (-29.0, 25.0), +# ], +# # Australia +# [(170.0, -47.0), (179.0, -37.0), (167.0, -12.0), (128.0, 17.0), (106.0, -29.0)], +# ] + + +CORINE_POLYGON = [ [ - (74.0, 71.0), - (166.0, 55.0), - (115.0, -11.0), - (74.0, -4.0), - (20.0, -38.0), - (-29.0, 25.0), - ], - # Australia - [(170.0, -47.0), (179.0, -37.0), (167.0, -12.0), (128.0, 17.0), (106.0, -29.0)], + [28.57402322629263, 71.85229647647411], + [-15.019726773707367, 52.90128640168962], + [-12.031445523707367, 36.44647958542454], + [32.26542947629263, 32.387853901053894], + [47.55839822629263, 38.12462418980472], + [39.12089822629263, 44.95586330772117], + [28.39824197629263, 50.61706208383491], + [35.95683572629263, 62.66834647436181], + [28.57402322629263, 71.85229647647411] + ] ] - def sample_points( seed: int, polygons: list[list[tuple[float, float]]], @@ -150,7 +164,7 @@ def run_tensorflow( points_per_class: int = POINTS_PER_CLASS, patch_size: int = PATCH_SIZE, max_requests: int = MAX_REQUESTS, - polygons: list[list[tuple[float, float]]] = WORLD_POLYGONS, + polygons: list[list[tuple[float, float]]] = CORINE_POLYGON, beam_args: list[str] | None = None, ) -> None: """Runs an Apache Beam pipeline to create a dataset.