From 245d60c5031317af0ed2473cfedc92f60c1a8dd6 Mon Sep 17 00:00:00 2001 From: palatos Date: Wed, 28 Oct 2020 14:58:53 -0300 Subject: [PATCH 01/10] Adding blur perturbation --- lime/lime_image.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lime/lime_image.py b/lime/lime_image.py index 5c252944..d181c152 100644 --- a/lime/lime_image.py +++ b/lime/lime_image.py @@ -184,6 +184,10 @@ def explain_instance(self, image, classifier_fn, labels=(1,), segments = segmentation_fn(image) except ValueError as e: raise e + + if hide_color is 'blur': + fudged_image = im.copy() + fudged_image = gaussian_filter(fudged_image,sigma=3) fudged_image = image.copy() if hide_color is None: From 004df4ee3689d506ffd2271a64ff9c2a44458c46 Mon Sep 17 00:00:00 2001 From: palatos <49554605+palatos@users.noreply.github.com> Date: Wed, 28 Oct 2020 15:02:09 -0300 Subject: [PATCH 02/10] no message --- lime/lime_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lime/lime_image.py b/lime/lime_image.py index d181c152..9a313dd0 100644 --- a/lime/lime_image.py +++ b/lime/lime_image.py @@ -187,7 +187,7 @@ def explain_instance(self, image, classifier_fn, labels=(1,), if hide_color is 'blur': fudged_image = im.copy() - fudged_image = gaussian_filter(fudged_image,sigma=3) + fudged_image = gaussian_filter(fudged_image,sigma=2) fudged_image = image.copy() if hide_color is None: From c1c9218d10ef772df012731afc81264b457806c4 Mon Sep 17 00:00:00 2001 From: palatos Date: Wed, 28 Oct 2020 15:19:45 -0300 Subject: [PATCH 03/10] Adding Blur --- lime/lime_image.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lime/lime_image.py b/lime/lime_image.py index 9a313dd0..535df57e 100644 --- a/lime/lime_image.py +++ b/lime/lime_image.py @@ -186,10 +186,10 @@ def explain_instance(self, image, classifier_fn, labels=(1,), raise e if hide_color is 'blur': - fudged_image = im.copy() - fudged_image = gaussian_filter(fudged_image,sigma=2) + fudged_image = im.copy() + fudged_image = gaussian_filter(fudged_image,sigma=2) - fudged_image = image.copy() + fudged_image = image.copy() if hide_color is None: for x in np.unique(segments): fudged_image[segments == x] = ( From 67a4da687a4b84879ebe3116d511cd41d644b59a Mon Sep 17 00:00:00 2001 From: palatos Date: Wed, 28 Oct 2020 15:21:46 -0300 Subject: [PATCH 04/10] Test --- lime/lime_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lime/lime_image.py b/lime/lime_image.py index 535df57e..c844e9f4 100644 --- a/lime/lime_image.py +++ b/lime/lime_image.py @@ -187,7 +187,7 @@ def explain_instance(self, image, classifier_fn, labels=(1,), if hide_color is 'blur': fudged_image = im.copy() - fudged_image = gaussian_filter(fudged_image,sigma=2) + fudged_image = gaussian_filter(fudged_image,sigma=3) fudged_image = image.copy() if hide_color is None: From 9454010139c871aa59c41b3887fe173d730fd54a Mon Sep 17 00:00:00 2001 From: palatos Date: Wed, 28 Oct 2020 15:41:34 -0300 Subject: [PATCH 05/10] Correction --- lime/lime_image.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lime/lime_image.py b/lime/lime_image.py index c844e9f4..9841b199 100644 --- a/lime/lime_image.py +++ b/lime/lime_image.py @@ -186,10 +186,9 @@ def explain_instance(self, image, classifier_fn, labels=(1,), raise e if hide_color is 'blur': - fudged_image = im.copy() - fudged_image = gaussian_filter(fudged_image,sigma=3) - fudged_image = image.copy() + fudged_image = gaussian_filter(fudged_image,sigma=3) + if hide_color is None: for x in np.unique(segments): fudged_image[segments == x] = ( From c5d604d65518cab8fe0c895431219da3475b8400 Mon Sep 17 00:00:00 2001 From: palatos Date: Wed, 28 Oct 2020 15:47:35 -0300 Subject: [PATCH 06/10] no message --- lime/lime_image.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lime/lime_image.py b/lime/lime_image.py index 9841b199..37da13ad 100644 --- a/lime/lime_image.py +++ b/lime/lime_image.py @@ -184,11 +184,12 @@ def explain_instance(self, image, classifier_fn, labels=(1,), segments = segmentation_fn(image) except ValueError as e: raise e - - if hide_color is 'blur': + fudged_image = image.copy() + + if hide_color is 'blur': fudged_image = gaussian_filter(fudged_image,sigma=3) - + if hide_color is None: for x in np.unique(segments): fudged_image[segments == x] = ( From cde187959899289abca6788e5175b700a9c03bbb Mon Sep 17 00:00:00 2001 From: palatos Date: Wed, 28 Oct 2020 15:50:01 -0300 Subject: [PATCH 07/10] no message --- lime/lime_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lime/lime_image.py b/lime/lime_image.py index 37da13ad..8a63bd55 100644 --- a/lime/lime_image.py +++ b/lime/lime_image.py @@ -185,7 +185,7 @@ def explain_instance(self, image, classifier_fn, labels=(1,), except ValueError as e: raise e - fudged_image = image.copy() + fudged_image = image.copy() if hide_color is 'blur': fudged_image = gaussian_filter(fudged_image,sigma=3) From e37ac976764be04bc879108d4ae99391519a4d48 Mon Sep 17 00:00:00 2001 From: palatos Date: Wed, 28 Oct 2020 15:55:36 -0300 Subject: [PATCH 08/10] Adding blur option to hide_color --- lime/lime_image.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lime/lime_image.py b/lime/lime_image.py index 8a63bd55..2db064cc 100644 --- a/lime/lime_image.py +++ b/lime/lime_image.py @@ -15,6 +15,7 @@ from . import lime_base from .wrappers.scikit_image import SegmentationAlgorithm +from scipy.ndimage import gaussian_filter class ImageExplanation(object): def __init__(self, image, segments): From e8bcaccb2abc8205eefbbf1b5299db2683ca105a Mon Sep 17 00:00:00 2001 From: palatos Date: Wed, 28 Oct 2020 16:20:57 -0300 Subject: [PATCH 09/10] Blur --- lime/lime_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lime/lime_image.py b/lime/lime_image.py index 2db064cc..a23adfd5 100644 --- a/lime/lime_image.py +++ b/lime/lime_image.py @@ -191,7 +191,7 @@ def explain_instance(self, image, classifier_fn, labels=(1,), if hide_color is 'blur': fudged_image = gaussian_filter(fudged_image,sigma=3) - if hide_color is None: + elif hide_color is None: for x in np.unique(segments): fudged_image[segments == x] = ( np.mean(image[segments == x][:, 0]), From fdc13bac76bf93f95e4c1d265706e19ced69fc66 Mon Sep 17 00:00:00 2001 From: palatos Date: Wed, 28 Oct 2020 18:21:00 -0300 Subject: [PATCH 10/10] Add skimage gaussian blur --- lime/lime_image.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lime/lime_image.py b/lime/lime_image.py index a23adfd5..055d914d 100644 --- a/lime/lime_image.py +++ b/lime/lime_image.py @@ -15,7 +15,7 @@ from . import lime_base from .wrappers.scikit_image import SegmentationAlgorithm -from scipy.ndimage import gaussian_filter +from skimage.filters import gaussian class ImageExplanation(object): def __init__(self, image, segments): @@ -189,7 +189,7 @@ def explain_instance(self, image, classifier_fn, labels=(1,), fudged_image = image.copy() if hide_color is 'blur': - fudged_image = gaussian_filter(fudged_image,sigma=3) + fudged_image = gaussian(fudged_image, sigma=4, multichannel=True, preserve_range = True) elif hide_color is None: for x in np.unique(segments): @@ -197,6 +197,7 @@ def explain_instance(self, image, classifier_fn, labels=(1,), np.mean(image[segments == x][:, 0]), np.mean(image[segments == x][:, 1]), np.mean(image[segments == x][:, 2])) + else: fudged_image[:] = hide_color