0

我正在尝试从这里加载模型以便对图像进行推断。关键是我想一次预测多个图像,但是当我尝试它时,我收到以下错误:

代码:

tensor = tf.convert_to_tensor(np.array([np.asarray(resized_image)]))
tensor2 = tf.convert_to_tensor(np.array([np.asarray(resized_image), np.asarray(resized_image)]))

test = model_new.signatures['serving_default'](tensor)
test2 = model_new.signatures['serving_default'](tensor2) 

错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<timed exec> in <module>

~/miniconda3/envs/tex/lib/python3.7/site-packages/tensorflow_core/python/eager/function.py in __call__(self, *args, **kwargs)
   1079       TypeError: For invalid positional/keyword argument combinations.
   1080     """
-> 1081     return self._call_impl(args, kwargs)
   1082 
   1083   def _call_impl(self, args, kwargs, cancellation_manager=None):

~/miniconda3/envs/tex/lib/python3.7/site-packages/tensorflow_core/python/eager/function.py in _call_impl(self, args, kwargs, cancellation_manager)
   1119       raise TypeError("Keyword arguments {} unknown. Expected {}.".format(
   1120           list(kwargs.keys()), list(self._arg_keywords)))
-> 1121     return self._call_flat(args, self.captured_inputs, cancellation_manager)
   1122 
   1123   def _filtered_call(self, args, kwargs):

~/miniconda3/envs/tex/lib/python3.7/site-packages/tensorflow_core/python/eager/function.py in _call_flat(self, args, captured_inputs, cancellation_manager)
   1208                      arg_name, arg,
   1209                      self._func_graph.inputs[i].shape,
-> 1210                      arg.shape))
   1211       elif (self._signature is not None and
   1212             isinstance(self._signature[i], tensor_spec.TensorSpec)):

ValueError: The argument 'ImageTensor' (value Tensor("Const_3:0", shape=(2, 342, 513, 3), dtype=uint8)) is not compatible with the shape this function was traced with. Expected shape (1, None, None, 3), but got shape (2, 342, 513, 3).

If you called get_concrete_function, you may need to pass a tf.TensorSpec(..., shape=...) with a less specific shape, having None on axes which can vary.

这表明该模型的固定批量大小为 1。关于如何更改它的任何想法?

4

0 回答 0