这次报错与是否gpu没有关系:
TENSORFLOW 导入失败:PROCESS FINISHED WITH EXIT CODE -1073741819 (0XC0000005)
测试脚本:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
这个异常,我的解决方法是,tf2.0一下版本,只支持cuda10.0。
重新安装cuda10.0,tf1.15.0版本,后来这个问题就解决了。
预训练下面有个:checkpoint文件,
checkpoint
model_checkpoint_path: "snap-43001"
all_model_checkpoint_paths: "snap-33501"
all_model_checkpoint_paths: "snap-35501"
all_model_checkpoint_paths: "snap-37001"
all_model_checkpoint_paths: "snap-43001"
实际上 最终模型是snap-37001
改一下checkpoint
model_checkpoint_path: "snap-37001"
all_model_checkpoint_paths: "snap-29001"
all_model_checkpoint_paths: "snap-33501"
all_model_checkpoint_paths: "snap-35501"
all_model_checkpoint_paths: "snap-37001"
ok,然后加载预训练ok!
加载预训练方法1:
tf 1.15版本以前加载预训练:
saver.restore(sess, restore_snap)
tf1.15版本:
aaa = tf.train.latest_checkpoint(restore_snap)
#saver.restore(sess, restore_snap)
print("start restore------------------", restore_snap,aaa)
self.saver.restore(self.sess, aaa)
print("Model restored from " + restore_snap)
加载预训练方法2:
参考:https://blog.csdn.net/wjc1182511338/article/details/82111790
def build_graph():
w1 = tf.Variable([1,3,10,15],name='W1',dtype=tf.float32)
w2 = tf.Variable([3,4,2,18],name='W2',dtype=tf.float32)
w3 = tf.placeholder(shape=[4],dtype=tf.float32,name='W3')
w4 = tf.Variable([100,100,100,100],dtype=tf.float32,name='W4')
add = tf.add(w1,w2,name='add')
add1 = tf.add(add,w3,name='add1')
return w3,add1
with tf.Session() as sess:
ckpt_state = tf.train.get_checkpoint_state('./temp/')
if ckpt_state:
w3,add1=build_graph()
saver = tf.train.Saver()
saver.restore(sess, ckpt_state.model_checkpoint_path)
else:
w3,add1=build_graph()
init_op = tf.group(tf.global_variables_initializer(),tf.local_variables_initializer())
sess.run(init_op)
saver = tf.train.Saver()
a = sess.run(add1,feed_dict={
w3:[1,2,3,4]
})
print(a)
saver.save(sess,'./temp/model')