Python 更改预训练模型的批量大小

Python 更改预训练模型的批量大小,python,tensorflow,tensorflow2.0,deeplab,Python,Tensorflow,Tensorflow2.0,Deeplab,我试图从中加载模型,以便对图像进行推断。重点是我想一次预测多个图像,但当我尝试时,我得到以下错误: 代码: 错误: --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <timed exec> in <module> ~/

我试图从中加载模型,以便对图像进行推断。重点是我想一次预测多个图像,但当我尝试时,我得到以下错误:

代码:

错误:

---------------------------------------------------------------------------
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.
---------------------------------------------------------------------------
ValueError回溯(最近一次调用上次)
在里面
~/miniconda3/envs/tex/lib/python3.7/site-packages/tensorflow\u core/python/eager/function.py在调用中(self,*args,**kwargs)
1079 TypeError:用于无效的位置/关键字参数组合。
1080     """
->1081返回自我。调用impl(args,kwargs)
1082
1083 def_call_impl(self、args、kwargs、cancellation_manager=None):
~/miniconda3/envs/tex/lib/python3.7/site-packages/tensorflow\u core/python/eager/function.py in\u call\u impl(self、args、kwargs、cancellation\u manager)
1119 raise TypeError(“关键字参数{}未知。应为{}.”格式(
1120列表(kwargs.keys()),列表(self.\u arg\u关键字)))
->1121返回self.\u调用\u平面(参数、self.captured\u输入、取消\u管理器)
1122
1123 def_filtered_调用(self、args、kwargs):
~/miniconda3/envs/tex/lib/python3.7/site-packages/tensorflow\u core/python/eager/function.py在调用平面中(self、args、捕获的输入、取消管理器)
1208 arg_名称,arg,
1209 self.\u func\u graph.inputs[i].形状,
->1210参数形状)
1211 elif(自我)签名不是无和
1212 isinstance(自我签名[i],张量规范张量规范):
ValueError:参数“ImageTensor”(值张量(“Const_3:0”,shape=(2342513,3),dtype=uint8))与跟踪此函数的形状不兼容。应为形状(1,无,无,3),但得到形状(2342513,3)。
如果调用get_concrete_函数,则可能需要传递一个tf.TensorSpec(…,shape=…)和一个不太具体的形状,在轴上没有任何形状可以变化。

这表明模型的固定批量大小为1。您知道如何更改吗?

我认为您对错误原因的解释不正确。据我所知,批量大小与优化器有关,而不是与模型有关。您可以传递要建模的任何批量大小。fit@MikeFurlender,我不想适合这个型号,因为它太贵了他已经预先训练过了,我想用不同于1的批次进行推断。你能给我们看一下预测代码吗?@sebastian sz我来编辑这个问题
---------------------------------------------------------------------------
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.