Skip to content

Commit

Permalink
Format code with black 23
Browse files Browse the repository at this point in the history
  • Loading branch information
adrhill committed May 5, 2023
1 parent f9627fc commit 49d6f6b
Show file tree
Hide file tree
Showing 10 changed files with 1 addition and 20 deletions.
2 changes: 0 additions & 2 deletions examples/introduction_development.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,6 @@
" return ibackend.gradients(Xs, Ys, reversed_Ys)\n",
"\n",
" def _create_analysis(self, *args, **kwargs):\n",
"\n",
" self._add_conditional_reverse_mapping(\n",
" # Apply to all layers that contain a relu activation\n",
" lambda layer: kchecks.contains_activation(layer, \"relu\"),\n",
Expand Down Expand Up @@ -706,7 +705,6 @@
" return X\n",
"\n",
" def _create_analysis(self, *args, **kwargs):\n",
"\n",
" self._add_conditional_reverse_mapping(\n",
" # Apply to all layers that contain a kernel\n",
" lambda layer: kchecks.contains_kernel(layer),\n",
Expand Down
1 change: 1 addition & 0 deletions examples/mnist_perturbation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
"steps = 15\n",
"regions_per_step = 1 # Perturbate 1 region per step\n",
"\n",
"\n",
"# Scale to [0, 1] range for plotting.\n",
"def input_postprocessing(X):\n",
" return revert_preprocessing(X) / 255\n",
Expand Down
4 changes: 0 additions & 4 deletions examples/sentiment_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,6 @@
"\n",
"\n",
"def train_model(model, batch_size=128, epochs=20):\n",
"\n",
" x_train = DATASETS[\"training\"][\"x4d\"]\n",
" y_train = to_one_hot(DATASETS[\"training\"][\"y\"])\n",
"\n",
Expand Down Expand Up @@ -1088,7 +1087,6 @@
"analysis = np.zeros([len(test_sample_indices), len(analyzers), 1, MAX_SEQ_LENGTH])\n",
"\n",
"for i, ridx in enumerate(test_sample_indices):\n",
"\n",
" x, y = DATASETS[\"testing\"][\"x4d\"][ridx], DATASETS[\"testing\"][\"y\"][ridx]\n",
"\n",
" t_start = time.time()\n",
Expand All @@ -1100,7 +1098,6 @@
" test_sample_preds[i] = y_hat\n",
"\n",
" for aidx, analyzer in enumerate(analyzers):\n",
"\n",
" a = np.squeeze(analyzer.analyze(x))\n",
" a = np.sum(a, axis=1)\n",
"\n",
Expand Down Expand Up @@ -1478,7 +1475,6 @@
"source": [
"# Traverse over the analysis results and visualize them.\n",
"for i, idx in enumerate(test_sample_indices):\n",
"\n",
" words = [decoder[t] for t in list(DATASETS[\"testing\"][\"encoded_reviews\"][idx])]\n",
"\n",
" print(\"Review(id=%d): %s\" % (idx, \" \".join(words)))\n",
Expand Down
2 changes: 0 additions & 2 deletions src/innvestigate/analyzer/deeptaylor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def __init__(self, model: Model, *args, **kwargs) -> None:
self._do_model_checks()

def _create_analysis(self, *args: Any, **kwargs: Any):

# Kernel layers.
self._add_conditional_reverse_mapping(
lambda l: (ichecks.contains_kernel(l) and ichecks.contains_activation(l)),
Expand Down Expand Up @@ -176,7 +175,6 @@ def __init__(self, model, low=None, high=None, **kwargs):
self._bounds_high = high

def _create_analysis(self, *args, **kwargs):

low, high = self._bounds_low, self._bounds_high

class BoundedProxyRule(lrp_rules.BoundedRule):
Expand Down
4 changes: 0 additions & 4 deletions src/innvestigate/analyzer/gradient_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ class InputTimesGradient(Gradient):
"""

def __init__(self, model, **kwargs):

super().__init__(model, **kwargs)

def _create_analysis(self, model, stop_analysis_at_tensors=None):
Expand Down Expand Up @@ -207,7 +206,6 @@ def __init__(self, model, **kwargs):
self._do_model_checks()

def _create_analysis(self, *args, **kwargs):

self._add_conditional_reverse_mapping(
lambda layer: ichecks.contains_activation(layer, "relu"),
DeconvnetReverseReLULayer,
Expand Down Expand Up @@ -247,7 +245,6 @@ def __init__(self, model, **kwargs):
self._do_model_checks()

def _create_analysis(self, *args, **kwargs):

self._add_conditional_reverse_mapping(
lambda layer: ichecks.contains_activation(layer, "relu"),
guided_backprop_reverse_relu_layer,
Expand Down Expand Up @@ -321,7 +318,6 @@ def __init__(
subanalyzer = kwargs.pop("subanalyzer")
# If initialized normally:
else:

subanalyzer = Gradient(
model,
neuron_selection_mode=neuron_selection_mode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def apply(
Rs: list[Tensor],
_reverse_state,
) -> list[Tensor]:

# Get activations.
Zs = ibackend.apply(self._layer_wo_act, Xs)
# Divide incoming relevance by the activations.
Expand Down
2 changes: 0 additions & 2 deletions src/innvestigate/analyzer/reverse_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ def _reverse_model(
def _create_analysis(
self, model: Model, stop_analysis_at_tensors: list[Tensor] = None
):

if stop_analysis_at_tensors is None:
stop_analysis_at_tensors = []

Expand Down Expand Up @@ -320,7 +319,6 @@ def _create_analysis(
return ret

def _handle_debug_output(self, debug_values):

if self._reverse_check_min_max_values:
indices = self._debug_tensors_indices["min"]
tmp = debug_values[indices[0] : indices[1]]
Expand Down
1 change: 0 additions & 1 deletion src/innvestigate/analyzer/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def __init__(
neuron_selection_mode="max_activation",
**kwargs,
):

if neuron_selection_mode == "max_activation":
# TODO: find a more transparent way.
#
Expand Down
2 changes: 0 additions & 2 deletions src/innvestigate/backend/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ def actual_mapping(
reversed_Ys: list[Tensor],
reverse_state,
):

X2s = ibackend.apply(surrogate_layer1, Xs)
# Apply first mapping
# TODO (alber): update reverse state
Expand Down Expand Up @@ -788,7 +787,6 @@ def get_model_execution_trace(

model_execution_trace = []
for nid, l, Xs, Ys in id_execution_trace:

if isinstance(l, klayers.InputLayer):
# The nids that created or receive the tensors.
Xs_nids = [] # Input layer does not receive.
Expand Down
2 changes: 0 additions & 2 deletions tests/backend/test_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def test_reducemean_layer():
@pytest.mark.fast
@pytest.mark.precommit
def test_fast_one_layer():

model = kmodels.Sequential([klayers.Dense(2, input_shape=(3,), use_bias=False)])
weights = [np.asarray(((1, 2), (3, 4), (5, 6)))]
model.set_weights(weights)
Expand All @@ -90,7 +89,6 @@ def test_fast_one_layer():
@pytest.mark.fast
@pytest.mark.precommit
def test_fast_two_layers():

model = kmodels.Sequential(
[
klayers.Dense(2, input_shape=(3,), use_bias=False),
Expand Down

0 comments on commit 49d6f6b

Please sign in to comment.