Skip to content
Draft
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jobs:
architecture:
- x64
python-version:
- '3.8'
- '3.11'
- '3.9'
- '3.12'
defaults:
run:
shell: bash
Expand Down
12 changes: 6 additions & 6 deletions examples/sentiment_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,9 @@
" return \"very_positive\"\n",
"\n",
"\n",
"df_reviews_with_sentiment_value[\n",
" \"label\"\n",
"] = df_reviews_with_sentiment_value.sentiment_value.apply(sentiment_discretizer)"
"df_reviews_with_sentiment_value[\"label\"] = (\n",
" df_reviews_with_sentiment_value.sentiment_value.apply(sentiment_discretizer)\n",
")"
]
},
{
Expand Down Expand Up @@ -740,9 +740,9 @@
"df_reviews_with_sentiment_value_filtered = df_reviews_with_sentiment_value.loc[\n",
" filtered_indices\n",
"].copy()\n",
"df_reviews_with_sentiment_value_filtered.loc[\n",
" :, \"label_idx\"\n",
"] = df_reviews_with_sentiment_value_filtered.label.apply(lambda l: LABEL_MAPPING[l])\n",
"df_reviews_with_sentiment_value_filtered.loc[:, \"label_idx\"] = (\n",
" df_reviews_with_sentiment_value_filtered.label.apply(lambda l: LABEL_MAPPING[l])\n",
")\n",
"\n",
"df_reviews_with_sentiment_value_filtered[:5]"
]
Expand Down
50 changes: 27 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,38 @@ documentation = "https://innvestigate.readthedocs.io/en/latest/"
keywords = ["XAI", "LRP", "Deep Taylor",]

[tool.poetry.dependencies]
python = ">=3.9, <3.12"
tensorflow = ">=2.6, <2.15"
numpy = ">=1.22, <2"
matplotlib = ">=3.5, <4"
future = ">=0.18, <0.19"
python = ">=3.9"
tensorflow = ">=2.6"
numpy = ">=1.22"
matplotlib = ">=3.5"
future = ">=0.18"

[tool.poetry.group.notebooks.dependencies]
ipykernel = ">=6.19, <7"
Pillow = ">=9.0, <11"
ftfy = ">=6.1, <7"
pandas = ">=1, <3"
ipykernel = ">=6.19"
Pillow = ">=9.0"
ftfy = ">=6.1"
pandas = ">=1"

[tool.poetry.group.docs.dependencies]
Sphinx = ">=6.1, <8"
Sphinx = ">=6.1"

[tool.poetry.group.tests.dependencies]
pytest = ">=7.2, <8"
pytest-cov = ">=4.0, <5"
coverage = {extras = ["toml"], version = ">=7, <8"}
codecov = ">=2.1, <3"
pytest = ">=7.2"
pytest-cov = ">=4.0"
coverage = {extras = ["toml"], version = ">=7"}
codecov = ">=2.1"
tox = "^4"

[tool.poetry.group.dev.dependencies]
black = ">=22.3, <24"
ruff = ">=0.0.264, <0.1"
rope = ">=1.6, <2"
pylint = ">=3, <4"
isort = ">=5.10, <6"
mypy = ">=1, <2"
vulture = ">=2.3, <3"
pyupgrade = ">=3.3, <4"
pre-commit = ">=2.19, <4"
black = ">=25"
ruff = ">=0.0.264"
rope = ">=1.6"
pylint = ">=3"
isort = ">=5.10"
mypy = ">=1"
vulture = ">=2.3"
pyupgrade = ">=3.3"
pre-commit = ">=2.19"

[tool.isort]
profile = "black"
Expand All @@ -74,6 +75,9 @@ known_first_party = "innvestigate"
known_local_folder = "tests"

[tool.pytest.ini_options]
pythonpath = [
"src"
]
addopts = "-v -m fast --strict-markers --cov"
# NOTE: locally run tests with `poetry run pytest -m precommit` before a commit
markers = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@
klayers.SpatialDropout1D,
klayers.SpatialDropout2D,
klayers.SpatialDropout3D,
klayers.LocallyConnected1D,
klayers.LocallyConnected2D,
klayers.Add,
klayers.Concatenate,
klayers.Dot,
Expand Down
2 changes: 0 additions & 2 deletions src/innvestigate/backend/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ def is_dense_layer(layer: Layer, *_args, **_kwargs) -> bool:
klayers.SpatialDropout2D,
klayers.SpatialDropout3D,
klayers.Embedding,
klayers.LocallyConnected1D,
klayers.LocallyConnected2D,
klayers.Add,
klayers.Average,
klayers.Concatenate,
Expand Down
6 changes: 3 additions & 3 deletions src/innvestigate/backend/graph.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Low-level operations on Keras graph."""

from __future__ import annotations

import inspect
Expand Down Expand Up @@ -869,7 +870,7 @@ def get_model_execution_graph(


def print_model_execution_graph(
graph: dict[int | None, OptionalList[NodeDict]]
graph: dict[int | None, OptionalList[NodeDict]],
) -> None:
"""Pretty print of a model execution graph."""
# TODO: check types
Expand Down Expand Up @@ -1004,8 +1005,7 @@ def reverse_model(
return_all_reversed_tensors: bool = False,
clip_all_reversed_tensors: bool | tuple[float, float] = False,
project_bottleneck_tensors: bool | tuple[float, float] = False,
execution_trace: None
| (
execution_trace: None | (
tuple[list[Layer], list[tuple[Layer, list[Tensor], list[Tensor]]], list[Tensor]]
) = None,
reapply_on_copied_layers: bool = False,
Expand Down
6 changes: 3 additions & 3 deletions src/innvestigate/tools/perturbate.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ def _perturbate_regions(self, x, perturbation_mask_regions):
if region_mask:
for c in range(n_channels):
region = xp[sample_idx, c, region_row, :, region_col, :]
xp[
sample_idx, c, region_row, :, region_col, :
] = self.perturbation_function(region)
xp[sample_idx, c, region_row, :, region_col, :] = (
self.perturbation_function(region)
)

if self.value_range is not None:
np.clip(xp, self.value_range[0], self.value_range[1], xp)
Expand Down
1 change: 1 addition & 0 deletions tests/_monkeytype.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Automated type annotations __absolutely__ need to be checked using mypy
as well as formated using black and isort before commiting.
"""

import pytest

pytest.main()
1 change: 1 addition & 0 deletions tests/analyzer/test_init.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test function 'innvestigate.create_analyzer'"""

from __future__ import annotations

import logging
Expand Down
1 change: 1 addition & 0 deletions tests/analyzer/test_reference_layer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test all LRP Analyzers over single layer models using random weights and random input.
"""

import os

import h5py
Expand Down
1 change: 1 addition & 0 deletions tests/analyzer/test_reference_vgg16.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Test all LRP Analyzers on VGG16.
"""

# NOTE:
# For VGG16 reference tests to work, clone the repo
# https://github.com/adrhill/test-data-innvestigate
Expand Down
1 change: 1 addition & 0 deletions tests/backend/test_model_wo_softmax.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test function 'innvestigate.create_analyzer'"""

from __future__ import annotations

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/dryrun.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Dryrun analyzers to catch crashes."""

from __future__ import annotations

from typing import Callable
Expand Down
1 change: 1 addition & 0 deletions tests/networks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Iterate over test networks specified by filter string."""

from __future__ import annotations

import fnmatch
Expand Down
1 change: 1 addition & 0 deletions tests/networks/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Predefined network architectures for testing."""

from __future__ import annotations

import tensorflow.keras.layers as klayers
Expand Down
1 change: 1 addition & 0 deletions tests/networks/imagenet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Load networks from Keras applications for dryrunning.
By default, weights are just randomly initialized.
"""

from __future__ import annotations

import tensorflow.keras.applications as kapps
Expand Down
1 change: 1 addition & 0 deletions tests/networks/mnist.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Apply network architectures defined in base.py using MNIST input shape,
512 units per dense layer and a dropout rate of 0.25.
"""

from __future__ import annotations

import tensorflow.keras.backend as kbackend
Expand Down
1 change: 1 addition & 0 deletions tests/networks/trivia.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Simple model architectures for fast testing of analyzers."""

from __future__ import annotations

import tensorflow.keras.layers as klayers
Expand Down
8 changes: 4 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
isolated_build = true
envlist = py{38, 310}, format, lint, docs
envlist = py{39, 312}, format, lint, docs

[testenv]
description = "Run unit tests"
Expand All @@ -12,7 +12,7 @@ commands =

[testenv:format]
description = "Check formatting"
basepython = python3.10
basepython = python3.12
deps =
isort
black
Expand All @@ -22,7 +22,7 @@ commands =

[testenv:lint]
description = "Check linting"
basepython = python3.10
basepython = python3.12
ignore_outcome = true
deps =
ruff
Expand All @@ -33,7 +33,7 @@ commands =

[testenv:docs]
description = "Test doc build"
basepython = python3.10
basepython = python3.12
deps =
sphinx
commands =
Expand Down
Loading