从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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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