tf.saved_model报错iterating over `tf.Tensor` is not allowed in Graph execution.

今天又是在保存模型时报错,结合最近的错误,我发现在梯度计算过程中是没有问题的,但是在保存模型时就会因为模型中不符合tf2要求的地方报错。

这次的错误是iterating over tf.Tensor is not allowed in Graph execution.
非常容易理解,就是迭代了一个tensor,我查看代码发现确实这样:

#输入的inputs是一个tensor类型变量
for input in inputs:
	....
	....

我之所以这么做,是因为当时我搭建的是一个CNN网络,每次只处理了一张图片,即输入维度是1heightweight*channel的shape,这就导致我需要遍历输入数据。

这个也是因为我第一次自己用tf2写CNN,没有太多经验,之后我改成了批量输入CNN,batchheightweight*channel,批量进行处理,就不需要迭代了

你可能感兴趣的:(tensorflow,tensorflow,python,深度学习)