Closed NotaCS closed 4 years ago
Hi,
I'm quite new to the DL world, so I might be doing idiotic things... If so, my apologies.
I'm trying to predict a continuous variable with a simple MLP by feeding it some 2D square matrices. Then, I'm using visualize_activation on the trained model to see what cells of the matrix increase or decrease the regression result. Each cell is more or less independent from its neighbors. So far so good.
When I use the full 2D matrices (with a flattening layer after the input layer), keras-vis gives me a sharp-looking matrix (no blur), which is great:
(I masked the upper triangle here, but the matrix given by visualize_activation is full)
But such full matrices contain redundant information, so I usually remove the selected useless cells (the upper triangle of the matrix) and flatten the result before feeding them to the MLP. So now, visualize_activation is supposed to give me a 1D vector, that I then reconstruct into the lower matrix triangle. But here is the result:
As you can see, the values have been smoothed along the flattened dimension, resulting in the horizontal streaks on the matrix. This looks like the is a 1D conv layer used somewhere, which is not the case...
I also tried to reshape the flattened triangular matrices into a 2D rectangle then train the MLP with these 2D images (so basically: matrix -> remove upper triangle and flatten -> reshape into a 2D image), but again, I obtain a smoothed image (this time in 2D) with visualize_activation! Why would it be different from when I use the 2D square matrices?
It's really strange and my stem from the fact that keras-vis is designed to work with images (and not matrices). But still, why would it work well when I use the full matrices?
Thank you in advance!
That's cool!
How did you generate the smoothed image? If you use matplotlib's imshow
with setting color-map, you need to remove cmap
option from imshow
.
If not, I recommend you that you try to some tweaking such as below:
input_range
argument of visualize_activation. In default, the argument value is 0 to 255 but your model's input-data seems to be -1 to 1.seed_input
argument to visualize_activation. In default, the random value's standard deviation (std) is 0.05 * input-value-range, and if your data's range is -1 to 1, the std is 0.1. It may be too low value.Despite you try all above If you could not get the result you want, let me know.
Hi,
Thanks for your answer. I actually also contacted you on Slack when I posted the question here and you've already perfectly solved my problem ^^
Here is a screenshot of the discussion's resolution, if other people happen to have the same problem:
Thanks again and have a nice day !
Ah! Sorry for forgetting it 💦 Thank you for reminding me. We'll close this issue, but please feel free to reopen this issue whenever you need. Thanks!
[ ] Check that you are up-to-date with the master branch of keras-vis. You can update with: pip install git+git://github.com/raghakot/keras-vis.git --upgrade --no-deps
[ ] If running on TensorFlow, check that you are up-to-date with the latest version. The installation instructions can be found here.
[ ] If running on Theano, check that you are up-to-date with the master branch of Theano. You can update with: pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps
[ ] Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).