From 6602228aa2e648e8ea011f8d9409bcbb9e843f11 Mon Sep 17 00:00:00 2001 From: Laura Ootes Date: Wed, 12 Jun 2024 15:17:35 +0200 Subject: [PATCH 01/16] delete default Random state for Lime --- dianna/dashboard/_shared.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/dianna/dashboard/_shared.py b/dianna/dashboard/_shared.py index 7bdd8db7..3ee41960 100644 --- a/dianna/dashboard/_shared.py +++ b/dianna/dashboard/_shared.py @@ -88,11 +88,6 @@ def _get_params(method: str): 'sigma': st.number_input('σ', value=0), } - elif method == 'LIME': - return { - 'rand_state': st.number_input('Random state', value=2), - } - else: raise ValueError(f'No such method: {method}') From 51d906869e1eef9551d237957b2e219c0b978c0c Mon Sep 17 00:00:00 2001 From: Laura Ootes Date: Thu, 13 Jun 2024 10:02:47 +0200 Subject: [PATCH 02/16] reset rand state --- dianna/dashboard/_shared.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dianna/dashboard/_shared.py b/dianna/dashboard/_shared.py index 3ee41960..7bdd8db7 100644 --- a/dianna/dashboard/_shared.py +++ b/dianna/dashboard/_shared.py @@ -88,6 +88,11 @@ def _get_params(method: str): 'sigma': st.number_input('σ', value=0), } + elif method == 'LIME': + return { + 'rand_state': st.number_input('Random state', value=2), + } + else: raise ValueError(f'No such method: {method}') From 8ea7d4babe8cd17042f005c4bbab3616fcf420c1 Mon Sep 17 00:00:00 2001 From: Laura Ootes Date: Thu, 13 Jun 2024 10:48:20 +0200 Subject: [PATCH 03/16] fix name of variable --- dianna/dashboard/_shared.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dianna/dashboard/_shared.py b/dianna/dashboard/_shared.py index 7bdd8db7..6790bddd 100644 --- a/dianna/dashboard/_shared.py +++ b/dianna/dashboard/_shared.py @@ -90,7 +90,7 @@ def _get_params(method: str): elif method == 'LIME': return { - 'rand_state': st.number_input('Random state', value=2), + 'random_state': st.number_input('Random state', value=2), } else: From a4f73c708e30f7585fd5e164f437e9f92eaa8253 Mon Sep 17 00:00:00 2001 From: Laura Ootes Date: Thu, 13 Jun 2024 10:48:41 +0200 Subject: [PATCH 04/16] add random_state variable to lime timseries --- dianna/methods/lime_timeseries.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dianna/methods/lime_timeseries.py b/dianna/methods/lime_timeseries.py index d1851e2c..0cbc517f 100644 --- a/dianna/methods/lime_timeseries.py +++ b/dianna/methods/lime_timeseries.py @@ -23,6 +23,7 @@ def __init__( verbose=False, preprocess_function=None, feature_selection='auto', + random_state = None ): """Initializes Lime explainer for timeseries. From 97259402e9a583eec6911ccec008c7e4fbf54980 Mon Sep 17 00:00:00 2001 From: Laura Ootes Date: Thu, 13 Jun 2024 11:32:40 +0200 Subject: [PATCH 05/16] add variable description --- dianna/methods/lime_timeseries.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dianna/methods/lime_timeseries.py b/dianna/methods/lime_timeseries.py index 0cbc517f..cc87b451 100644 --- a/dianna/methods/lime_timeseries.py +++ b/dianna/methods/lime_timeseries.py @@ -33,6 +33,7 @@ def __init__( feature_selection (str): Feature selection method to be used by explainer. preprocess_function (callable, optional): Function to preprocess the time series data before passing it to the explainer. Defaults to None. + random_state (int or np.RandomState, optional): seed or random state. Unused variable for current ts method """ def kernel(d): From 8691e9122a14b89d98257532b7cd72d49eedbb64 Mon Sep 17 00:00:00 2001 From: Laura Ootes Date: Thu, 13 Jun 2024 15:08:45 +0200 Subject: [PATCH 06/16] add test for dashboard text page LIME --- tests/test_dashboard.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/test_dashboard.py b/tests/test_dashboard.py index 62da478b..5207ded6 100644 --- a/tests/test_dashboard.py +++ b/tests/test_dashboard.py @@ -103,19 +103,24 @@ def test_text_page(page: Page): expect(page.get_by_text('Select a method to continue')).to_be_visible() page.locator('label').filter(has_text='RISE').locator('span').click() + page.locator('label').filter(has_text='LIME').locator('span').click() page.get_by_text('Running...').wait_for(state='detached', timeout=45_000) for selector in ( page.get_by_role('heading', name='RISE').get_by_text('RISE'), - # first image + page.get_by_role('heading', name='LIME').get_by_text('LIME'), + # Images for positive (RISE/LIME) page.get_by_role('heading', name='positive').get_by_text('positive'), - page.get_by_role('img', name='0').first, - # second image + page.get_by_role('img', name='0').first, + page.get_by_role('img', name='0').nth(1), + + # Images for negative (RISE/LIME) page.get_by_role('heading', name='negative').get_by_text('negative'), - page.get_by_role('img', name='0').nth(1), + page.get_by_role('img', name='0').nth(2), + page.get_by_role('img', name='0').nth(3), ): print(selector) expect(selector).to_be_visible() From 2c9f39887ed1adbebd42cd98fc8e474de9ce1107 Mon Sep 17 00:00:00 2001 From: Laura Ootes Date: Mon, 17 Jun 2024 09:30:17 +0200 Subject: [PATCH 07/16] fix kernelshap image for dashboard? --- dianna/dashboard/_models_image.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dianna/dashboard/_models_image.py b/dianna/dashboard/_models_image.py index 2a79997a..0541ae81 100644 --- a/dianna/dashboard/_models_image.py +++ b/dianna/dashboard/_models_image.py @@ -42,12 +42,12 @@ def _run_kernelshap_image(model, image, i, **kwargs): with tempfile.NamedTemporaryFile() as f: f.write(model) f.flush() - shap_values, segments_slic = explain_image(f.name, - image, - method='KernelSHAP', - **kwargs) - - return fill_segmentation(shap_values[i][0], segments_slic) + relevances = explain_image(f.name, + image, + method='KernelSHAP', + **kwargs) + #return fill_segmentation(relevances[i][0], segments_slic) + return relevances[0] explain_image_dispatcher = { From 6fcea8e4e6a6b6ffe3790101f13a3abbd4df7ed2 Mon Sep 17 00:00:00 2001 From: Laura Ootes Date: Mon, 17 Jun 2024 09:36:45 +0200 Subject: [PATCH 08/16] add kernelsshap and lime tests for images --- tests/test_dashboard.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_dashboard.py b/tests/test_dashboard.py index 5207ded6..e7371a68 100644 --- a/tests/test_dashboard.py +++ b/tests/test_dashboard.py @@ -144,17 +144,25 @@ def test_image_page(page: Page): expect(page.get_by_text('Select a method to continue')).to_be_visible() page.locator('label').filter(has_text='RISE').locator('span').click() + page.locator('label').filter(has_text='KernelSHAP').locator('span').click() + page.locator('label').filter(has_text='LIME').locator('span').click() page.get_by_text('Running...').wait_for(state='detached', timeout=45_000) for selector in ( page.get_by_role('heading', name='RISE').get_by_text('RISE'), + page.get_by_role('heading', name='KernelSHAP').get_by_text('KernelSHAP'), + page.get_by_role('heading', name='LIME').get_by_text('LIME'), # first image page.get_by_role('heading', name='0').get_by_text('0'), page.get_by_role('img', name='0').first, + page.get_by_role('img', name='0').nth(1), + page.get_by_role('img', name='0').nth(2), # second image page.get_by_role('heading', name='1').get_by_text('1'), - page.get_by_role('img', name='0').nth(1), + page.get_by_role('img', name='0').nth(3), + page.get_by_role('img', name='0').nth(4), + page.get_by_role('img', name='0').nth(5), ): expect(selector).to_be_visible(timeout=45_000) From e120805ba0a4ab672c12183e4d98ff7a3f432bce Mon Sep 17 00:00:00 2001 From: Laura Ootes Date: Mon, 17 Jun 2024 09:38:04 +0200 Subject: [PATCH 09/16] increase timeouts --- tests/test_dashboard.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_dashboard.py b/tests/test_dashboard.py index e7371a68..a7acea37 100644 --- a/tests/test_dashboard.py +++ b/tests/test_dashboard.py @@ -105,7 +105,7 @@ def test_text_page(page: Page): page.locator('label').filter(has_text='RISE').locator('span').click() page.locator('label').filter(has_text='LIME').locator('span').click() - page.get_by_text('Running...').wait_for(state='detached', timeout=45_000) + page.get_by_text('Running...').wait_for(state='detached', timeout=60_000) for selector in ( page.get_by_role('heading', name='RISE').get_by_text('RISE'), @@ -136,7 +136,7 @@ def test_image_page(page: Page): expect( page.get_by_text('Add your input data in the left panel to continue') - ).to_be_visible(timeout=30_000) + ).to_be_visible(timeout=45_000) page.locator('label').filter( has_text='Load example data').locator('span').click() @@ -164,7 +164,7 @@ def test_image_page(page: Page): page.get_by_role('img', name='0').nth(4), page.get_by_role('img', name='0').nth(5), ): - expect(selector).to_be_visible(timeout=45_000) + expect(selector).to_be_visible(timeout=60_000) def test_timeseries_page(page: Page): From 75952493bfb8c8b1b7e77d04c3657f6659e3cdbb Mon Sep 17 00:00:00 2001 From: Laura Ootes Date: Mon, 17 Jun 2024 10:11:44 +0200 Subject: [PATCH 10/16] add test for LIME timeseries --- tests/test_dashboard.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_dashboard.py b/tests/test_dashboard.py index a7acea37..d6291756 100644 --- a/tests/test_dashboard.py +++ b/tests/test_dashboard.py @@ -184,17 +184,21 @@ def test_timeseries_page(page: Page): expect(page.get_by_text('Select a method to continue')).to_be_visible() + page.locator('label').filter(has_text='LIME').locator('span').click() page.locator('label').filter(has_text='RISE').locator('span').click() - page.get_by_text('Running...').wait_for(state='detached', timeout=45_000) + page.get_by_text('Running...').wait_for(state='detached', timeout=60_000) for selector in ( + page.get_by_role('heading', name='LIME').get_by_text('LIME'), page.get_by_role('heading', name='RISE').get_by_text('RISE'), # first image page.get_by_role('heading', name='winter').get_by_text('winter'), page.get_by_role('img', name='0').first, + page.get_by_role('img', name='0').nth(1), # second image page.get_by_role('heading', name='summer').get_by_text('summer'), - page.get_by_role('img', name='0').nth(1), + page.get_by_role('img', name='0').nth(2), + page.get_by_role('img', name='0').nth(3), ): expect(selector).to_be_visible() From d15f33c248bc7da0782856e07aabd8ac8c4949d7 Mon Sep 17 00:00:00 2001 From: Laura Ootes Date: Mon, 17 Jun 2024 10:35:25 +0200 Subject: [PATCH 11/16] delete unused import --- dianna/dashboard/_models_image.py | 1 - 1 file changed, 1 deletion(-) diff --git a/dianna/dashboard/_models_image.py b/dianna/dashboard/_models_image.py index 0541ae81..28c7e72d 100644 --- a/dianna/dashboard/_models_image.py +++ b/dianna/dashboard/_models_image.py @@ -1,6 +1,5 @@ import tempfile import streamlit as st -from _model_utils import fill_segmentation from _model_utils import preprocess_function from onnx_tf.backend import prepare from dianna import explain_image From 39dcad5892176eda71606e83ff4a1f2322cbda5e Mon Sep 17 00:00:00 2001 From: Laura Ootes Date: Mon, 17 Jun 2024 10:35:42 +0200 Subject: [PATCH 12/16] delete trailing whitespaces --- tests/test_dashboard.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_dashboard.py b/tests/test_dashboard.py index d6291756..a3d721fa 100644 --- a/tests/test_dashboard.py +++ b/tests/test_dashboard.py @@ -109,11 +109,11 @@ def test_text_page(page: Page): for selector in ( page.get_by_role('heading', name='RISE').get_by_text('RISE'), - page.get_by_role('heading', name='LIME').get_by_text('LIME'), + page.get_by_role('heading', name='LIME').get_by_text('LIME'), # Images for positive (RISE/LIME) page.get_by_role('heading', name='positive').get_by_text('positive'), - page.get_by_role('img', name='0').first, + page.get_by_role('img', name='0').first, page.get_by_role('img', name='0').nth(1), # Images for negative (RISE/LIME) From d6bb27ead20d926bb9f635a2403334358dca31e0 Mon Sep 17 00:00:00 2001 From: Laura Ootes Date: Mon, 17 Jun 2024 10:51:26 +0200 Subject: [PATCH 13/16] increase timeout --- tests/test_dashboard.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_dashboard.py b/tests/test_dashboard.py index a3d721fa..9eab1aec 100644 --- a/tests/test_dashboard.py +++ b/tests/test_dashboard.py @@ -105,7 +105,7 @@ def test_text_page(page: Page): page.locator('label').filter(has_text='RISE').locator('span').click() page.locator('label').filter(has_text='LIME').locator('span').click() - page.get_by_text('Running...').wait_for(state='detached', timeout=60_000) + page.get_by_text('Running...').wait_for(state='detached', timeout=100_000) for selector in ( page.get_by_role('heading', name='RISE').get_by_text('RISE'), @@ -136,7 +136,7 @@ def test_image_page(page: Page): expect( page.get_by_text('Add your input data in the left panel to continue') - ).to_be_visible(timeout=45_000) + ).to_be_visible(timeout=100_000) page.locator('label').filter( has_text='Load example data').locator('span').click() @@ -164,7 +164,7 @@ def test_image_page(page: Page): page.get_by_role('img', name='0').nth(4), page.get_by_role('img', name='0').nth(5), ): - expect(selector).to_be_visible(timeout=60_000) + expect(selector).to_be_visible(timeout=100_000) def test_timeseries_page(page: Page): @@ -187,7 +187,7 @@ def test_timeseries_page(page: Page): page.locator('label').filter(has_text='LIME').locator('span').click() page.locator('label').filter(has_text='RISE').locator('span').click() - page.get_by_text('Running...').wait_for(state='detached', timeout=60_000) + page.get_by_text('Running...').wait_for(state='detached', timeout=100_000) for selector in ( page.get_by_role('heading', name='LIME').get_by_text('LIME'), From c0aa94f15dbb1ea1347c1d14a8d41330f7b6fd45 Mon Sep 17 00:00:00 2001 From: Laura Ootes Date: Mon, 17 Jun 2024 10:53:34 +0200 Subject: [PATCH 14/16] add watchdog for increased performance --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 596ba029..39e9e5ae 100644 --- a/setup.cfg +++ b/setup.cfg @@ -95,6 +95,7 @@ dashboard = spacy streamlit torchtext + watchdog notebooks = keras nbmake From 0d8a028fa8f3ad7745ca884d65727185b3f5b534 Mon Sep 17 00:00:00 2001 From: Laura Ootes Date: Mon, 17 Jun 2024 15:50:34 +0200 Subject: [PATCH 15/16] undo watchdog --- setup.cfg | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 39e9e5ae..596ba029 100644 --- a/setup.cfg +++ b/setup.cfg @@ -95,7 +95,6 @@ dashboard = spacy streamlit torchtext - watchdog notebooks = keras nbmake From 82c002874fd2dbab48d6a22047a47e3433bcbda7 Mon Sep 17 00:00:00 2001 From: Laura Ootes Date: Tue, 18 Jun 2024 09:56:57 +0200 Subject: [PATCH 16/16] delete outcommented code --- dianna/dashboard/_models_image.py | 1 - 1 file changed, 1 deletion(-) diff --git a/dianna/dashboard/_models_image.py b/dianna/dashboard/_models_image.py index 28c7e72d..a3650e58 100644 --- a/dianna/dashboard/_models_image.py +++ b/dianna/dashboard/_models_image.py @@ -45,7 +45,6 @@ def _run_kernelshap_image(model, image, i, **kwargs): image, method='KernelSHAP', **kwargs) - #return fill_segmentation(relevances[i][0], segments_slic) return relevances[0]