更改预训练模型的批次大小

时间:2020-01-21 20:12:55

标签: python tensorflow tensorflow2.0 deeplab

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

代码:

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。是否有更改想法?

0 个答案:

没有答案
相关问题