Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

517 add configurable parent directory for patches #556

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading