从TensorFlow模型检查点中提取权重值

我在TensorFlow中训练一个模型,并为我的模型设置了检查点。在Checkpoints目录中,我有四个文件,分别是:

  • checkpoint
  • model.cpkt-0.data-00000-of-00001
  • model.cpkt-0.index
  • model.cpkt-0.meta

现在我想提取图中每一层的权重值,该如何操作呢?

我尝试了以下方法:

import tensorflow as tfsess = tf.InteractiveSession()saver = tf.train.import_meta_graph('model.cpkt-0.meta')w = saver.restore(sess, 'model.cpkt-0.data-00000-of-00001')

但我遇到了以下错误:

Unable to open table file ./model.cpkt-0.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?

回答:

你恢复的方式不对

saver.restore(sess, 'model.cpkt-0')# 获取图g = tf.get_default_graph()w1 = g.get_tensor_by_name('some_variable_name as per your definition in the model')

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注