From fab234ce7d39a9e01bd7a6f2922f94ed631feb0e Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Thu, 4 Jun 2020 15:05:14 +0000 Subject: [PATCH 01/19] intermediate work for normalization --- cv_lib/cv_lib/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cv_lib/cv_lib/utils.py b/cv_lib/cv_lib/utils.py index 0c0cef82..c3a912b9 100644 --- a/cv_lib/cv_lib/utils.py +++ b/cv_lib/cv_lib/utils.py @@ -8,7 +8,7 @@ from matplotlib import pyplot as plt -def normalize(array): +def normalize(array, MIN, MAX): """ Normalizes a segmentation mask array to be in [0,1] range for use with PIL.Image @@ -30,12 +30,12 @@ def mask_to_disk(mask, fname, n_classes, cmap_name="rainbow"): Image.fromarray(cmap(mask / n_classes, bytes=True)).save(fname) -def image_to_disk(mask, fname, cmap_name="seismic"): +def image_to_disk(image, fname, cmap_name="seismic"): """ write segmentation image to disk using a particular colormap """ cmap = plt.get_cmap(cmap_name) - Image.fromarray(cmap(normalize(mask), bytes=True)).save(fname) + Image.fromarray(cmap(normalize(image), bytes=True)).save(fname) def decode_segmap(label_mask, colormap_name="rainbow"): From cd575ff66dde8681bd5149848f81626606e88886 Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Thu, 4 Jun 2020 18:52:32 +0000 Subject: [PATCH 02/19] 1) normalize function runs based on global MIN and MAX 2) has a error handling for division by zero, np.finfo 3) decode_segmap normalizes the label/mask based on the n_calsses --- .../event_handlers/tensorboard_handlers.py | 8 ++++---- cv_lib/cv_lib/utils.py | 19 ++++++++++-------- .../dutchf3/data.py | 20 +++++++++---------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/cv_lib/cv_lib/event_handlers/tensorboard_handlers.py b/cv_lib/cv_lib/event_handlers/tensorboard_handlers.py index d3df7f31..76247e71 100644 --- a/cv_lib/cv_lib/event_handlers/tensorboard_handlers.py +++ b/cv_lib/cv_lib/event_handlers/tensorboard_handlers.py @@ -20,9 +20,9 @@ def _transform_image(output_tensor): return torchvision.utils.make_grid(output_tensor, normalize=True, scale_each=True) -def _transform_pred(output_tensor): +def _transform_pred(output_tensor, n_classes): output_tensor = output_tensor.squeeze().cpu().numpy() - decoded = decode_segmap(output_tensor) + decoded = decode_segmap(output_tensor, n_classes) return torchvision.utils.make_grid(np_to_tb(decoded), normalize=False, scale_each=False) @@ -111,5 +111,5 @@ def log_results(engine, evaluator, summary_writer, n_classes, stage): y_pred[mask == 255] = 255 summary_writer.add_image(f"{stage}/Image", _transform_image(image), epoch) - summary_writer.add_image(f"{stage}/Mask", _transform_pred(mask), epoch) - summary_writer.add_image(f"{stage}/Pred", _transform_pred(y_pred), epoch) + summary_writer.add_image(f"{stage}/Mask", _transform_pred(mask, n_classes), epoch) + summary_writer.add_image(f"{stage}/Pred", _transform_pred(y_pred, n_classes), epoch) diff --git a/cv_lib/cv_lib/utils.py b/cv_lib/cv_lib/utils.py index c3a912b9..a6b3d6cb 100644 --- a/cv_lib/cv_lib/utils.py +++ b/cv_lib/cv_lib/utils.py @@ -10,11 +10,14 @@ def normalize(array, MIN, MAX): """ - Normalizes a segmentation mask array to be in [0,1] range - for use with PIL.Image + Normalizes a segmentation image array by the global range of the data, + MIN and MAX, for use with PIL.Image """ - min = array.min() - return (array - min) / (array.max() - min) + + den = MAX - MIN + if den==0: + den += np.finfo(float).eps + return (array - MIN) / den def mask_to_disk(mask, fname, n_classes, cmap_name="rainbow"): @@ -30,15 +33,15 @@ def mask_to_disk(mask, fname, n_classes, cmap_name="rainbow"): Image.fromarray(cmap(mask / n_classes, bytes=True)).save(fname) -def image_to_disk(image, fname, cmap_name="seismic"): +def image_to_disk(image, fname, MIN, MAX, cmap_name="seismic"): """ write segmentation image to disk using a particular colormap """ cmap = plt.get_cmap(cmap_name) - Image.fromarray(cmap(normalize(image), bytes=True)).save(fname) + Image.fromarray(cmap(normalize(image, MIN, MAX), bytes=True)).save(fname) -def decode_segmap(label_mask, colormap_name="rainbow"): +def decode_segmap(label_mask, n_classes, colormap_name="rainbow"): """ Decode segmentation class labels into a colour image Args: @@ -51,7 +54,7 @@ def decode_segmap(label_mask, colormap_name="rainbow"): cmap = plt.get_cmap(colormap_name) # loop over the batch for i in range(label_mask.shape[0]): - im = Image.fromarray(cmap(normalize(label_mask[i, :, :]), bytes=True)).convert("RGB") + im = Image.fromarray(cmap((label_mask[i, :, :] / n_classes), bytes=True)).convert("RGB") out[i, :, :, :] = np.array(im).swapaxes(0, 2).swapaxes(1, 2) return out diff --git a/interpretation/deepseismic_interpretation/dutchf3/data.py b/interpretation/deepseismic_interpretation/dutchf3/data.py index 2767f005..77e65597 100644 --- a/interpretation/deepseismic_interpretation/dutchf3/data.py +++ b/interpretation/deepseismic_interpretation/dutchf3/data.py @@ -155,7 +155,7 @@ def __getitem__(self, index): outdir = f"debug/sectionLoader_{self.split}_raw" generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{section_name}" - image_to_disk(im, path_prefix + "_img.png") + image_to_disk(im, path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.augmentations is not None: @@ -169,7 +169,7 @@ def __getitem__(self, index): outdir = f"debug/sectionLoader_{self.split}_{'aug' if self.augmentations is not None else 'noaug'}" generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{section_name}" - image_to_disk(np.array(im[0]), path_prefix + "_img.png") + image_to_disk(np.array(im[0]), path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) mask_to_disk(np.array(lbl[0]), path_prefix + "_lbl.png", self.n_classes) return im, lbl @@ -411,7 +411,7 @@ def __getitem__(self, index): generate_path(outdir) # this needs to take the first dimension of image (no depth) but lbl only has 1 dim path_prefix = f"{outdir}/index_{index}_section_{section_name}" - image_to_disk(im[0, :, :], path_prefix + "_img.png") + image_to_disk(im[0, :, :], path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.augmentations is not None: @@ -430,7 +430,7 @@ def __getitem__(self, index): ) generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{section_name}" - image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png") + image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) mask_to_disk(np.array(lbl[0, :, :]), path_prefix + "_lbl.png", self.n_classes) return im, lbl @@ -500,7 +500,7 @@ def __getitem__(self, index): outdir = f"debug/patchLoader_{self.split}_raw" generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{patch_name}" - image_to_disk(im, path_prefix + "_img.png") + image_to_disk(im, path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.augmentations is not None: @@ -512,7 +512,7 @@ def __getitem__(self, index): outdir = f"patchLoader_{self.split}_{'aug' if self.augmentations is not None else 'noaug'}" generate_path(outdir) path_prefix = f"{outdir}/{index}" - image_to_disk(im, path_prefix + "_img.png") + image_to_disk(im, path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.is_transform: @@ -523,7 +523,7 @@ def __getitem__(self, index): outdir = f"debug/patchLoader_{self.split}_{'aug' if self.augmentations is not None else 'noaug'}" generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{patch_name}" - image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png") + image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) mask_to_disk(np.array(lbl[0, :, :]), path_prefix + "_lbl.png", self.n_classes) return im, lbl @@ -769,7 +769,7 @@ def __getitem__(self, index): outdir = f"debug/patchLoaderWithSectionDepth_{self.split}_raw" generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{patch_name}" - image_to_disk(im[0, :, :], path_prefix + "_img.png") + image_to_disk(im[0, :, :], path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.augmentations is not None: @@ -783,7 +783,7 @@ def __getitem__(self, index): outdir = f"patchLoaderWithSectionDepth_{self.split}_{'aug' if self.augmentations is not None else 'noaug'}" generate_path(outdir) path_prefix = f"{outdir}/{index}" - image_to_disk(im[0, :, :], path_prefix + "_img.png") + image_to_disk(im[0, :, :], path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.is_transform: @@ -796,7 +796,7 @@ def __getitem__(self, index): ) generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{patch_name}" - image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png") + image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) mask_to_disk(np.array(lbl[0, :, :]), path_prefix + "_lbl.png", self.n_classes) return im, lbl From 6b1ebdfbf3a55ea5b73d62efabbdd76f317fdb6f Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Fri, 5 Jun 2020 19:45:14 +0000 Subject: [PATCH 03/19] global normalization added to test.py --- experiments/interpretation/dutchf3_patch/local/test.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/experiments/interpretation/dutchf3_patch/local/test.py b/experiments/interpretation/dutchf3_patch/local/test.py index 09d5ebf3..8aa40039 100644 --- a/experiments/interpretation/dutchf3_patch/local/test.py +++ b/experiments/interpretation/dutchf3_patch/local/test.py @@ -205,6 +205,8 @@ def _patch_label_2d( ): """Processes a whole section """ + + img = torch.squeeze(img) h, w = img.shape[-2], img.shape[-1] # height and width @@ -234,14 +236,14 @@ def _patch_label_2d( path_prefix = f"{outdir}/{batch_indexes[i][0]}_{batch_indexes[i][1]}" model_output = model_output.detach().cpu() # save image: - image_to_disk(np.array(batch[i, 0, :, :]), path_prefix + "_img.png") + image_to_disk(np.array(batch[i, 0, :, :]), path_prefix + "_img.png", float(img.min()), float(img.max())) # dump model prediction: mask_to_disk(model_output[i, :, :, :].argmax(dim=1).numpy(), path_prefix + "_pred.png", num_classes) # dump model confidence values for nclass in range(num_classes): image_to_disk( model_output[i, nclass, :, :].numpy(), path_prefix + f"_class_{nclass}_conf.png", - ) + model_output[i, nclass, :, :].numpy().min(), model_output[i, nclass, :, :].numpy().max()) # crop the output_p in the middle output = output_p[:, :, ps:-ps, ps:-ps] @@ -288,7 +290,6 @@ def _evaluate_split( for i, (images, labels) in enumerate(test_loader): logger.info(f"split: {split}, section: {i}") total_iteration = total_iteration + 1 - outputs = _patch_label_2d( model, images, From 684e225ac1c08405e955b97756f870f49ba51b48 Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Fri, 5 Jun 2020 21:03:56 +0000 Subject: [PATCH 04/19] increasing the threshold on timeout --- tests/cicd/main_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cicd/main_build.yml b/tests/cicd/main_build.yml index ebec7963..10f57466 100644 --- a/tests/cicd/main_build.yml +++ b/tests/cicd/main_build.yml @@ -96,7 +96,7 @@ jobs: - job: checkerboard_dutchf3_patch dependsOn: cv_lib_unit_tests_job - timeoutInMinutes: 30 + timeoutInMinutes: 45 displayName: Checkerboard Dutch F3 patch local pool: name: deepseismicagentpool From f699e996b14bbf9e3cd321e0b9af8f454bd305bd Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Fri, 5 Jun 2020 21:59:25 +0000 Subject: [PATCH 05/19] trigger --- tests/cicd/main_build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/cicd/main_build.yml b/tests/cicd/main_build.yml index 10f57466..9473e2ed 100644 --- a/tests/cicd/main_build.yml +++ b/tests/cicd/main_build.yml @@ -30,7 +30,7 @@ jobs: ################################################################################################### - job: setup - timeoutInMinutes: 10 + timeoutInMinutes: 15 displayName: Setup pool: name: deepseismicagentpool @@ -113,6 +113,7 @@ jobs: # Create a temporary directory to store the statuses dir=$(mktemp -d) + MEAN: 0.0009997 # 0.0009996710808862074 # we are running a single batch in debug mode through, so increase the # number of epochs to obtain a representative set of results From 0a050b1f44b2c010c48c537cef19a9143a848949 Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Fri, 5 Jun 2020 22:06:14 +0000 Subject: [PATCH 06/19] revert --- tests/cicd/main_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cicd/main_build.yml b/tests/cicd/main_build.yml index 9473e2ed..a9f4b846 100644 --- a/tests/cicd/main_build.yml +++ b/tests/cicd/main_build.yml @@ -30,7 +30,7 @@ jobs: ################################################################################################### - job: setup - timeoutInMinutes: 15 + timeoutInMinutes: 10 displayName: Setup pool: name: deepseismicagentpool From 18d66cb59e0b00957dc5295ef650339eaeabd1c9 Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Fri, 5 Jun 2020 22:08:43 +0000 Subject: [PATCH 07/19] idk what happened --- tests/cicd/main_build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/cicd/main_build.yml b/tests/cicd/main_build.yml index a9f4b846..10f57466 100644 --- a/tests/cicd/main_build.yml +++ b/tests/cicd/main_build.yml @@ -113,7 +113,6 @@ jobs: # Create a temporary directory to store the statuses dir=$(mktemp -d) - MEAN: 0.0009997 # 0.0009996710808862074 # we are running a single batch in debug mode through, so increase the # number of epochs to obtain a representative set of results From 627afe86ea845c895cab7bb89a217f14bbe8c386 Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Mon, 8 Jun 2020 15:40:30 +0000 Subject: [PATCH 08/19] increase timeout --- tests/cicd/main_build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cicd/main_build.yml b/tests/cicd/main_build.yml index 41ea7d85..e930e88e 100644 --- a/tests/cicd/main_build.yml +++ b/tests/cicd/main_build.yml @@ -96,7 +96,7 @@ jobs: - job: checkerboard_dutchf3_patch dependsOn: cv_lib_unit_tests_job - timeoutInMinutes: 45 + timeoutInMinutes: 60 displayName: Checkerboard Dutch F3 patch local pool: name: deepseismicagentpool From b015317720838392054a5db2e57fe2bc5edb54c3 Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Tue, 9 Jun 2020 13:14:57 +0000 Subject: [PATCH 09/19] picking up global min and max --- .../dutchf3/data.py | 20 +++++++++---------- scripts/dev_build.py | 10 +++++++++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/interpretation/deepseismic_interpretation/dutchf3/data.py b/interpretation/deepseismic_interpretation/dutchf3/data.py index 77e65597..f8566afa 100644 --- a/interpretation/deepseismic_interpretation/dutchf3/data.py +++ b/interpretation/deepseismic_interpretation/dutchf3/data.py @@ -155,7 +155,7 @@ def __getitem__(self, index): outdir = f"debug/sectionLoader_{self.split}_raw" generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{section_name}" - image_to_disk(im, path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) + image_to_disk(im, path_prefix + "_img.png", -1, 1) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.augmentations is not None: @@ -169,7 +169,7 @@ def __getitem__(self, index): outdir = f"debug/sectionLoader_{self.split}_{'aug' if self.augmentations is not None else 'noaug'}" generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{section_name}" - image_to_disk(np.array(im[0]), path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) + image_to_disk(np.array(im[0]), path_prefix + "_img.png", -1, 1) mask_to_disk(np.array(lbl[0]), path_prefix + "_lbl.png", self.n_classes) return im, lbl @@ -411,7 +411,7 @@ def __getitem__(self, index): generate_path(outdir) # this needs to take the first dimension of image (no depth) but lbl only has 1 dim path_prefix = f"{outdir}/index_{index}_section_{section_name}" - image_to_disk(im[0, :, :], path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) + image_to_disk(im[0, :, :], path_prefix + "_img.png", -1, 1) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.augmentations is not None: @@ -430,7 +430,7 @@ def __getitem__(self, index): ) generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{section_name}" - image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) + image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", -1, 1) mask_to_disk(np.array(lbl[0, :, :]), path_prefix + "_lbl.png", self.n_classes) return im, lbl @@ -500,7 +500,7 @@ def __getitem__(self, index): outdir = f"debug/patchLoader_{self.split}_raw" generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{patch_name}" - image_to_disk(im, path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) + image_to_disk(im, path_prefix + "_img.png", -1, 1) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.augmentations is not None: @@ -512,7 +512,7 @@ def __getitem__(self, index): outdir = f"patchLoader_{self.split}_{'aug' if self.augmentations is not None else 'noaug'}" generate_path(outdir) path_prefix = f"{outdir}/{index}" - image_to_disk(im, path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) + image_to_disk(im, path_prefix + "_img.png", -1, 1) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.is_transform: @@ -523,7 +523,7 @@ def __getitem__(self, index): outdir = f"debug/patchLoader_{self.split}_{'aug' if self.augmentations is not None else 'noaug'}" generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{patch_name}" - image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) + image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", -1, 1) mask_to_disk(np.array(lbl[0, :, :]), path_prefix + "_lbl.png", self.n_classes) return im, lbl @@ -769,7 +769,7 @@ def __getitem__(self, index): outdir = f"debug/patchLoaderWithSectionDepth_{self.split}_raw" generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{patch_name}" - image_to_disk(im[0, :, :], path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) + image_to_disk(im[0, :, :], path_prefix + "_img.png", -1, 1) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.augmentations is not None: @@ -783,7 +783,7 @@ def __getitem__(self, index): outdir = f"patchLoaderWithSectionDepth_{self.split}_{'aug' if self.augmentations is not None else 'noaug'}" generate_path(outdir) path_prefix = f"{outdir}/{index}" - image_to_disk(im[0, :, :], path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) + image_to_disk(im[0, :, :], path_prefix + "_img.png", -1, 1) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.is_transform: @@ -796,7 +796,7 @@ def __getitem__(self, index): ) generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{patch_name}" - image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", self.seismic.min(), self.seismic.max()) + image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", -1, 1) mask_to_disk(np.array(lbl[0, :, :]), path_prefix + "_lbl.png", self.n_classes) return im, lbl diff --git a/scripts/dev_build.py b/scripts/dev_build.py index c490705c..93a34105 100644 --- a/scripts/dev_build.py +++ b/scripts/dev_build.py @@ -32,6 +32,10 @@ def main(args): add --setup to run it (destroys existing environment and creates a new one, along with all the data) """ + from datetime import datetime + + beg = datetime.now() + logging.info("loading data") @@ -91,9 +95,13 @@ def main(args): logging.info(f"Have {len(completed.stdout)} output bytes: \n{completed.stdout.decode('utf-8')}") logging.info(f"Everything ran! You can try running the same jobs {job_names} on the build VM now") + end = datetime.now() + + print(end, beg) + print((end-beg).total_seconds()) """ GLOBAL VARIABLES """ -PATH_PREFIX = "/data/anaconda/envs/seismic-interpretation/bin:/data/anaconda/bin" +PATH_PREFIX = "/anaconda/envs/seismic-interpretation/bin:/anaconda/bin" parser.add_argument( "--file", help="Which yaml file you'd like to read which specifies build info", type=str, required=True From 39a861a670dc82a2907644b47e8dc6d4c0ffedf0 Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Tue, 9 Jun 2020 15:15:28 +0000 Subject: [PATCH 10/19] passing config to TrainPatchLoader to facilitate access to global min and max and other attr in low level functions, WIP --- cv_lib/cv_lib/utils.py | 1 + .../dutchf3_patch/local/default.py | 2 ++ .../dutchf3_patch/local/train.py | 15 ++++---- .../dutchf3/data.py | 34 +++++++++---------- scripts/dev_build.py | 5 ++- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/cv_lib/cv_lib/utils.py b/cv_lib/cv_lib/utils.py index a6b3d6cb..e88413ba 100644 --- a/cv_lib/cv_lib/utils.py +++ b/cv_lib/cv_lib/utils.py @@ -17,6 +17,7 @@ def normalize(array, MIN, MAX): den = MAX - MIN if den==0: den += np.finfo(float).eps + return (array - MIN) / den diff --git a/experiments/interpretation/dutchf3_patch/local/default.py b/experiments/interpretation/dutchf3_patch/local/default.py index 0322d5b1..a5fe7c9c 100644 --- a/experiments/interpretation/dutchf3_patch/local/default.py +++ b/experiments/interpretation/dutchf3_patch/local/default.py @@ -37,6 +37,8 @@ _C.DATASET.ROOT = "" _C.DATASET.NUM_CLASSES = 6 _C.DATASET.CLASS_WEIGHTS = [0.7151, 0.8811, 0.5156, 0.9346, 0.9683, 0.9852] +_C.DATASET.MIN = 0 +_C.DATASET.MAX = 7 # common params for NETWORK _C.MODEL = CN() diff --git a/experiments/interpretation/dutchf3_patch/local/train.py b/experiments/interpretation/dutchf3_patch/local/train.py index 397a7e16..20e88283 100644 --- a/experiments/interpretation/dutchf3_patch/local/train.py +++ b/experiments/interpretation/dutchf3_patch/local/train.py @@ -125,25 +125,24 @@ def run(*options, cfg=None, debug=False): # Training and Validation Loaders: TrainPatchLoader = get_patch_loader(config) logging.info(f"Using {TrainPatchLoader}") + sog = (config.DATASET.NUM_CLASSES, config.DATASET.MIN, config.DATASET.MAX) + print(sog) + train_set = TrainPatchLoader( - config.DATASET.ROOT, - config.DATASET.NUM_CLASSES, + config, split="train", is_transform=True, - stride=config.TRAIN.STRIDE, - patch_size=config.TRAIN.PATCH_SIZE, augmentations=train_aug, debug=debug, ) logger.info(train_set) + + n_classes = train_set.n_classes val_set = TrainPatchLoader( - config.DATASET.ROOT, - config.DATASET.NUM_CLASSES, + config, split="val", is_transform=True, - stride=config.TRAIN.STRIDE, - patch_size=config.TRAIN.PATCH_SIZE, augmentations=val_aug, debug=debug, ) diff --git a/interpretation/deepseismic_interpretation/dutchf3/data.py b/interpretation/deepseismic_interpretation/dutchf3/data.py index f8566afa..788f1008 100644 --- a/interpretation/deepseismic_interpretation/dutchf3/data.py +++ b/interpretation/deepseismic_interpretation/dutchf3/data.py @@ -455,15 +455,17 @@ class PatchLoader(data.Dataset): """ def __init__( - self, data_dir, n_classes, stride=30, patch_size=99, is_transform=True, augmentations=None, debug=False, - ): - self.data_dir = data_dir + self, config, is_transform=True, augmentations=None, debug=False, + ): #stride=30, patch_size=99, + self.data_dir = config.DATASET.ROOT + self.n_classes = config.DATASET.NUM_CLASSES + self.MIN = config.DATASET.MIN + self.MAX = config.DATASET.MAX + self.patch_size = config.TRAIN.PATCH_SIZE + self.stride = config.TRAIN.STRIDE self.is_transform = is_transform self.augmentations = augmentations - self.n_classes = n_classes self.patches = list() - self.patch_size = patch_size - self.stride = stride self.debug = debug def pad_volume(self, volume): @@ -500,7 +502,7 @@ def __getitem__(self, index): outdir = f"debug/patchLoader_{self.split}_raw" generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{patch_name}" - image_to_disk(im, path_prefix + "_img.png", -1, 1) + image_to_disk(im, path_prefix + "_img.png", self.MIN, self.MAX) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.augmentations is not None: @@ -512,7 +514,7 @@ def __getitem__(self, index): outdir = f"patchLoader_{self.split}_{'aug' if self.augmentations is not None else 'noaug'}" generate_path(outdir) path_prefix = f"{outdir}/{index}" - image_to_disk(im, path_prefix + "_img.png", -1, 1) + image_to_disk(im, path_prefix + "_img.png", self.MIN, self.MAX) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.is_transform: @@ -523,7 +525,7 @@ def __getitem__(self, index): outdir = f"debug/patchLoader_{self.split}_{'aug' if self.augmentations is not None else 'noaug'}" generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{patch_name}" - image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", -1, 1) + image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", self.MIN, self.MAX) mask_to_disk(np.array(lbl[0, :, :]), path_prefix + "_lbl.png", self.n_classes) return im, lbl @@ -584,11 +586,10 @@ class TrainPatchLoader(PatchLoader): def __init__( self, - data_dir, - n_classes, + config, split="train", - stride=30, - patch_size=99, + # stride=30, + # patch_size=99, is_transform=True, augmentations=None, seismic_path=None, @@ -596,10 +597,9 @@ def __init__( debug=False, ): super(TrainPatchLoader, self).__init__( - data_dir, - n_classes, - stride=stride, - patch_size=patch_size, + config, + # stride=stride, + # patch_size=patch_size, is_transform=is_transform, augmentations=augmentations, debug=debug, diff --git a/scripts/dev_build.py b/scripts/dev_build.py index 93a34105..7d74ea32 100644 --- a/scripts/dev_build.py +++ b/scripts/dev_build.py @@ -35,7 +35,6 @@ def main(args): from datetime import datetime beg = datetime.now() - logging.info("loading data") @@ -95,10 +94,10 @@ def main(args): logging.info(f"Have {len(completed.stdout)} output bytes: \n{completed.stdout.decode('utf-8')}") logging.info(f"Everything ran! You can try running the same jobs {job_names} on the build VM now") + end = datetime.now() - print(end, beg) - print((end-beg).total_seconds()) + print('time elapsed in seconds', (end-beg).total_seconds()) """ GLOBAL VARIABLES """ PATH_PREFIX = "/anaconda/envs/seismic-interpretation/bin:/anaconda/bin" From ea9f319533bad2b6f432190cad3c4b8f365f267f Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Tue, 9 Jun 2020 15:21:27 +0000 Subject: [PATCH 11/19] removed print statement --- experiments/interpretation/dutchf3_patch/local/train.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/experiments/interpretation/dutchf3_patch/local/train.py b/experiments/interpretation/dutchf3_patch/local/train.py index 20e88283..7b645695 100644 --- a/experiments/interpretation/dutchf3_patch/local/train.py +++ b/experiments/interpretation/dutchf3_patch/local/train.py @@ -125,8 +125,6 @@ def run(*options, cfg=None, debug=False): # Training and Validation Loaders: TrainPatchLoader = get_patch_loader(config) logging.info(f"Using {TrainPatchLoader}") - sog = (config.DATASET.NUM_CLASSES, config.DATASET.MIN, config.DATASET.MAX) - print(sog) train_set = TrainPatchLoader( config, From 7818b733acf8d800a38f35223da0c386882ca6aa Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Tue, 9 Jun 2020 16:00:04 +0000 Subject: [PATCH 12/19] changed section loaders --- .../dutchf3/data.py | 45 +++++++++---------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/interpretation/deepseismic_interpretation/dutchf3/data.py b/interpretation/deepseismic_interpretation/dutchf3/data.py index 788f1008..5d93431a 100644 --- a/interpretation/deepseismic_interpretation/dutchf3/data.py +++ b/interpretation/deepseismic_interpretation/dutchf3/data.py @@ -125,12 +125,14 @@ class SectionLoader(data.Dataset): :param bool debug: enable debugging output """ - def __init__(self, data_dir, n_classes, split="train", is_transform=True, augmentations=None, debug=False): + def __init__(self, config, split="train", is_transform=True, augmentations=None, debug=False): + self.data_dir = config.DATASET.ROOT + self.n_classes = config.DATASET.NUM_CLASSES + self.MIN = config.DATASET.MIN + self.MAX = config.DATASET.MAX self.split = split - self.data_dir = data_dir self.is_transform = is_transform self.augmentations = augmentations - self.n_classes = n_classes self.sections = list() self.debug = debug @@ -155,7 +157,7 @@ def __getitem__(self, index): outdir = f"debug/sectionLoader_{self.split}_raw" generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{section_name}" - image_to_disk(im, path_prefix + "_img.png", -1, 1) + image_to_disk(im, path_prefix + "_img.png", self.MIN, self.MAX) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.augmentations is not None: @@ -169,7 +171,7 @@ def __getitem__(self, index): outdir = f"debug/sectionLoader_{self.split}_{'aug' if self.augmentations is not None else 'noaug'}" generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{section_name}" - image_to_disk(np.array(im[0]), path_prefix + "_img.png", -1, 1) + image_to_disk(np.array(im[0]), path_prefix + "_img.png", self.MIN, self.MAX) mask_to_disk(np.array(lbl[0]), path_prefix + "_lbl.png", self.n_classes) return im, lbl @@ -197,8 +199,7 @@ class TrainSectionLoader(SectionLoader): def __init__( self, - data_dir, - n_classes, + config, split="train", is_transform=True, augmentations=None, @@ -207,8 +208,7 @@ def __init__( debug=False, ): super(TrainSectionLoader, self).__init__( - data_dir, - n_classes, + config, split=split, is_transform=is_transform, augmentations=augmentations, @@ -252,8 +252,7 @@ class TrainSectionLoaderWithDepth(TrainSectionLoader): def __init__( self, - data_dir, - n_classes, + config, split="train", is_transform=True, augmentations=None, @@ -262,8 +261,7 @@ def __init__( debug=False, ): super(TrainSectionLoaderWithDepth, self).__init__( - data_dir, - n_classes, + config, split=split, is_transform=is_transform, augmentations=augmentations, @@ -316,8 +314,7 @@ class TestSectionLoader(SectionLoader): def __init__( self, - data_dir, - n_classes, + config, split="test1", is_transform=True, augmentations=None, @@ -326,7 +323,7 @@ def __init__( debug=False, ): super(TestSectionLoader, self).__init__( - data_dir, n_classes, split=split, is_transform=is_transform, augmentations=augmentations, debug=debug, + config, split=split, is_transform=is_transform, augmentations=augmentations, debug=debug, ) if "test1" in self.split: @@ -368,8 +365,7 @@ class TestSectionLoaderWithDepth(TestSectionLoader): def __init__( self, - data_dir, - n_classes, + config, split="test1", is_transform=True, augmentations=None, @@ -378,8 +374,7 @@ def __init__( debug=False, ): super(TestSectionLoaderWithDepth, self).__init__( - data_dir, - n_classes, + config, split=split, is_transform=is_transform, augmentations=augmentations, @@ -411,7 +406,7 @@ def __getitem__(self, index): generate_path(outdir) # this needs to take the first dimension of image (no depth) but lbl only has 1 dim path_prefix = f"{outdir}/index_{index}_section_{section_name}" - image_to_disk(im[0, :, :], path_prefix + "_img.png", -1, 1) + image_to_disk(im[0, :, :], path_prefix + "_img.png", self.MIN, self.MAX) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.augmentations is not None: @@ -430,7 +425,7 @@ def __getitem__(self, index): ) generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{section_name}" - image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", -1, 1) + image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", self.MIN, self.MAX mask_to_disk(np.array(lbl[0, :, :]), path_prefix + "_lbl.png", self.n_classes) return im, lbl @@ -769,7 +764,7 @@ def __getitem__(self, index): outdir = f"debug/patchLoaderWithSectionDepth_{self.split}_raw" generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{patch_name}" - image_to_disk(im[0, :, :], path_prefix + "_img.png", -1, 1) + image_to_disk(im[0, :, :], path_prefix + "_img.png") mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.augmentations is not None: @@ -783,7 +778,7 @@ def __getitem__(self, index): outdir = f"patchLoaderWithSectionDepth_{self.split}_{'aug' if self.augmentations is not None else 'noaug'}" generate_path(outdir) path_prefix = f"{outdir}/{index}" - image_to_disk(im[0, :, :], path_prefix + "_img.png", -1, 1) + image_to_disk(im[0, :, :], path_prefix + "_img.png") mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.is_transform: @@ -796,7 +791,7 @@ def __getitem__(self, index): ) generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{patch_name}" - image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", -1, 1) + image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png") mask_to_disk(np.array(lbl[0, :, :]), path_prefix + "_lbl.png", self.n_classes) return im, lbl From 18f4e02abb876e59a21ba171220cb6e521131239 Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Tue, 9 Jun 2020 16:58:42 +0000 Subject: [PATCH 13/19] updated test for min and max from config too --- .../dutchf3_patch/local/test.py | 12 +++---- .../dutchf3/data.py | 35 ++++++------------- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/experiments/interpretation/dutchf3_patch/local/test.py b/experiments/interpretation/dutchf3_patch/local/test.py index 0f996d5f..e79ff15f 100644 --- a/experiments/interpretation/dutchf3_patch/local/test.py +++ b/experiments/interpretation/dutchf3_patch/local/test.py @@ -201,7 +201,7 @@ def _output_processing_pipeline(config, output): def _patch_label_2d( - model, img, pre_processing, output_processing, patch_size, stride, batch_size, device, num_classes, split, debug + model, img, pre_processing, output_processing, patch_size, stride, batch_size, device, num_classes, split, debug, MIN, MAX ): """Processes a whole section """ @@ -236,14 +236,14 @@ def _patch_label_2d( path_prefix = f"{outdir}/{batch_indexes[i][0]}_{batch_indexes[i][1]}" model_output = model_output.detach().cpu() # save image: - image_to_disk(np.array(batch[i, 0, :, :]), path_prefix + "_img.png", float(img.min()), float(img.max())) + image_to_disk(np.array(batch[i, 0, :, :]), path_prefix + "_img.png", MIN, MAX) # dump model prediction: mask_to_disk(model_output[i, :, :, :].argmax(dim=0).numpy(), path_prefix + "_pred.png", num_classes) # dump model confidence values for nclass in range(num_classes): image_to_disk( model_output[i, nclass, :, :].numpy(), path_prefix + f"_class_{nclass}_conf.png", - model_output[i, nclass, :, :].numpy().min(), model_output[i, nclass, :, :].numpy().max()) + MIN, MAX) # crop the output_p in the middle output = output_p[:, :, ps:-ps, ps:-ps] @@ -258,8 +258,7 @@ def _evaluate_split( TestSectionLoader = get_test_loader(config) test_set = TestSectionLoader( - config.DATASET.ROOT, - config.DATASET.NUM_CLASSES, + config, split=split, is_transform=True, augmentations=section_aug, @@ -302,7 +301,8 @@ def _evaluate_split( n_classes, split, debug, - ) + config.DATASET.MIN, + config.DATASET.MAX) pred = outputs.detach().max(1)[1].numpy() gt = labels.numpy() diff --git a/interpretation/deepseismic_interpretation/dutchf3/data.py b/interpretation/deepseismic_interpretation/dutchf3/data.py index 5d93431a..da1e86c2 100644 --- a/interpretation/deepseismic_interpretation/dutchf3/data.py +++ b/interpretation/deepseismic_interpretation/dutchf3/data.py @@ -425,7 +425,7 @@ def __getitem__(self, index): ) generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{section_name}" - image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", self.MIN, self.MAX + image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", self.MIN, self.MAX) mask_to_disk(np.array(lbl[0, :, :]), path_prefix + "_lbl.png", self.n_classes) return im, lbl @@ -546,13 +546,10 @@ class TestPatchLoader(PatchLoader): """ def __init__( - self, data_dir, n_classes, stride=30, patch_size=99, is_transform=True, augmentations=None, debug=False - ): + self, config, is_transform=True, augmentations=None, debug=False + ): #stride=30, patch_size=99 super(TestPatchLoader, self).__init__( - data_dir, - n_classes, - stride=stride, - patch_size=patch_size, + config, is_transform=is_transform, augmentations=augmentations, debug=debug, @@ -637,10 +634,8 @@ class TrainPatchLoaderWithDepth(TrainPatchLoader): def __init__( self, - data_dir, + config, split="train", - stride=30, - patch_size=99, is_transform=True, augmentations=None, seismic_path=None, @@ -648,10 +643,8 @@ def __init__( debug=False, ): super(TrainPatchLoaderWithDepth, self).__init__( - data_dir, + config, split=split, - stride=stride, - patch_size=patch_size, is_transform=is_transform, augmentations=augmentations, seismic_path=seismic_path, @@ -713,11 +706,8 @@ class TrainPatchLoaderWithSectionDepth(TrainPatchLoader): def __init__( self, - data_dir, - n_classes, + config, split="train", - stride=30, - patch_size=99, is_transform=True, augmentations=None, seismic_path=None, @@ -725,11 +715,8 @@ def __init__( debug=False, ): super(TrainPatchLoaderWithSectionDepth, self).__init__( - data_dir, - n_classes, + config, split=split, - stride=stride, - patch_size=patch_size, is_transform=is_transform, augmentations=augmentations, seismic_path=seismic_path, @@ -764,7 +751,7 @@ def __getitem__(self, index): outdir = f"debug/patchLoaderWithSectionDepth_{self.split}_raw" generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{patch_name}" - image_to_disk(im[0, :, :], path_prefix + "_img.png") + image_to_disk(im[0, :, :], path_prefix + "_img.png", self.MIN, self.MAX) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.augmentations is not None: @@ -778,7 +765,7 @@ def __getitem__(self, index): outdir = f"patchLoaderWithSectionDepth_{self.split}_{'aug' if self.augmentations is not None else 'noaug'}" generate_path(outdir) path_prefix = f"{outdir}/{index}" - image_to_disk(im[0, :, :], path_prefix + "_img.png") + image_to_disk(im[0, :, :], path_prefix + "_img.png", self.MIN, self.MAX) mask_to_disk(lbl, path_prefix + "_lbl.png", self.n_classes) if self.is_transform: @@ -791,7 +778,7 @@ def __getitem__(self, index): ) generate_path(outdir) path_prefix = f"{outdir}/index_{index}_section_{patch_name}" - image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png") + image_to_disk(np.array(im[0, :, :]), path_prefix + "_img.png", self.MIN, self.MAX) mask_to_disk(np.array(lbl[0, :, :]), path_prefix + "_lbl.png", self.n_classes) return im, lbl From 380f217e08a978b530eeed94e69f75fd467592db Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Tue, 9 Jun 2020 17:12:31 +0000 Subject: [PATCH 14/19] adde MIN and MAX to config --- .../interpretation/dutchf3_patch/local/configs/hrnet.yaml | 2 ++ .../dutchf3_patch/local/configs/patch_deconvnet.yaml | 2 ++ .../dutchf3_patch/local/configs/patch_deconvnet_skip.yaml | 2 ++ .../dutchf3_patch/local/configs/seresnet_unet.yaml | 2 ++ .../interpretation/dutchf3_patch/local/configs/unet.yaml | 2 ++ 5 files changed, 10 insertions(+) diff --git a/experiments/interpretation/dutchf3_patch/local/configs/hrnet.yaml b/experiments/interpretation/dutchf3_patch/local/configs/hrnet.yaml index e6e5091a..3f612796 100644 --- a/experiments/interpretation/dutchf3_patch/local/configs/hrnet.yaml +++ b/experiments/interpretation/dutchf3_patch/local/configs/hrnet.yaml @@ -16,6 +16,8 @@ DATASET: NUM_CLASSES: 6 ROOT: "/home/username/data/dutch/data" CLASS_WEIGHTS: [0.7151, 0.8811, 0.5156, 0.9346, 0.9683, 0.9852] + MIN: 0 + MAX: 7 MODEL: diff --git a/experiments/interpretation/dutchf3_patch/local/configs/patch_deconvnet.yaml b/experiments/interpretation/dutchf3_patch/local/configs/patch_deconvnet.yaml index 0d5ee793..7e6824dd 100644 --- a/experiments/interpretation/dutchf3_patch/local/configs/patch_deconvnet.yaml +++ b/experiments/interpretation/dutchf3_patch/local/configs/patch_deconvnet.yaml @@ -14,6 +14,8 @@ DATASET: NUM_CLASSES: 6 ROOT: /home/username/data/dutch/data CLASS_WEIGHTS: [0.7151, 0.8811, 0.5156, 0.9346, 0.9683, 0.9852] + MIN: 0 + MAX: 7 MODEL: NAME: patch_deconvnet diff --git a/experiments/interpretation/dutchf3_patch/local/configs/patch_deconvnet_skip.yaml b/experiments/interpretation/dutchf3_patch/local/configs/patch_deconvnet_skip.yaml index 4f06a089..7701cc30 100644 --- a/experiments/interpretation/dutchf3_patch/local/configs/patch_deconvnet_skip.yaml +++ b/experiments/interpretation/dutchf3_patch/local/configs/patch_deconvnet_skip.yaml @@ -14,6 +14,8 @@ DATASET: NUM_CLASSES: 6 ROOT: /home/username/data/dutch/data CLASS_WEIGHTS: [0.7151, 0.8811, 0.5156, 0.9346, 0.9683, 0.9852] + MIN: 0 + MAX: 7 MODEL: NAME: patch_deconvnet_skip diff --git a/experiments/interpretation/dutchf3_patch/local/configs/seresnet_unet.yaml b/experiments/interpretation/dutchf3_patch/local/configs/seresnet_unet.yaml index 962fe8fe..3850ca3e 100644 --- a/experiments/interpretation/dutchf3_patch/local/configs/seresnet_unet.yaml +++ b/experiments/interpretation/dutchf3_patch/local/configs/seresnet_unet.yaml @@ -15,6 +15,8 @@ DATASET: NUM_CLASSES: 6 ROOT: /home/username/data/dutch/data CLASS_WEIGHTS: [0.7151, 0.8811, 0.5156, 0.9346, 0.9683, 0.9852] + MIN: 0 + MAX: 7 MODEL: NAME: resnet_unet diff --git a/experiments/interpretation/dutchf3_patch/local/configs/unet.yaml b/experiments/interpretation/dutchf3_patch/local/configs/unet.yaml index ab4b9674..c2ee2e10 100644 --- a/experiments/interpretation/dutchf3_patch/local/configs/unet.yaml +++ b/experiments/interpretation/dutchf3_patch/local/configs/unet.yaml @@ -17,6 +17,8 @@ DATASET: NUM_CLASSES: 6 ROOT: '/home/username/data/dutch/data' CLASS_WEIGHTS: [0.7151, 0.8811, 0.5156, 0.9346, 0.9683, 0.9852] + MIN: 0 + MAX: 7 MODEL: NAME: resnet_unet From 4f3b5032b8f1222ac1b8b72d5f28f917dd39a837 Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Tue, 9 Jun 2020 18:08:48 +0000 Subject: [PATCH 15/19] notebook modified for loaders --- ...utch_F3_patch_model_training_and_evaluation.ipynb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/examples/interpretation/notebooks/Dutch_F3_patch_model_training_and_evaluation.ipynb b/examples/interpretation/notebooks/Dutch_F3_patch_model_training_and_evaluation.ipynb index 134a73ec..0c0d7380 100644 --- a/examples/interpretation/notebooks/Dutch_F3_patch_model_training_and_evaluation.ipynb +++ b/examples/interpretation/notebooks/Dutch_F3_patch_model_training_and_evaluation.ipynb @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -511,23 +511,17 @@ "TrainPatchLoader = get_patch_loader(config)\n", "\n", "train_set = TrainPatchLoader(\n", - " config.DATASET.ROOT,\n", - " config.DATASET.NUM_CLASSES,\n", + " config,\n", " split=\"train\",\n", " is_transform=True,\n", - " stride=config.TRAIN.STRIDE,\n", - " patch_size=config.TRAIN.PATCH_SIZE,\n", " augmentations=train_aug,\n", ")\n", "n_classes = train_set.n_classes\n", "logger.info(train_set)\n", "val_set = TrainPatchLoader(\n", - " config.DATASET.ROOT,\n", - " config.DATASET.NUM_CLASSES,\n", + " config,\n", " split=\"val\",\n", " is_transform=True,\n", - " stride=config.TRAIN.STRIDE,\n", - " patch_size=config.TRAIN.PATCH_SIZE,\n", " augmentations=val_aug,\n", ")\n", "\n", From ff797b79201823e7a1a5468e18716fc337b29704 Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Tue, 9 Jun 2020 18:19:48 +0000 Subject: [PATCH 16/19] another dataloader in notebook --- .../Dutch_F3_patch_model_training_and_evaluation.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/interpretation/notebooks/Dutch_F3_patch_model_training_and_evaluation.ipynb b/examples/interpretation/notebooks/Dutch_F3_patch_model_training_and_evaluation.ipynb index 0c0d7380..a1fdd642 100644 --- a/examples/interpretation/notebooks/Dutch_F3_patch_model_training_and_evaluation.ipynb +++ b/examples/interpretation/notebooks/Dutch_F3_patch_model_training_and_evaluation.ipynb @@ -926,7 +926,7 @@ "# Load test data\n", "TestSectionLoader = get_test_loader(config)\n", "test_set = TestSectionLoader(\n", - " config.DATASET.ROOT, config.DATASET.NUM_CLASSES, split=split, is_transform=True, augmentations=section_aug\n", + " config, split=split, is_transform=True, augmentations=section_aug\n", ")\n", "# needed to fix this bug in pytorch https://github.com/pytorch/pytorch/issues/973\n", "# one of the workers will quit prematurely\n", From c92ce78796d8e3d7818ec269f9460eecf3b231c6 Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Tue, 9 Jun 2020 19:59:34 +0000 Subject: [PATCH 17/19] readme update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 295be5ce..8e0822ce 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ python prepare_dutchf3.py split_train_val patch --data_dir=${data_dir}/data --la --stride=50 --patch_size=100 --split_direction=both # For section-based experiments -python prepare_dutchf3.py split_train_val section --data-dir=${data_dir}/data --label_file=train/train_labels.npy --output_dir=splits \ --split_direction=both +python prepare_dutchf3.py split_train_val section --data-dir=${data_dir}/data --label_file=train/train_labels.npy --output_dir=splits --split_direction=both # go back to repo root cd .. From 6140e235142318025a091d477e93f71bfa01c9d7 Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Tue, 9 Jun 2020 20:47:32 +0000 Subject: [PATCH 18/19] changed the default values for min max, updated the docstring for loaders, removed suppressed lines --- .../dutchf3_patch/local/configs/hrnet.yaml | 4 +- .../local/configs/patch_deconvnet.yaml | 4 +- .../local/configs/patch_deconvnet_skip.yaml | 4 +- .../local/configs/seresnet_unet.yaml | 4 +- .../dutchf3_patch/local/configs/unet.yaml | 4 +- .../dutchf3_patch/local/default.py | 4 +- .../dutchf3/data.py | 45 +++++-------------- 7 files changed, 24 insertions(+), 45 deletions(-) diff --git a/experiments/interpretation/dutchf3_patch/local/configs/hrnet.yaml b/experiments/interpretation/dutchf3_patch/local/configs/hrnet.yaml index 3f612796..94921bf7 100644 --- a/experiments/interpretation/dutchf3_patch/local/configs/hrnet.yaml +++ b/experiments/interpretation/dutchf3_patch/local/configs/hrnet.yaml @@ -16,8 +16,8 @@ DATASET: NUM_CLASSES: 6 ROOT: "/home/username/data/dutch/data" CLASS_WEIGHTS: [0.7151, 0.8811, 0.5156, 0.9346, 0.9683, 0.9852] - MIN: 0 - MAX: 7 + MIN: -1 + MAX: 1 MODEL: diff --git a/experiments/interpretation/dutchf3_patch/local/configs/patch_deconvnet.yaml b/experiments/interpretation/dutchf3_patch/local/configs/patch_deconvnet.yaml index 7e6824dd..9722cec9 100644 --- a/experiments/interpretation/dutchf3_patch/local/configs/patch_deconvnet.yaml +++ b/experiments/interpretation/dutchf3_patch/local/configs/patch_deconvnet.yaml @@ -14,8 +14,8 @@ DATASET: NUM_CLASSES: 6 ROOT: /home/username/data/dutch/data CLASS_WEIGHTS: [0.7151, 0.8811, 0.5156, 0.9346, 0.9683, 0.9852] - MIN: 0 - MAX: 7 + MIN: -1 + MAX: 1 MODEL: NAME: patch_deconvnet diff --git a/experiments/interpretation/dutchf3_patch/local/configs/patch_deconvnet_skip.yaml b/experiments/interpretation/dutchf3_patch/local/configs/patch_deconvnet_skip.yaml index 7701cc30..b1261308 100644 --- a/experiments/interpretation/dutchf3_patch/local/configs/patch_deconvnet_skip.yaml +++ b/experiments/interpretation/dutchf3_patch/local/configs/patch_deconvnet_skip.yaml @@ -14,8 +14,8 @@ DATASET: NUM_CLASSES: 6 ROOT: /home/username/data/dutch/data CLASS_WEIGHTS: [0.7151, 0.8811, 0.5156, 0.9346, 0.9683, 0.9852] - MIN: 0 - MAX: 7 + MIN: -1 + MAX: 1 MODEL: NAME: patch_deconvnet_skip diff --git a/experiments/interpretation/dutchf3_patch/local/configs/seresnet_unet.yaml b/experiments/interpretation/dutchf3_patch/local/configs/seresnet_unet.yaml index 3850ca3e..448da775 100644 --- a/experiments/interpretation/dutchf3_patch/local/configs/seresnet_unet.yaml +++ b/experiments/interpretation/dutchf3_patch/local/configs/seresnet_unet.yaml @@ -15,8 +15,8 @@ DATASET: NUM_CLASSES: 6 ROOT: /home/username/data/dutch/data CLASS_WEIGHTS: [0.7151, 0.8811, 0.5156, 0.9346, 0.9683, 0.9852] - MIN: 0 - MAX: 7 + MIN: -1 + MAX: 1 MODEL: NAME: resnet_unet diff --git a/experiments/interpretation/dutchf3_patch/local/configs/unet.yaml b/experiments/interpretation/dutchf3_patch/local/configs/unet.yaml index c2ee2e10..5ae1ee45 100644 --- a/experiments/interpretation/dutchf3_patch/local/configs/unet.yaml +++ b/experiments/interpretation/dutchf3_patch/local/configs/unet.yaml @@ -17,8 +17,8 @@ DATASET: NUM_CLASSES: 6 ROOT: '/home/username/data/dutch/data' CLASS_WEIGHTS: [0.7151, 0.8811, 0.5156, 0.9346, 0.9683, 0.9852] - MIN: 0 - MAX: 7 + MIN: -1 + MAX: 1 MODEL: NAME: resnet_unet diff --git a/experiments/interpretation/dutchf3_patch/local/default.py b/experiments/interpretation/dutchf3_patch/local/default.py index a5fe7c9c..e87d18c4 100644 --- a/experiments/interpretation/dutchf3_patch/local/default.py +++ b/experiments/interpretation/dutchf3_patch/local/default.py @@ -37,8 +37,8 @@ _C.DATASET.ROOT = "" _C.DATASET.NUM_CLASSES = 6 _C.DATASET.CLASS_WEIGHTS = [0.7151, 0.8811, 0.5156, 0.9346, 0.9683, 0.9852] -_C.DATASET.MIN = 0 -_C.DATASET.MAX = 7 +_C.DATASET.MIN = -1 +_C.DATASET.MAX = 1 # common params for NETWORK _C.MODEL = CN() diff --git a/interpretation/deepseismic_interpretation/dutchf3/data.py b/interpretation/deepseismic_interpretation/dutchf3/data.py index da1e86c2..7b678005 100644 --- a/interpretation/deepseismic_interpretation/dutchf3/data.py +++ b/interpretation/deepseismic_interpretation/dutchf3/data.py @@ -117,8 +117,7 @@ def read_labels(fname, data_info): class SectionLoader(data.Dataset): """ Base class for section data loader - :param str data_dir: Root directory for training/test data - :param str n_classes: number of segmentation mask classes + :param config: configuration object to define other attributes in loaders :param str split: split file to use for loading patches :param bool is_transform: Transform patch to dimensions expected by PyTorch :param list augmentations: Data augmentations to apply to patches @@ -187,8 +186,7 @@ def transform(self, img, lbl): class TrainSectionLoader(SectionLoader): """ Training data loader for sections - :param str data_dir: Root directory for training/test data - :param str n_classes: number of segmentation mask classes + :param config: configuration object to define other attributes in loaders :param str split: split file to use for loading patches :param bool is_transform: Transform patch to dimensions expected by PyTorch :param list augmentations: Data augmentations to apply to patches @@ -240,8 +238,7 @@ def __init__( class TrainSectionLoaderWithDepth(TrainSectionLoader): """ Section data loader that includes additional channel for depth - :param str data_dir: Root directory for training/test data - :param str n_classes: number of segmentation mask classes + :param config: configuration object to define other attributes in loaders :param str split: split file to use for loading patches :param bool is_transform: Transform patch to dimensions expected by PyTorch :param list augmentations: Data augmentations to apply to patches @@ -302,8 +299,7 @@ def __getitem__(self, index): class TestSectionLoader(SectionLoader): """ Test data loader for sections - :param str data_dir: Root directory for training/test data - :param str n_classes: number of segmentation mask classes + :param config: configuration object to define other attributes in loaders :param str split: split file to use for loading patches :param bool is_transform: Transform patch to dimensions expected by PyTorch :param list augmentations: Data augmentations to apply to patches @@ -353,8 +349,7 @@ def __init__( class TestSectionLoaderWithDepth(TestSectionLoader): """ Test data loader for sections that includes additional channel for depth - :param str data_dir: Root directory for training/test data - :param str n_classes: number of segmentation mask classes + :param config: configuration object to define other attributes in loaders :param str split: split file to use for loading patches :param bool is_transform: Transform patch to dimensions expected by PyTorch :param list augmentations: Data augmentations to apply to patches @@ -439,10 +434,7 @@ def _transform_WH_to_HW(numpy_array): class PatchLoader(data.Dataset): """ Base Data loader for the patch-based deconvnet - :param str data_dir: Root directory for training/test data - :param str n_classes: number of segmentation mask classes - :param int stride: training data stride - :param int patch_size: Size of patch for training + :param config: configuration object to define other attributes in loaders :param str split: split file to use for loading patches :param bool is_transform: Transform patch to dimensions expected by PyTorch :param list augmentations: Data augmentations to apply to patches @@ -451,7 +443,7 @@ class PatchLoader(data.Dataset): def __init__( self, config, is_transform=True, augmentations=None, debug=False, - ): #stride=30, patch_size=99, + ) self.data_dir = config.DATASET.ROOT self.n_classes = config.DATASET.NUM_CLASSES self.MIN = config.DATASET.MIN @@ -536,10 +528,7 @@ def transform(self, img, lbl): class TestPatchLoader(PatchLoader): """ Test Data loader for the patch-based deconvnet - :param str data_dir: Root directory for training/test data - :param str n_classes: number of segmentation mask classes - :param int stride: training data stride - :param int patch_size: Size of patch for training + :param config: configuration object to define other attributes in loaders :param bool is_transform: Transform patch to dimensions expected by PyTorch :param list augmentations: Data augmentations to apply to patches :param bool debug: enable debugging output @@ -547,7 +536,7 @@ class TestPatchLoader(PatchLoader): def __init__( self, config, is_transform=True, augmentations=None, debug=False - ): #stride=30, patch_size=99 + ): super(TestPatchLoader, self).__init__( config, is_transform=is_transform, @@ -567,9 +556,7 @@ def __init__( class TrainPatchLoader(PatchLoader): """ Train data loader for the patch-based deconvnet - :param str data_dir: Root directory for training/test data - :param int stride: training data stride - :param int patch_size: Size of patch for training + :param config: configuration object to define other attributes in loaders :param str split: split file to use for loading patches :param bool is_transform: Transform patch to dimensions expected by PyTorch :param list augmentations: Data augmentations to apply to patches @@ -580,8 +567,6 @@ def __init__( self, config, split="train", - # stride=30, - # patch_size=99, is_transform=True, augmentations=None, seismic_path=None, @@ -590,8 +575,6 @@ def __init__( ): super(TrainPatchLoader, self).__init__( config, - # stride=stride, - # patch_size=patch_size, is_transform=is_transform, augmentations=augmentations, debug=debug, @@ -623,9 +606,7 @@ def __init__( class TrainPatchLoaderWithDepth(TrainPatchLoader): """ Train data loader for the patch-based deconvnet with patch depth channel - :param str data_dir: Root directory for training/test data - :param int stride: training data stride - :param int patch_size: Size of patch for training + :param config: configuration object to define other attributes in loaders :param str split: split file to use for loading patches :param bool is_transform: Transform patch to dimensions expected by PyTorch :param list augmentations: Data augmentations to apply to patches @@ -693,9 +674,7 @@ def _transform_HWC_to_CHW(numpy_array): class TrainPatchLoaderWithSectionDepth(TrainPatchLoader): """ Train data loader for the patch-based deconvnet section depth channel - :param str data_dir: Root directory for training/test data - :param int stride: training data stride - :param int patch_size: Size of patch for training + :param config: configuration object to define other attributes in loaders :param str split: split file to use for loading patches :param bool is_transform: Transform patch to dimensions expected by PyTorch :param list augmentations: Data augmentations to apply to patches From ab184d87a46ed279307d15289e4e51002106a4e5 Mon Sep 17 00:00:00 2001 From: Fatemeh Date: Tue, 9 Jun 2020 20:54:11 +0000 Subject: [PATCH 19/19] debug --- interpretation/deepseismic_interpretation/dutchf3/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interpretation/deepseismic_interpretation/dutchf3/data.py b/interpretation/deepseismic_interpretation/dutchf3/data.py index 7b678005..83b4635b 100644 --- a/interpretation/deepseismic_interpretation/dutchf3/data.py +++ b/interpretation/deepseismic_interpretation/dutchf3/data.py @@ -443,7 +443,7 @@ class PatchLoader(data.Dataset): def __init__( self, config, is_transform=True, augmentations=None, debug=False, - ) + ): self.data_dir = config.DATASET.ROOT self.n_classes = config.DATASET.NUM_CLASSES self.MIN = config.DATASET.MIN