0

I'm trying to load the model from here in order to make inferences on images. The point is I want to predict on more than one image at a time but when I try it I get the following error:

Code:

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) 

Error:

---------------------------------------------------------------------------
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.

Which indicates the model has a fixed batch size of 1. Any idea on how to change it?

0 Answers0