tensorflow报错,版本问题。高版本到低版本使用:
import tensorflow.compat.v1 as tf
tf.placeholder() is not compatible with eager execution.
2.0版本出现,加一句代码即可
tf.compat.v1.disable_eager_execution()
如何读取tensorflow训练好的模型
saver = tf.train.Saver() with tf.Session() as sess: print("从指定的路径中加载模型。。。。") # 将模型加载到sess 中 ckpt = tf.train.get_checkpoint_state(logs_train_dir) if ckpt and ckpt.model_checkpoint_path: global_step = ckpt.model_checkpoint_path.split(‘/‘)[-1].split(‘-‘)[-1] saver.restore(sess, ckpt.model_checkpoint_path)
我们是这样做的
saver = tf.train.Saver() sess.run(tf.initialize_all_variables()) checkpoint = tf.train.get_checkpoint_state("saved_networks")
#model_checkpoint_path保存了最新的tensorflow模型文件的文件名
if checkpoint and checkpoint.model_checkpoint_path:
saver.restore(sess, checkpoint.model_checkpoint_path)
print("Successfully loaded:", checkpoint.model_checkpoint_path)
else:
print("Could not find old network weights")
原文:https://www.cnblogs.com/snailbuster/p/14637165.html