1、原始版本
import tensorflow as tf
print(tf.__version__)
1.13.1
2、安装TensorFlow2.0
pip install tensorflow==2.0.0-beta0
2.1 Cannot uninstall 'wrapt'.
解决:
pip install -U --ignore-installed wrapt enum34 simplejson netaddr
2.2 Consider using the `--user` option or check the permissions.
pip install tensorflow==2.0.0-beta0 --user
3 graphviz加载不上
用:conda install graphviz
tensorflow模型的加载和训练
saver=tf.train.Saver(max_to_keep=1)##保留最新的模型
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
ckpt = tf.train.get_checkpoint_state('E:/201904/tensorflow_base/model/')
# 这两个函数之间最大的区别是当父目录不存在的时候os.mkdir(path)不会创建,#os.makedirs(path)则会创建父目录。
if ckpt and ckpt.model_checkpoint_path:
saver.restore(sess,ckpt.model_checkpoint_path)
###
saver.save(sess,os.path.join(path,model_name))
tf.train.Saver(
['var_list=None', 'reshape=False', 'sharded=False', 'max_to_keep=5', 'keep_checkpoint_every_n_hours=10000.0', 'name=None', 'restore_sequentially=False', 'saver_def=None', 'builder=None', 'defer_build=False', 'allow_empty=False', 'write_version=2', 'pad_step_number=False', 'save_relative_paths=False', 'filename=None'],
)
官方例子:
saver = tf.train.Saver(...variables...)
# Launch the graph and train, saving the model every 1,000 steps.
sess = tf.Session()
for step in xrange(1000000):
sess.run(..training_op..)
if step % 1000 == 0:
# Append the step number to the checkpoint name:
saver.save(sess, 'my-model', global_step=step)
4、从tf迁移到tf2
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()