-
Notifications
You must be signed in to change notification settings - Fork 663
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
ValueError: Cannot feed value of shape (1, 3, 299, 299) for Tensor 'input_1_1:0', which has shape '(?, ?, ?, 3)' while using visualize cam #66
Comments
You might need to set the input_shape parameter when assigning InceptionV3 with the proper input shape. This is my usual setting:
Not sure whenever you have set Hope it helps |
@sakares thanks a ton! its working!!!!! I will close this issue now |
@sakares solution works indeed. But since I fine-tuned some models without specifying Assume import sys
from keras.models import Model,load_model
modelArg = sys.argv[1] #read filename from command line
oldmodel=load_model(modelArg)
model = newModel()
#Some sanity checking with assertions.
assert len(oldmodel.layers) == len(model.layers)
for idx,layer in enumerate(oldmodel.layers):
assert type(oldmodel.layers[idx]) == type(model.layers[idx])
model.layers[idx].set_weights(layer.get_weights())
#Sometimes keras will complain if the model isn't compiled already so compile at will
model.compile(optimizer=SGD(lr=0.001, momentum=0.9), loss='categorical_crossentropy')
#save it again or use it with keras-vis It takes a bit of time to transfer all the weights but orders of magnitude less than retraining the whole network. |
hey @raghakot, @sakares, I am trying to use visualize cam on my network (a fine-tuned inceptionv3)
here is my code
when i run this i am getting a weird value error:
**
ValueError Traceback (most recent call last)
in ()
/opt/conda/lib/python3.5/site-packages/vis/visualization/saliency.py in visualize_cam(model, layer_idx, filter_indices, seed_input, penultimate_layer_idx, backprop_modifier, grad_modifier)
237 (ActivationMaximization(model.layers[layer_idx], filter_indices), -1)
238 ]
--> 239 return visualize_cam_with_losses(model.input, losses, seed_input, penultimate_layer, grad_modifier)
/opt/conda/lib/python3.5/site-packages/vis/visualization/saliency.py in visualize_cam_with_losses(input_tensor, losses, seed_input, penultimate_layer, grad_modifier)
158 penultimate_output = penultimate_layer.output
159 opt = Optimizer(input_tensor, losses, wrt_tensor=penultimate_output, norm_grads=False)
--> 160 _, grads, penultimate_output_value = opt.minimize(seed_input, max_iter=1, grad_modifier=grad_modifier, verbose=False)
161
162 # For numerical stability. Very small grad values along with small penultimate_output_value can cause
/opt/conda/lib/python3.5/site-packages/vis/optimizer.py in minimize(self, seed_input, max_iter, input_modifiers, grad_modifier, callbacks, verbose)
141
142 # 0 learning phase for 'test'
--> 143 computed_values = self.compute_fn([seed_input, 0])
144 losses = computed_values[:len(self.loss_names)]
145 named_losses = zip(self.loss_names, losses)
/src/keras/backend/tensorflow_backend.py in call(self, inputs)
2266 updated = session.run(self.outputs + [self.updates_op],
2267 feed_dict=feed_dict,
-> 2268 **self.session_kwargs)
2269 return updated[:len(self.outputs)]
2270
/opt/conda/lib/python3.5/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
787 try:
788 result = self._run(None, fetches, feed_dict, options_ptr,
--> 789 run_metadata_ptr)
790 if run_metadata:
791 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
/opt/conda/lib/python3.5/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
973 'Cannot feed value of shape %r for Tensor %r, '
974 'which has shape %r'
--> 975 % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
976 if not self.graph.is_feedable(subfeed_t):
977 raise ValueError('Tensor %s may not be fed.' % subfeed_t)
ValueError: Cannot feed value of shape (1, 3, 299, 299) for Tensor 'input_1_1:0', which has shape '(?, ?, ?, 3)'
**
My model definition code is given below:
I am clueless why it is showing this value error.
The error looks like a clash between tensorflow and theano background. Idk why this is happening because I have made the keras config file to run tensorflow by default.
could you please help me sort this issue out?
Thanks in advance
**update :
1)This error doesn't come up when I load the full inceptionv3 model from keras (including the top layer as given in #65
2) same error with visualize_saliency also **
The text was updated successfully, but these errors were encountered: