首页 > 解决方案 > Tensorflow如何检查模型

问题描述

我建立了一个 Tensorflow RNN 模型并想检查模型结果(例如,使用了哪些特征/变量以及强度等)

我创建了以下文件:

但是我在阅读这些文件时遇到了问题。我找到了以下代码:

from tensorflow.python import pywrap_tensorflow

model_file = "/trained/checkpoint"
reader = pywrap_tensorflow.NewCheckpointReader(model_file)
var_to_shape_map = reader.get_variable_to_shape_map()

for key in sorted(var_to_shape_map):
    print("tensor_name: ", key)
    print(reader.get_tensor(key))

我收到以下错误:

检查点:数据丢失:不是 sstable(坏幻数):您的文件可能是不同的文件格式,您需要使用不同的恢复操作符?

检查点是错误的文件吗?它在我的文件夹中没有扩展名,它只是说类型是数据?

任何帮助都会很棒!

标签: tensorflowmachine-learningoutput

解决方案


您可以使用inspect_checkpointtensorflow python 工具中的功能检查检查点的张量。

来自张量流文档的示例:

# import the inspect_checkpoint library
from tensorflow.python.tools import inspect_checkpoint as chkp

# print all tensors in checkpoint file
chkp.print_tensors_in_checkpoint_file("/tmp/model.ckpt", tensor_name='', all_tensors=True)

# tensor_name:  v1
# [ 1.  1.  1.]
# tensor_name:  v2
# [-1. -1. -1. -1. -1.]

https://www.tensorflow.org/guide/saved_model#inspect_variables_in_a_checkpoint


推荐阅读