如何解决此错误InvalidArgumentError:已同时获取并提取了serial_6_input:0

时间:2019-07-24 04:49:48

标签: python tensorflow machine-learning keras deep-learning

我已经开始研究Keras,我的水平很基本,我在代码中收到无效的参数错误,正在使用Keras加载权重并进行一些预测。我尝试使用Keras进行更新是因为我认为这是Keras版本的问题,但这不是因为Keras版本问题出现在以前的版本中,而该版本的版本已经相当枯竭。然后我尝试更新TensorFlow和其他库,因为从教程中我知道可能会出现这些问题。我找到了此链接https://github.com/raghakot/keras-vis/pull/120/files/74f2d086feb9556cbb2f1cfd90d6d4f8c21f520d,但没有从该链接中学到如何解决此错误。我希望您能帮助我解决这个无效的参数错误,到目前为止我还没有任何信息。 如果可以的话,请帮助我,因为我确实需要这样做,所以我被困在这里。

img_width, img_height=300,300
# predicting images
img = image.load_img('omnglot.jpg', target_size=(img_width, img_height))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)

images = np.vstack([x])
print(images)
classes = model.predict_classes(images, batch_size=32)
#print(classes)

# predicting multiple images at once
img = image.load_img('omnglot2.jpg', target_size=(img_width, img_height))
y = image.img_to_array(img)
y = np.expand_dims(y, axis=0)

# pass the list of multiple images np.vstack()
images = np.vstack([x, y])
classes = model.predict_classes(images, batch_size=32)

# print the classes, the images belong to
print(classes)
print(classes[0])
print(classes[0][0])

InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-10-4fda4804f4b7> in <module>
      7 images = np.vstack([x])
      8 print(images)
----> 9 classes = model.predict_classes(images, batch_size=32)
     10 #print(classes)
     11 

C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\sequential.py in predict_classes(self, x, batch_size, verbose)
    265             A numpy array of class predictions.
    266         """
--> 267         proba = self.predict(x, batch_size=batch_size, verbose=verbose)
    268         if proba.shape[-1] > 1:
    269             return proba.argmax(axis=-1)

C:\ProgramData\Anaconda3\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:\ProgramData\Anaconda3\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:\ProgramData\Anaconda3\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:\ProgramData\Anaconda3\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:\ProgramData\Anaconda3\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:\ProgramData\Anaconda3\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:\ProgramData\Anaconda3\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:\ProgramData\Anaconda3\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: sequential_6_input:0 is both fed and fetched.

0 个答案:

没有答案