保存:
saver = tf.train.Saver()
saver.save(sess, './model/model.ckpt', global_step=i)
读取:
model_dir = "./model/" # 文件路径
reader = tf.train.NewCheckpointReader(tf.train.get_checkpoint_state(model_dir).model_checkpoint_path)
data_dict = reader.get_variable_to_shape_map()
for key in data_dict:
# Print tensor name and values
print("tensor_name: ", key)
print(reader.get_tensor(key))
# save
f = open('./model/tensor.txt', 'a')
f.write(key)
f.write(str(reader.get_tensor(key)))
f.write('\r\n')
f.close()