TensorFlow CPU版合并Checkpoint与图生成Frozen Graph报错求助
Hey Hamza, let's work through this issue you're having when trying to freeze your object detection model. That error about names_to_saveables happens because the script is encountering a Tensor where it expected a Variable, and there are a few straightforward fixes to try:
1. 确认输出节点名称是否正确
Your current --output_node_names=ObjectRes looks incomplete—object detection models typically have multiple output nodes like detection_boxes, detection_scores, detection_classes, and num_detections. To find the exact output nodes for your model, run this command:
saved_model_cli show --dir /home/hamza/object_detection/saved_model1 --all
This will list all input/output nodes for your SavedModel. Update the --output_node_names parameter with the correct comma-separated names (e.g., --output_node_names=detection_boxes,detection_scores,detection_classes,num_detections).
2. 检查Checkpoint与图的匹配性
Make sure all checkpoint files (model.ckpt.meta, model.ckpt.index, model.ckpt.data-00000-of-00001) are present in the same directory as model.ckpt, and that they correspond to the same training session as your frozen_inference_graph.pb. Mismatched files can cause Tensor/Variable mismatch errors.
3. 尝试手动冻结图(替代freeze_graph.py)
Instead of using the freeze_graph.py script, you can write a small Python script to directly load your SavedModel and freeze it. This often avoids parameter-related issues:
import tensorflow as tf # Initialize graph and session graph = tf.Graph() with graph.as_default(): sess = tf.compat.v1.Session() # Load the SavedModel (use 'serve' tag for inference) tf.compat.v1.saved_model.loader.load(sess, ['serve'], '/home/hamza/object_detection/saved_model1') # Get the graph definition graph_def = graph.as_graph_def() # Freeze variables into constants (replace with your actual output nodes) frozen_graph_def = tf.compat.v1.graph_util.convert_variables_to_constants( sess, graph_def, ['detection_boxes', 'detection_scores', 'detection_classes', 'num_detections'] ) # Save the frozen graph with tf.io.gfile.GFile('/home/hamza/object_detection/saved_model1/frozen_graph.pb', 'wb') as f: f.write(frozen_graph_def.SerializeToString())
Run this script, and it should generate your frozen graph without the TypeError.
关于CPU指令警告
The line about SSE4.1 SSE4.2 AVX AVX2 FMA is just a warning—TensorFlow is letting you know your CPU supports faster instructions that your build isn't using. This doesn't cause the freeze error, so you can ignore it unless you want to recompile TensorFlow with those optimizations later.
内容的提问来源于stack exchange,提问作者Hamza bekkouri

