Python 3.x 保存时保存tf.keras.Model断言错误:未跟踪对象
我有一个基于Python 3.x 保存时保存tf.keras.Model断言错误:未跟踪对象,python-3.x,tensorflow,keras,tensorflow2.0,Python 3.x,Tensorflow,Keras,Tensorflow2.0,我有一个基于tf.keras.model构建的模型,当我尝试使用model.save(/path/to/model)保存模型时,我得到了错误 AssertionError: Tried to export a function which references untracked object Tensor("Network/truediv_3:0", shape=(4, 3), dtype=float32).TensorFlow objects (e.g. tf.Varia
tf.keras.model
构建的模型,当我尝试使用model.save(/path/to/model)
保存模型时,我得到了错误
AssertionError: Tried to export a function which references untracked object Tensor("Network/truediv_3:0", shape=(4, 3), dtype=float32).TensorFlow objects (e.g. tf.Variable) captured by functions must be tracked by assigning them to an attribute of a tracked object or assigned to an attribute of the main object directly.
它所指的张量计算如下
def gmm(self, gamma, z):
# some code omitted
# here is the tensor:
self.mu = tf.divide(
tf.matmul(gamma, z, transpose_a=True), sums_exp_dims
)
# more code omitted
我需要将这个张量作为训练例程的类属性。我尝试“转储”参数:
def dump(self):
out = {'mu':self.mu}
self.mu = None
return out
但这导致了计算图中更多的错误。有没有办法保存模型以避免断言错误