raghakot / keras-vis

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

i have some problem in using visualize_cam when i load a inceptionV3 network! #85

Open zhangxiaodi opened 6 years ago

zhangxiaodi commented 6 years ago

File "/home/xy/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2209, in set_shapes_for_outputs shapes = shape_func(op)

File "/home/xy/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2159, in call_with_requiring return call_cpp_shape_fn(op, require_shape_fn=True)

File "/home/xy/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/common_shapes.py", line 627, in call_cpp_shape_fn require_shape_fn)

File "/home/xy/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/common_shapes.py", line 691, in _call_cpp_shape_fn_impl raise ValueError(err.message)

ValueError: slice index 5 of dimension 1 out of bounds. for 'strided_slice_1' (op: 'StridedSlice') with input shapes: [?,5], [2], [2], [2] and with computed input tensors: input[1] = <0 5>, input[2] = <0 6>, input[3] = <1 1>.

zhangxiaodi commented 6 years ago

i want to know how use the visualize_cam in InceptionV3? please recommend me!

4OH4 commented 6 years ago

I was able to use visualize_cam on Inception V3 by making a few modifications to the VGG example here: https://github.com/raghakot/keras-vis/blob/master/examples/vggnet/attention.ipynb

I had to define the input_shape to the network, so that the neural network layers were all of defined sizes (this is done by default in VGG, but not in Inception V3):

from keras.applications import InceptionV3 model = InceptionV3(weights='imagenet', include_top=True, input_shape=(299, 299, 3))

and then changing the image load size to (299, 299):

img1 = utils.load_img('test-a.jpg', target_size=(299, 299))