DataLossError (see above for traceback): Unable to open table file

最近在练习使用TensorFlow框架进行模型的训练和恢复,在进行模型恢复的过程中遇到了问题:

原代码:

meta_path = 'data_batch.txt_epoch_2.ckpt.meta'            #图路径
model_path = 'data_batch.txt_epoch_2.ckpt.data-00000-of-00001'                #数据路径
saver = tf.train.import_meta_graph(meta_path)       #加载图

with tf.Session() as sess:
    saver.restore(sess, model_path)                 #加载数据
    graph = tf.get_default_graph()
    input_pro = graph.get_tensor_by_name('input_pro:0')     #加载张量
    input_lnc = graph.get_tensor_by_name('input_lnc:0')
    true_labels = graph.get_tensor_by_name('true_labels:0')
    accuracy = graph.get_tensor_by_name('Accuracy/acc:0')
提示错误:DataLossError (see above for traceback): Unable to open table file .\data_batch.txt_epoch_2.ckpt.data-00000-of-00001: Data loss: not an sstable (bad magic number): perhaps your file is in a different file format and you need to use a different restore operator?
     [[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]]

更改代码:

meta_path = 'E:/test_restort_model/xixi/data_batch.txt_epoch_2.ckpt.meta'           #图路径
model_path =tf.train.latest_checkpoint('E:/test_restort_model/xixi/')                #数据路径
saver = tf.train.import_meta_graph(meta_path)       #加载图

with tf.Session() as sess:
    saver.restore(sess,model_path)                 #加载数据
    graph = tf.get_default_graph()
    input_pro = graph.get_tensor_by_name('input_pro:0')     #加载张量
    input_lnc = graph.get_tensor_by_name('input_lnc:0')
    true_labels = graph.get_tensor_by_name('true_labels:0')
    accuracy = graph.get_tensor_by_name('Accuracy/acc:0')
    is_train=graph.get_tensor_by_name('is_train:0')

就可以正常运行了。其中E:/test_restort_model/xixi/是训练模型时保存的到的文件的存储路径,这样操作恢复的模型是最新的训练得到的模型。

你可能感兴趣的:(DataLossError (see above for traceback): Unable to open table file)