I\'m learning about MobileNet thesedays and i\'m new to tensorflow. After training with ssd-mobilenet model,i got checkpoint file , .meta file , graph.pbtxt file and so on.
You should load the graph using tf.train.import_meta_graph()
and then get the tensors using get_tensor_by_name()
. You can try:
model_path = "model.ckpt"
detection_graph = tf.Graph()
with tf.Session(graph=detection_graph) as sess:
# Load the graph with the trained states
loader = tf.train.import_meta_graph(model_path+'.meta')
loader.restore(sess, model_path)
# Get the tensors by their variable name
image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
scores = detection_graph.get_tensor_by_name('detection_scores:0')
...
# Make predictions
_boxes, _scores = sess.run([boxes, scores], feed_dict={image_tensor: image_np_expanded})
Just for those who have the problem like wu ruize and CoupDeMistral:
But I got this error:
"The name 'image_tensor:0' refers to a Tensor which does not exist. The operation, 'image_tensor', does not exist in the graph."
You need to name your tensor first before using detection_graph.get_tensor_by_name.
For example, something like this:
accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32),name='accuracy')
Notice that the tensor above has been named as 'accuracy'.
After that you can enjoy the restore operation by:
detection_graph.get_tensor_by_name('accuracy:0')
Have fun now :P!