Closed Guoyinzh closed 6 years ago
Hi, @Guoyinzh
You should also write the results of below.
import keras.backend as K
print(K.image_data_format()) # 'channels_first' ?
Thanks
K.image_data_format() = 'channels_last' Maybe it is because I am usinig tensorflow as backend, and it is using 'channels_last' for the default? Also, I defined the data_format='channels_first' in the Conv2D layer in my model, as follows
model = Sequential() model.add(Conv2D(input_shape=X_train[0].shape, filters=filters, kernel_size=kernel_size, strides=strides, padding='same', data_format='channels_first')
Problem solved! Just changing the data_format in Conv2D layer is not enough. I change the backend image_data_format to 'channels_first' and It works now! Thanks!
@Guoyinzh , Could you close this issue ?
[@ ] 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).
Thanks for your excellent job! I have run your examples very well. But I got some problems when running it for my model.
I trained a very small model using keras with tensorflow as backend. The input image is 'channels_first': img.shape = (1,15,20) # one channel
When I run visualize_saliency as follows, I should get: grads.shape = (15, 20) #right? But I got: grads.shape = (1,15) Keras-vis still treat the input as 'channels_last' data format. The same for visualize_cam.
Thanks for your time.
from vis.utils import utils from keras import activations from vis.visualization import visualize_saliency
model.layers[-1].activation = activations.linear model = utils.apply_modifications(model)
grads = visualize_saliency(model,-1, filter_indices=1, seed_input=img, backprop_modifier='guided')