python - 更改预训练模型的批量大小
问题描述
我正在尝试从这里加载模型以便对图像进行推断。关键是我想一次预测多个图像,但是当我尝试它时,我收到以下错误:
代码:
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。关于如何更改它的任何想法?
解决方案
推荐阅读
- java - 如何在带有 Maven 的 OSGi 应用程序中使用 MySQL?
- datagrip - 为什么 Data Grip 一直连接到数据库?
- eclipse - Eclipse在内容辅助变量初始化时添加@NotNull注解
- grails - Grails 3 / GORM 从结果中剔除单个记录
- java - Maven Central 和 JCenter 是否容易被域名抢注?
- computer-science - 记录状态机——来自状态或转换?
- python - 为什么 glob 会从此文件目录返回一个空列表?
- ios - UIView layoutConstraint 奇怪的行为,粘在上面
- c# - 反序列化 bool 时丢失数据
- vb.net - 如何计算平均值?