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/是训练模型时保存的到的文件的存储路径,这样操作恢复的模型是最新的训练得到的模型。

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值