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

Scipy.ndimage.interpolation raises exception on rotate in utils.input_modifiers #58

Open
fabianostermann opened this issue Jun 1, 2021 · 4 comments · Fixed by #59
Open
Labels
bug Something isn't working

Comments

@fabianostermann
Copy link

Hi there, thank you for this great library!

I've stepped over a problem on trying to "Visualizing Dense layer using ActivationMaximization" as in your perfect example.

I updated everything and the example worked as expected. When I run with my own fully dense model I get following error (model summary in front, exact same for the other example with conv!):

Model: "sequential_4"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
flatten_4 (Flatten)          (None, 128000)            0         
_________________________________________________________________
dense_16 (Dense)             (None, 256)               32768256  
_________________________________________________________________
dropout_12 (Dropout)         (None, 256)               0         
_________________________________________________________________
dense_17 (Dense)             (None, 128)               32896     
_________________________________________________________________
dropout_13 (Dropout)         (None, 128)               0         
_________________________________________________________________
dense_18 (Dense)             (None, 64)                8256      
_________________________________________________________________
dropout_14 (Dropout)         (None, 64)                0         
_________________________________________________________________
dense_19 (Dense)             (None, 2)                 130       
=================================================================
Total params: 32,809,538
Trainable params: 32,809,538
Non-trainable params: 0
_________________________________________________________________
Traceback (most recent call last):
  File "explain_dense.py", line 47, in <module>
    activations = activation_maximization(score, steps=256, callbacks=[PrintLogger(interval=50)])
  File "/home/oyster/.local/lib/python3.8/site-packages/tf_keras_vis/activation_maximization/__init__.py", line 111, in __call__
    seed_inputs[j] = modifier(seed_inputs[j])
  File "/home/oyster/.local/lib/python3.8/site-packages/tf_keras_vis/utils/input_modifiers.py", line 56, in __call__
    seed_input = rotate(seed_input,
  File "/home/oyster/.local/lib/python3.8/site-packages/scipy/ndimage/interpolation.py", line 686, in rotate
    raise ValueError('axes should contain exactly two values')
ValueError: axes should contain exactly two values

I debugged through the code but couldn't find any clues yet and would like to help to find out if this is a bug or a setup problem.
Is anything similar known? Any suggestions where to look?

Thanks!

@keisen keisen added the bug Something isn't working label Jun 2, 2021
@keisen
Copy link
Owner

keisen commented Jun 2, 2021

@oystersandwich , Thank you for your reporting the error!

You can avoid this error by modifying input_modifiers and regularizers options like below:

from tf_keras_vis.utils.regularizers import Norm

activations = activation_maximization(score,
                                      steps=256,
                                      input_modifiers=[],
                                      regularizers=[Norm(10.)],
                                      callbacks=[PrintLogger(interval=50)])

(EDITED: Remove Jitter and Add L2Norm.)

The cause of this problem is that tf_keras_vis.utils.input_modifiers.Rotate can't support N-dim inputs.
We will rename Rotate to Rotate2D and improve them to get the proper error.

Thanks!

@fabianostermann
Copy link
Author

@keisen , thanks very much for your quick reply!

Cannot say I already fully understand your solution, but I can report the former one with jitter is working:

from tf_keras_vis.utils.input_modifiers import Jitter
activations = activation_maximization(score_function,
                                      steps=256,
                                      input_modifiers=[Jitter(jitter=8)],
                                      callbacks=[PrintLogger(interval=5)])

However, the edited one with tf_keras_vis.utils.regularizers import Norm does not work..?

@keisen
Copy link
Owner

keisen commented Jun 2, 2021

Thank you for letting me know that.

Cannot say I already fully understand your solution, but I can report the former one with jitter is working:
However, the edited one with tf_keras_vis.utils.regularizers import Norm does not work..?

I may not understand your situation enough, or my test environment may have any problem.
In any case, there is no problem if your work is well !

@keisen
Copy link
Owner

keisen commented Jun 3, 2021

However, the edited one with tf_keras_vis.utils.regularizers import Norm does not work..?

I looked into this error, but I didn't find the cause of it.
So, if you could, please submit the message and stack trace of the error.

Thanks!

@keisen keisen closed this as completed in #59 Jun 3, 2021
keisen added a commit that referenced this issue Jun 3, 2021
@keisen keisen reopened this Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants