【问题标题】:Tensorflow how to inspect modelTensorflow如何检查模型
【发布时间】:2019-07-16 23:03:41
【问题描述】:

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

我创建了以下文件:

  • 检查点
  • my_time_series_model
  • my_time_series_model.index
  • my_time_series_model 元数据
  • train.PBTXT

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

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(坏幻数):也许是您的 文件是不同的文件格式,您需要使用不同的文件格式 恢复运算符?

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

任何帮助都会很棒!

【问题讨论】:

  • tf.train.list_variables(ckpt_file) 是否足以完成您的任务?
  • 我只是想知道使用 tf.train.write_graph(input_graph_def, logdir=destination, name=out_file, as_text=True) 创建的文件“检查点”是否甚至是写入文件?跨度>
  • 试过model_file = destination + "/checkpoint" 然后print(tf.train.list_variables(model_file)),还是一样的错误信息
  • 尝试使用`tf.train.latest_checkpoint(model_dir)'。您也可以从此函数获取名称格式,因为检查点的调用方式可能不同
  • 非常感谢。我试过了,我用了 print(tf.train.latest_checkpoint(model_file)),它打印“None”?

标签: tensorflow machine-learning output


【解决方案1】:

您可以使用 tensorflow python 工具中的inspect_checkpoint 函数检查检查点的张量。

来自 tensorflow 文档的示例:

# 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

【讨论】:

  • 您好弗朗索瓦,非常感谢您的帮助。不幸的是,我收到以下消息:“不成功的 TensorSliceReader 构造函数:无法找到 /tmp/model.ckpt 的任何匹配文件”,我也找不到 model.ckpt 文件?
猜你喜欢
  • 2019-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-17
  • 2019-12-13
  • 2021-04-21
相关资源
最近更新 更多