You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从导入的TensorFlow元图中检索输入变量名称?

How to Identify Input/Output Tensor Names for a Pre-Trained TensorFlow Model (No Source Code)

I’ve been in this exact situation before—importing a pre-trained model without access to the original code can feel like guessing in the dark, but there are straightforward ways to figure out the tensor names you need. Here’s what you can do:

1. List All Tensor Nodes in the Graph

First, after restoring the model, you can dump out every node name in the TensorFlow graph. This will give you a full list to sift through:

graph = tf.get_default_graph()
# Iterate through all nodes and print their names
for node in graph.as_graph_def().node:
    print(node.name)

You’ll get a long list, but look for keywords that make sense for your use case (since your model is from a VizDoom RL project, think game-related terms).

2. Filter for Likely Input Tensors

For RL models built on VizDoom, inputs are almost always game frames/screens. So search for names containing terms like:

  • input
  • observation
  • screen
  • frame
  • state

To narrow things down quickly, add a filter to your loop:

for node in graph.as_graph_def().node:
    if any(keyword in node.name.lower() for keyword in ["input", "observation", "screen"]):
        print(node.name)

Remember: When you want to fetch the actual tensor, you need to append :0 to the node name (this refers to the first output tensor of that node). For example, if you see input_layer, the tensor would be input_layer:0.

3. Find Output Tensors

For reinforcement learning models, outputs are typically actions, Q-values, or policy distributions. Look for names with:

  • action
  • q_value
  • policy
  • logit

Again, use a filter to speed this up:

for node in graph.as_graph_def().node:
    if any(keyword in node.name.lower() for keyword in ["action", "q_value", "policy"]):
        print(node.name)

4. Validate the Tensors

Once you have candidate names, test them by feeding in dummy data that matches the expected input shape (VizDoom models often use 4 stacked 84x84 grayscale frames, so shape (1, 84, 84, 4)):

import numpy as np

# Replace with your candidate input/output names
input_tensor = graph.get_tensor_by_name("your_input_node:0")
output_tensor = graph.get_tensor_by_name("your_output_node:0")

# Generate dummy input
test_input = np.random.rand(1, 84, 84, 4).astype(np.float32)
# Run the model
result = session.run(output_tensor, feed_dict={input_tensor: test_input})

print("Model output:", result)

If you get a reasonable output (like a discrete action index or Q-values for each action), you’ve found the right tensors!

内容的提问来源于stack exchange,提问作者AFanthomme

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:41:18