TensorFlow 1.7 freeze_graph报错:缺少必填参数unused_args
Hey there, let's work through this freeze_graph error you're hitting. That unused_args message usually means the command-line argument parser is having trouble interpreting your inputs—this often stems from path formatting issues or a slightly off way of calling the tool. Here are the actionable steps I'd recommend:
1. Wrap Paths in Quotes if They Have Spaces/Special Characters
If any of your file paths include spaces, parentheses, or other non-standard characters, the shell might split them incorrectly, throwing off the argument parser. Enclose each full path in double quotes to fix this:
freeze_graph --input_graph="/full/actual/path/to/graph.pbtxt" --input_checkpoint="/full/actual/path/to/model.ckpt-21000" --input_binary=false --output_graph="/full/actual/path/to/frozen_mnist.pb" --output_node_names=softmax_tensor
2. Call freeze_graph via the TensorFlow Python Module
Sometimes directly using the freeze_graph command can run into environment variable or path resolution issues. A more reliable approach is to run it as a Python module, which guarantees you're using the exact TensorFlow version installed in your Mac environment:
python -m tensorflow.python.tools.freeze_graph --input_graph="/full/actual/path/to/graph.pbtxt" --input_checkpoint="/full/actual/path/to/model.ckpt-21000" --input_binary=false --output_graph="/full/actual/path/to/frozen_mnist.pb" --output_node_names=softmax_tensor
3. Double-Check Your Output Node Name
Make sure softmax_tensor is actually the correct name of your model's final output node. If you're unsure, use this quick Python script to list all nodes in your graph:
import tensorflow as tf # Replace with your actual graph.pbtxt path with tf.gfile.GFile("/full/actual/path/to/graph.pbtxt", "r") as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) # Print all node names to locate your output node for node in graph_def.node: print(node.name)
Swap in the correct node name (it might be something like just softmax instead of softmax_tensor) in your freeze_graph command.
4. Rule Out Version-Specific Bugs
While TensorFlow 1.7 supports all the parameters you're using, if the above steps don't resolve the issue, try upgrading to the final TensorFlow 1.x release (1.15) to eliminate potential bugs in the 1.7 freeze_graph implementation. Just confirm your trained model works with the newer version before making the switch.
These steps should get your freeze_graph command running smoothly—chances are the first two fixes will resolve that unused_args error right away.
内容的提问来源于stack exchange,提问作者Andrea Rossi

