From 677b2177f0c7fe59d9fd6d63c73903c20c074dde Mon Sep 17 00:00:00 2001 From: valhassan Date: Thu, 29 Feb 2024 16:56:51 -0500 Subject: [PATCH 1/4] Refactor dataset line creation in Tiler class --- tiling_segmentation.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tiling_segmentation.py b/tiling_segmentation.py index ad573b65..248b17c5 100644 --- a/tiling_segmentation.py +++ b/tiling_segmentation.py @@ -554,8 +554,10 @@ def filter_and_burn_dataset( nodata_val=int(nodata), mask_val=255 ) + line_img_path = Path(*Path(img_patch).absolute().parts[-4:]) + line_out_gt_burned_path = Path(*Path(out_gt_burned_path).absolute().parts[-4:]) - dataset_line = f'{Path(img_patch).absolute()};{Path(out_gt_burned_path).absolute()};{round(annot_perc)}\n' + dataset_line = f'{line_img_path};{line_out_gt_burned_path};{round(annot_perc)}\n' return dataset, dataset_line else: return dataset, None From 0bb20bcdbfac41b933901298845c53dacc4951a9 Mon Sep 17 00:00:00 2001 From: valhassan Date: Thu, 29 Feb 2024 16:57:08 -0500 Subject: [PATCH 2/4] Refactor image and label paths in SegmentationDataset class --- dataset/create_dataset.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dataset/create_dataset.py b/dataset/create_dataset.py index 3007de5f..a7f33110 100644 --- a/dataset/create_dataset.py +++ b/dataset/create_dataset.py @@ -68,6 +68,7 @@ def __init__(self, self.debug = debug self.dontcare = dontcare self.list_path = dataset_list_path + self.parent_folder = dataset_list_path.parent if not Path(self.list_path).is_file(): logging.error(f"Couldn't locate dataset list file: {self.list_path}.\n" @@ -139,10 +140,10 @@ def _load_image(self, index: int): Returns: image array and metadata """ - image_path = self.assets[index]["image"] + image_path = self.parent_folder.joinpath(self.assets[index]["image"]) with rasterio.open(image_path, 'r') as image_handle: - image = reshape_as_image(image_handle.read()) - metadata = image_handle.meta + image = reshape_as_image(image_handle.read()) + metadata = image_handle.meta assert self.num_bands <= image.shape[-1] return image, metadata @@ -156,8 +157,7 @@ def _load_label(self, index: int): Returns: label array and metadata """ - label_path = self.assets[index]["label"] - + label_path = self.parent_folder.joinpath(self.assets[index]["label"]) with rasterio.open(label_path, 'r') as label_handle: label = reshape_as_image(label_handle.read()) label = label[..., 0] From ee90486f9d5e25f42866d6b28b862aa4ed65ef8f Mon Sep 17 00:00:00 2001 From: valhassan Date: Fri, 1 Mar 2024 08:17:57 -0500 Subject: [PATCH 3/4] Update file paths in tiles.csv --- tests/data/tiles/tiles.csv | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/data/tiles/tiles.csv b/tests/data/tiles/tiles.csv index 54cac1d5..a7724882 100644 --- a/tests/data/tiles/tiles.csv +++ b/tests/data/tiles/tiles.csv @@ -1,2 +1,2 @@ -tests/data/tiles/tiled_image_1.tif;tests/data/tiles/tiled_label_1.tif -tests/data/tiles/tiled_image_2.tif;tests/data/tiles/tiled_label_2.tif \ No newline at end of file +tiled_image_1.tif;tiled_label_1.tif +tiled_image_2.tif;tiled_label_2.tif \ No newline at end of file From 507276ea2d1ee54de20d5a4b8fc79a5730e0c418 Mon Sep 17 00:00:00 2001 From: valhassan Date: Fri, 1 Mar 2024 08:18:10 -0500 Subject: [PATCH 4/4] Fix parent folder path in create_dataset.py --- dataset/create_dataset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dataset/create_dataset.py b/dataset/create_dataset.py index a7f33110..709bc998 100644 --- a/dataset/create_dataset.py +++ b/dataset/create_dataset.py @@ -68,7 +68,7 @@ def __init__(self, self.debug = debug self.dontcare = dontcare self.list_path = dataset_list_path - self.parent_folder = dataset_list_path.parent + self.parent_folder = Path(self.list_path).parent if not Path(self.list_path).is_file(): logging.error(f"Couldn't locate dataset list file: {self.list_path}.\n"