raghakot / keras-vis

Neural network visualization toolkit for keras
https://raghakot.github.io/keras-vis
MIT License
2.98k stars 660 forks source link

InvalidArgumentError when trying to evaluate batch of images with visualise_cam #176

Closed GeneKitamura closed 5 years ago

GeneKitamura commented 5 years ago

So I'm having issues with using the visualize_cam method. So I built my model using Keras as below:

base_model = keras.applications.densenet.DenseNet201(include_top=False, input_shape=(224, 224, 3), pooling='avg', weights='imagenet')
x = base_model.output
x = keras.layers.Dense(2, activation='softmax')(x)
model = Model(inputs=base_model.input, outputs=x)

model.input_shape is (None, 224, 224, 3) and model.output_shape is (None, 2)

Then I have a image_array loaded in memory of shape (10, 224, 224, 3).

When I go to create the heat_map by the method:

visualization.visualize_cam(model, layer_idx=708, filter_indices=[1], seed_input=image_array)

I get the following error:

InvalidArgumentError: input depth must be evenly divisible by filter depth: 224 vs 3

Interestingly, I CAN evaluate one image at a time, but I was hoping you can help me with using the method on a batch of images. Python 3.5.2, Keras 2.2.4, keras-vis 0.4.1, tensorflow 1.12.0.