gpt4 book ai didi

machine-learning - 从 tensorflow 模型检查点提取权重值

转载 作者:行者123 更新时间:2023-11-30 08:33:29 24 4
gpt4 key购买 nike

我正在 tensorflow 中训练模型,并且正在为我的模型做检查点。我在 Checkpoints 目录中,有四个文件,即,

  • 检查点
  • model.cpkt-0.data-00000-of-00001
  • model.cpkt-0.index
  • model.cpkt-0.meta

现在我想提取图表中每一层的权重值,我该怎么做?

我尝试过这个:

import tensorflow as tf
sess = 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')
# get the graph
g = tf.get_default_graph()
w1 = g.get_tensor_by_name('some_variable_name as per your definition in the model')

关于machine-learning - 从 tensorflow 模型检查点提取权重值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45562755/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com