首页 > 解决方案 > 调用 keras 模型 train_on_batch 时,“张量必须来自与张量相同的图”

问题描述

gen_examples = self.generator.predict([xmal_batch, noise])

生成器是一个 keras 模型,它向原始数据添加噪声并生成新示例

with tf.Session() as sess:         
    sess.run(tf.global_variables_initializer())
    sess.run(tf.local_variables_initializer())

    saver.restore(sess, PATH)
    print ("load model from:", PATH)

    ymal_batch = sess.run(model.y_pred, feed_dict = {model.x_input: gen_examples})

    self.substitute_detector.train_on_batch(gen_examples, ymal_batch)

ValueError: Tensor("training/Adam/Const:0", shape=(), dtype=int64) 必须与 Tensor("Adam/iterations:0", shape=(), dtype=resource) 来自同一个图。

我是 Tensorflow 的新手,我不知道为什么会出现这个错误,因为gen_examples并且ymal_batch基本上是 numpy 数组。

似乎创建了新图表,但我很困惑。

标签: pythontensorflow

解决方案


推荐阅读