Skip to content

Commit

Permalink
Merge pull request #556 from valhassan/517-add-configurable-parent-di…
Browse files Browse the repository at this point in the history
…rectory-for-patches
  • Loading branch information
valhassan authored Mar 1, 2024
2 parents abcb9e9 + 507276e commit e8fe9f8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
10 changes: 5 additions & 5 deletions dataset/create_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions tests/data/tiles/tiles.csv
Original file line number Diff line number Diff line change
@@ -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
tiled_image_1.tif;tiled_label_1.tif
tiled_image_2.tif;tiled_label_2.tif
4 changes: 3 additions & 1 deletion tiling_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e8fe9f8

Please sign in to comment.