Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Updates to prepare dutchf3 #185

Merged
merged 7 commits into from
Feb 10, 2020
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
31 changes: 16 additions & 15 deletions scripts/prepare_dutchf3.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ def split_section_train_val(data_dir, per_val=0.2, log_config=None):
_write_split_files(splits_path, train_list, test_list, "section")


def split_patch_train_val(data_dir, stride, patch, per_val=0.2, log_config=None):
def split_patch_train_val(data_dir, stride, patch_size, per_val=0.2, log_config=None):
"""Generate train and validation files for Netherlands F3 dataset.

Args:
data_dir (str): data directory path
stride (int): stride to use when sectioning of the volume
patch (int): size of patch to extract
patch_size (int): size of patch to extract
per_val (float, optional): the fraction of the volume to use for validation.
Defaults to 0.2.
"""
Expand All @@ -119,8 +119,8 @@ def split_patch_train_val(data_dir, stride, patch, per_val=0.2, log_config=None)

# Generate patches from sections
# Process inlines
horz_locations = range(0, xline - stride, stride)
vert_locations = range(0, depth - stride, stride)
horz_locations = range(0, xline - patch_size + 1, stride)
vert_locations = range(0, depth - patch_size + 1, stride)
logger.debug("Generating Inline patches")
logger.debug(horz_locations)
logger.debug(vert_locations)
Expand All @@ -138,8 +138,8 @@ def _i_extract_patches(iline_range, horz_locations, vert_locations):
logger.debug(test_iline_range)

# Process crosslines
horz_locations = range(0, iline - stride, stride)
vert_locations = range(0, depth - stride, stride)
horz_locations = range(0, iline - patch_size + 1, stride)
vert_locations = range(0, depth - patch_size + 1, stride)
logger.debug("Generating Crossline patches")
logger.debug(horz_locations)
logger.debug(vert_locations)
Expand Down Expand Up @@ -176,14 +176,15 @@ def run_split_func(loader_type, *args, **kwargs):
split_func(*args, **kwargs)


def split_alaudah_et_al_19(data_dir, stride, fraction_validation=0.2, loader_type="patch", log_config=None):
def split_alaudah_et_al_19(data_dir, stride, patch_size, fraction_validation=0.2, loader_type="patch", log_config=None):
"""Generate train and validation files (with overlap) for Netherlands F3 dataset.
The original split method from https://github.com/olivesgatech/facies_classification_benchmark
DON'T USE, SEE NOTES BELOW

Args:
data_dir (str): data directory path
stride (int): stride to use when sectioning of the volume
patch_size (int): size of patch to extract
fraction_validation (float, optional): the fraction of the volume to use for validation.
Defaults to 0.2.
loader_type (str, optional): type of data loader, can be "patch" or "section".
Expand Down Expand Up @@ -222,8 +223,8 @@ def split_alaudah_et_al_19(data_dir, stride, fraction_validation=0.2, loader_typ
x_list = ["x_" + str(x) for x in range(xline)]
elif loader_type == "patch":
i_list = []
horz_locations = range(0, xline - stride, stride)
vert_locations = range(0, depth - stride, stride)
horz_locations = range(0, xline - patch_size + 1, stride)
vert_locations = range(0, depth - patch_size + 1, stride)
logger.debug("Generating Inline patches")
logger.debug(horz_locations)
logger.debug(vert_locations)
Expand All @@ -238,8 +239,8 @@ def split_alaudah_et_al_19(data_dir, stride, fraction_validation=0.2, loader_typ
i_list = list(itertools.chain(*i_list))

x_list = []
horz_locations = range(0, iline - stride, stride)
vert_locations = range(0, depth - stride, stride)
horz_locations = range(0, iline - patch_size + 1, stride)
vert_locations = range(0, depth - patch_size + 1, stride)
for j in range(xline):
# for every xline:
# images are references by top-left corner:
Expand Down Expand Up @@ -273,25 +274,25 @@ def section(self, data_dir, per_val=0.2, log_config="logging.conf"):
"""
return split_section_train_val(data_dir, per_val=per_val, log_config=log_config)

def patch(self, data_dir, stride, patch, per_val=0.2, log_config="logging.conf"):
def patch(self, data_dir, stride, patch_size, per_val=0.2, log_config="logging.conf"):
"""Generate patch based train and validation files for Netherlands F3 dataset.

Args:
data_dir (str): data directory path
stride (int): stride to use when sectioning of the volume
patch (int): size of patch to extract
patch_size (int): size of patch to extract
per_val (float, optional): the fraction of the volume to use for validation.
Defaults to 0.2.
log_config (str): path to log configurations
"""
return split_patch_train_val(data_dir, stride, patch, per_val=per_val, log_config=log_config)
return split_patch_train_val(data_dir, stride, patch_size, per_val=per_val, log_config=log_config)


if __name__ == "__main__":
"""Example:
python prepare_data.py split_train_val section --data-dir=/mnt/dutch
or
python prepare_data.py split_train_val patch --data-dir=/mnt/dutch --stride=50 --patch=100
python prepare_data.py split_train_val patch --data-dir=/mnt/dutch --stride=50 --patch_size=100

"""
fire.Fire(
Expand Down
2 changes: 1 addition & 1 deletion tests/cicd/src/scripts/get_data_for_builds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ DATA_F3="${DATA_F3}/data"
cd scripts
python prepare_penobscot.py split_inline --data-dir=${DATA_PENOBSCOT} --val-ratio=.1 --test-ratio=.2
python prepare_dutchf3.py split_train_val section --data-dir=${DATA_F3}
python prepare_dutchf3.py split_train_val patch --data-dir=${DATA_F3} --stride=50 --patch=100
python prepare_dutchf3.py split_train_val patch --data-dir=${DATA_F3} --stride=50 --patch_size=100