查看ckpt中节点信息

from tensorflow.python import pywrap_tensorflow
import os
checkpoint_path = MODEL_FILE_CKPT
reader = pywrap_tensorflow.NewCheckpointReader(checkpoint_path)
var_to_shape_map = reader.get_variable_to_shape_map()
for key in var_to_shape_map:
    print("tensor_name: ", key)
您可以使用TensorFlow的`inspect_checkpoint`模块来获取ckpt文件的所有变量,然后根据变量名找到要输出的节点名称。 以下是一个示例代码,它列出了给定ckpt文件的所有变量名称: ```python import tensorflow as tf from tensorflow.python.tools import inspect_checkpoint ckpt_path = "/path/to/your/ckpt/file" # List all variables in the checkpoint file inspect_checkpoint.print_tensors_in_checkpoint_file(ckpt_path, tensor_name='', all_tensors=True) ``` 输出将类似于以下内容: ``` tensor_name: dense/kernel (DT_FLOAT) [784,10] [[ 0.02416449 -0.0475637 0.0556073 ... -0.05033178 0.04500757 -0.02516449] [-0.05762496 -0.03277328 -0.00278839 ... 0.06256668 -0.03260396 -0.03537507] ... [-0.0303502 0.03090762 -0.04702229 ... 0.04498903 0.04480387 0.01993509] [-0.04007631 -0.00890576 0.01127442 ... -0.01387329 -0.00065558 0.00172326]] tensor_name: dense/bias (DT_FLOAT) [10] [ 0.02104062 -0.02318692 -0.02234132 -0.00386816 0.03873952 0.02142542 -0.0235577 0.0084792 -0.02807822 0.00934654] ... ``` 在这个例子,`dense/kernel`和`dense/bias`是两个变量,它们分别对应Dense层的权重和偏差。您可以使用这些变量名称来找到这些节点的输出名称。例如,如果您想输出Dense层的激活值,则可以使用以下代码: ```python import tensorflow as tf ckpt_path = "/path/to/your/ckpt/file" with tf.Session() as sess: saver = tf.train.import_meta_graph(ckpt_path + '.meta') saver.restore(sess, ckpt_path) # Find the output tensor by name output_tensor = sess.graph.get_tensor_by_name("dense/BiasAdd:0") # Run the session to get the output output_value = sess.run(output_tensor, feed_dict={...}) ``` 在这个例子,`dense/BiasAdd:0`是Dense层的输出节点名称,您可以使用`sess.graph.get_tensor_by_name()`方法来获取它。然后,您可以使用`sess.run()`方法来运行该节点并获得输出值。请注意,您需要将正确的输入数据提供给`feed_dict`参数。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值