diff --git a/dataset/create_dataset.py b/dataset/create_dataset.py index 3007de5f..709bc998 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 = 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" @@ -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] 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 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