如何检查我的tensorflow神经网络中所有训练变量的值?

2024-06-26 14:27:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经保存了检查点,我可以用它们进行预测。不过,我只想看看我训练过的变量,知道它们的确切值是多少。你知道吗

我现在在检查点文件中使用打印张量tensorflow.python.tools工具.检查检查点。你知道吗

我也在使用系统标准输出将输出存储到txt文件中。你知道吗

我当前的代码如下所示:

from tensorflow.python.tools.inspect_checkpoint import print_tensors_in_checkpoint_file
import sys

def peekckpt(filePath):
    print_tensors_in_checkpoint_file(filePath,None,True)

sys.stdout = open("tmp.txt",'w')
peekckpt("/save/model.ckpt-10000")

但是,它不会显示所有细节。在tmp.txt文件,一些变量以省略号的形式表示(可能是因为变量太多),例如:

tensor_name:  fully_connected_1/weights
[[ 0.01625621 -0.01740162  0.04686484 ... -0.02088195 -0.02621443
   0.00247668]
 [-0.00319242 -0.04545522  0.01150012 ...  0.00360141 -0.00241386
  -0.04921322]
 [ 0.04347562  0.00918857  0.00323885 ...  0.01275046 -0.06735339
   0.02492226]

那么,我有没有办法摆脱这个省略号问题,让print\u checkpoint\u file()中的张量打印所有变量?


Tags: 文件inimporttxttensorflowsystools检查点
1条回答
网友
1楼 · 发布于 2024-06-26 14:27:22

在我的原始代码之前添加以下内容:

import numpy as np
np.set_printoptions(threshold=np.nan)

这会有用的。大约花了30到40秒,最后我得到了一个81MB的txt文件。你知道吗

相关问题 更多 >