Code for 3D object detection for autonomous driving
MIT License
939
stars
347
forks
source link
Convert checkpoints to frozen graph, "ValueError: graph_def is invalid at node u'global_step/Assign': Input tensor 'global_step:0' Cannot convert a tensor of type int32 to an input of type int32_ref." #190
I am using python 3.6 and TF 1.5.0. I downloaded an AVOD checkpoint from the pseudo_lidar repo https://github.com/mileyan/pseudo_lidar, and I am trying to convert the checkpoint to a frozen_graph.pb using this script:
`import tensorflow as tf
import os
meta_path = './checkpoints/pyramid_cars_with_aug_example_scratch_300_val-00120000.meta' # Your .meta file
ckpt_path = './checkpoints/pyramid_cars_with_aug_example_scratch_300_val-00120000'
dir(tf.contrib)
saver = tf.train.import_meta_graph(meta_path)
# Load weights
saver.restore(sess, ckpt_path) #tf.train.latest_checkpoint(ckpt_path))
output_node_names = ['avod_nms/Gather_1', 'avod_nms/Gather_2', 'avod_nms/Gather_3', 'avod_nms/Gather_4', 'avod_nms/Gather_5']
# Freeze the graph
frozen_graph_def = tf.graph_util.convert_variables_to_constants(
sess,
sess.graph_def,
output_node_names)
# Save the frozen graph
with open('frozen_graph.pb', 'wb') as f:
f.write(frozen_graph_def.SerializeToString())`
However, when I load the frozen_graph.pb using this script:
`import os
import sys
import tensorflow as tf
from tensorflow.python.client import device_lib
dir(tf.contrib)
detection_graph = tf.Graph()
with detection_graph.as_default():
od_graph_def = tf.GraphDef()
with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
serialized_graph = fid.read()
od_graph_def.ParseFromString(serialized_graph)
global_step_tensor = tf.Variable(0, trainable=False, name='global_step')
# import graph
tf.import_graph_def(od_graph_def, name='')`
I get this error:
Traceback (most recent call last): File "/home/iyu/racecar/catkin_ws/src/knightrider-racecar/avod_obj_detection/src/model_import_test.py", line 52, in <module> tf.import_graph_def(od_graph_def, name='') File "/home/iyu/.local/lib/python2.7/site-packages/tensorflow/python/util/deprecation.py", line 316, in new_func return func(*args, **kwargs) File "/home/iyu/.local/lib/python2.7/site-packages/tensorflow/python/framework/importer.py", line 648, in import_graph_def node, 'Input tensor %r %s' % (input_name, te))) ValueError: graph_def is invalid at node u'global_step/Assign': Input tensor 'global_step:0' Cannot convert a tensor of type int32 to an input of type int32_ref.
I think the script for freezing the graph is not properly storing global_step as a constant... how would I do this? Or is there a frozen AVOD graph somewhere I could download?
I am using python 3.6 and TF 1.5.0. I downloaded an AVOD checkpoint from the pseudo_lidar repo https://github.com/mileyan/pseudo_lidar, and I am trying to convert the checkpoint to a frozen_graph.pb using this script:
`import tensorflow as tf import os
meta_path = './checkpoints/pyramid_cars_with_aug_example_scratch_300_val-00120000.meta' # Your .meta file ckpt_path = './checkpoints/pyramid_cars_with_aug_example_scratch_300_val-00120000'
os.environ["CUDA_VISIBLE_DEVICES"] = '0'
config = tf.ConfigProto() config.gpu_options.allow_growth = True config.log_device_placement=True
with tf.Session(config=config) as sess:
Restore the graph
However, when I load the frozen_graph.pb using this script: `import os import sys import tensorflow as tf
from tensorflow.python.client import device_lib
dir(tf.contrib) detection_graph = tf.Graph() with detection_graph.as_default(): od_graph_def = tf.GraphDef()
I get this error:
Traceback (most recent call last): File "/home/iyu/racecar/catkin_ws/src/knightrider-racecar/avod_obj_detection/src/model_import_test.py", line 52, in <module> tf.import_graph_def(od_graph_def, name='') File "/home/iyu/.local/lib/python2.7/site-packages/tensorflow/python/util/deprecation.py", line 316, in new_func return func(*args, **kwargs) File "/home/iyu/.local/lib/python2.7/site-packages/tensorflow/python/framework/importer.py", line 648, in import_graph_def node, 'Input tensor %r %s' % (input_name, te))) ValueError: graph_def is invalid at node u'global_step/Assign': Input tensor 'global_step:0' Cannot convert a tensor of type int32 to an input of type int32_ref.
I think the script for freezing the graph is not properly storing global_step as a constant... how would I do this? Or is there a frozen AVOD graph somewhere I could download?