Skip to content
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

activations = activation_model.predict(img_arr) giving error #2

Open
KVK012 opened this issue Jun 24, 2019 · 2 comments
Open

activations = activation_model.predict(img_arr) giving error #2

KVK012 opened this issue Jun 24, 2019 · 2 comments

Comments

@KVK012
Copy link

KVK012 commented Jun 24, 2019

Hello,

I am new to TF and I am using TF version 1.13.1

I am using jupyter notebook and I got stuck at following line.
activations = activation_model.predict(img_arr)

When I execute it then it is giving an error as shown below.
`InvalidArgumentError Traceback (most recent call last)
in
----> 1 activations = activation_model.predict(img_arr)

c:\users\rameshmdamor777.conda\envs\pythongpu\lib\site-packages\keras\engine\training.py in predict(self, x, batch_size, verbose, steps)
1167 batch_size=batch_size,
1168 verbose=verbose,
-> 1169 steps=steps)
1170
1171 def train_on_batch(self, x, y,

c:\users\rameshmdamor777.conda\envs\pythongpu\lib\site-packages\keras\engine\training_arrays.py in predict_loop(model, f, ins, batch_size, verbose, steps)
292 ins_batch[i] = ins_batch[i].toarray()
293
--> 294 batch_outs = f(ins_batch)
295 batch_outs = to_list(batch_outs)
296 if batch_index == 0:

c:\users\rameshmdamor777.conda\envs\pythongpu\lib\site-packages\keras\backend\tensorflow_backend.py in call(self, inputs)
2713 return self._legacy_call(inputs)
2714
-> 2715 return self._call(inputs)
2716 else:
2717 if py_any(is_tensor(x) for x in inputs):

c:\users\rameshmdamor777.conda\envs\pythongpu\lib\site-packages\keras\backend\tensorflow_backend.py in _call(self, inputs)
2669 feed_symbols,
2670 symbol_vals,
-> 2671 session)
2672 if self.run_metadata:
2673 fetched = self._callable_fn(*array_vals, run_metadata=self.run_metadata)

c:\users\rameshmdamor777.conda\envs\pythongpu\lib\site-packages\keras\backend\tensorflow_backend.py in _make_callable(self, feed_arrays, feed_symbols, symbol_vals, session)
2621 callable_opts.run_options.CopyFrom(self.run_options)
2622 # Create callable.
-> 2623 callable_fn = session._make_callable_from_options(callable_opts)
2624 # Cache parameters corresponding to the generated callable, so that
2625 # we can detect future mismatches and refresh the callable.

c:\users\rameshmdamor777.conda\envs\pythongpu\lib\site-packages\tensorflow\python\client\session.py in _make_callable_from_options(self, callable_options)
1469 """
1470 self._extend_graph()
-> 1471 return BaseSession._Callable(self, callable_options)
1472
1473

c:\users\rameshmdamor777.conda\envs\pythongpu\lib\site-packages\tensorflow\python\client\session.py in init(self, session, callable_options)
1423 with errors.raise_exception_on_not_ok_status() as status:
1424 self._handle = tf_session.TF_SessionMakeCallable(
-> 1425 session._session, options_ptr, status)
1426 finally:
1427 tf_session.TF_DeleteBuffer(options_ptr)

c:\users\rameshmdamor777.conda\envs\pythongpu\lib\site-packages\tensorflow\python\framework\errors_impl.py in exit(self, type_arg, value_arg, traceback_arg)
526 None, None,
527 compat.as_text(c_api.TF_Message(self.status.status)),
--> 528 c_api.TF_GetCode(self.status.status))
529 # Delete the underlying status object from memory otherwise it stays alive
530 # as there is a reference to status from this from the traceback due to

InvalidArgumentError: input_3:0 is both fed and fetched.
`

Can you please help me on this.

Thanks

@anktplwl91
Copy link
Owner

Hi @KVK012
I guess you are talking about line 79 here. I have made a mistake the line should be

activations = activation_model.predict(img_tensor)

I'll correct it in code. If this doesn't solve your issue, can you please tell me more details about whats the input shape of your img_tensor and if you are trying to do anything other than what I've done?

@KVK012
Copy link
Author

KVK012 commented Jun 24, 2019

Thanks for the quick response.

No, I am using "model_training.ipynb" from GitHub as it is, I kept image size 299x299 (color image).

ipynb file code portion:
P[14]:
img = image.load_img(test_image, target_size=(299, 299))
img_arr = image.img_to_array(img)
img_arr = np.expand_dims(img_arr, axis=0)
img_arr /= 255.

P[15] (I am stuck here):
activations = activation_model.predict(img_arr)

p[16]:
activations[1].shape

First, I want to see how visualization works so I have reduced epoch to 10 (steps_per_epoch=10). Just wanted to speed up the execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants