Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update backend #263

Merged
merged 20 commits into from
Jul 9, 2021
Merged

Update backend #263

merged 20 commits into from
Jul 9, 2021

Conversation

adrhill
Copy link
Collaborator

@adrhill adrhill commented Jul 6, 2021

Updates the backend in preparation for the switch to TF2.0.
I tried to not touch innvestigate/analyzers to keep this commit a bit more concise. Further type annotations and fixes will follow as soon as this is merged.

Changes

Type annotations

Adds type annotations to the backend, making refactoring a whole lot easier going forward. Static type checking can be run by calling

poetry run mypy

In the future, this should be included as part of CI.

Bug fixes

  • fixed contains_activation and added tests
  • updated DeepTaylor to match changes
  • refactored reverse_model
  • removed several import hacks
  • added NotImplementedError to is_layer_at_idx. (I'll open an issue on this topic.)

Dead code removal

  • removed several unused functions, listed in e72d5c5
  • commented out unreachable code

Linting fixes

Updated lots of small things to appease pylint and flake8, mostly updating variable names with more meaningful ones and untangling if-else-statements.

adrhill added 17 commits July 6, 2021 18:29
and clean up imports.

Types are grouped in `/utils/types.py` for convenience.
Checked "dead-ness" using vulture, code search and pytest.

From layers.py:
* Constant
* Zero
* One
* ZerosLike
* Greater
* Less
* LessThanZero
* GreaterEqual
* LessEqual
* GreaterEqualThanZero
* Print

From graph.py:
* get_layer_outbound_count

From checks.py:
* get_current_layers
* get_known_layers
* is_relu_convnet_layer
and an import in the middle of the file.
reduces type complexity and fixes possible bug with `iK.gradients`.
Adds: 
* type hints
* assert that `clip_all_reversed_tensors` really is either False or tuple of min/max values.
* remove the dynamic attribute removing and checking from `reversed_tensors`, enabling us to... 
* turn `reversed_tensors` into a fixed TypedDict, allowing type checking
first or-statement would return true if layer contains any activation.
@codecov-commenter
Copy link

codecov-commenter commented Jul 9, 2021

Codecov Report

Merging #263 (e619003) into master (c6ce893) will increase coverage by 1.19%.
The diff coverage is 79.84%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #263      +/-   ##
==========================================
+ Coverage   71.36%   72.55%   +1.19%     
==========================================
  Files          41       43       +2     
  Lines        4173     4129      -44     
  Branches      637      614      -23     
==========================================
+ Hits         2978     2996      +18     
+ Misses       1007      948      -59     
+ Partials      188      185       -3     
Impacted Files Coverage Δ
src/innvestigate/analyzer/deeptaylor.py 89.36% <ø> (-6.39%) ⬇️
src/innvestigate/applications/mnist.py 0.00% <0.00%> (ø)
src/innvestigate/applications/imagenet.py 37.83% <40.00%> (ø)
src/innvestigate/utils/keras/backend.py 65.38% <62.50%> (+30.29%) ⬆️
src/innvestigate/utils/keras/checks.py 78.31% <70.17%> (+1.71%) ⬆️
src/innvestigate/utils/keras/graph.py 56.44% <73.39%> (+0.41%) ⬆️
src/innvestigate/tools/perturbate.py 62.98% <76.92%> (ø)
src/innvestigate/tools/pattern.py 79.43% <83.33%> (+1.91%) ⬆️
src/innvestigate/layers.py 82.79% <89.10%> (+4.40%) ⬆️
src/innvestigate/utils/types.py 100.00% <100.00%> (ø)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c6ce893...e619003. Read the comment docs.

@albermax albermax merged commit 32ead9d into albermax:master Jul 9, 2021
@adrhill adrhill deleted the adrhill/update-backend branch July 22, 2021 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants