SSD-Tensorflow icon indicating copy to clipboard operation
SSD-Tensorflow copied to clipboard

How to freeze ssd_300_vgg graph

Open mjohnst opened this issue 7 years ago • 7 comments

Hello,

I am interested in loading one of the checkpoints you've made into an application that only takes Tensorflow frozen graphs (.pb file).

I'm using the freeze_graph.py tool to do so. I've generated the input_graph by running tf.train.write_graph(session.graph_def, '/home/mjohnst/graph.pbtxt') during the caffe_to_tensorflow.py script that generates the checkpoint.

One additional parameter I need is the output_node_names. I got all the node names by running tf.get_default_graph().as_graph_def().node and choose the last node in the list save/restore_all Is this the correct name of the output nodes?

If I'm going about this wrong, feel free to correct me :) I was thinking that my call to write_graph may be able to write out the whole frozen graph, but I'm not sure. In the write_graph I tried using as_text=False and changed the format to pb, but when trying to freeze the weights into the input graph (assuming I still need to do this), I get an exception.

Thanks!

mjohnst avatar Apr 03 '17 23:04 mjohnst

@mjohnst Did you ever figure this out? I'm in the same situation, and I didn't see a good final layer to use in the Tensorboard representation of the network.

mckees avatar May 19 '17 22:05 mckees

I think below softmax loss layers are good choices for freezing(not only one but many),

ssd_300_vgg/softmax/Softmax ssd_300_vgg/softmax_1/Softmax ssd_300_vgg/softmax_2/Softmax ssd_300_vgg/softmax_3/Softmax ssd_300_vgg/softmax_4/Softmax ssd_300_vgg/softmax_5/Softmax ssd_losses/softmax/Softmax ssd_losses/cross_entropy_pos/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits ssd_losses/cross_entropy_neg/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits

can any body suggest other layers for freezing?

dedoogong avatar Dec 28 '17 00:12 dedoogong

I found 'ssd_losses/softmax/Softmax' is the best choice

I got stuck with passing one image into the frozen graph for inference.

original graph has prefetch queue/dequeue for batch processing, but in test phase, we usually need to pass one image. so I need to trasform or remap the original input queue to just a simple "input" which can be found in the tensorflow inceptionV3 pb example. a gist already made it (https://gist.github.com/tokestermw/795cc1fd6d0c9069b20204cbd133e36b), but I'm still struggling in how to adapt "tf.import_graph_def" to fit it in my SSD case..

tf.import_graph_def( graph_def, input_map={"input:0": new_input}, return_elements=None, # if input_map is not None, needs a name name="bla", op_dict=None, producer_op_list=None )

dedoogong avatar Jan 04 '18 01:01 dedoogong

freezing:

python3 freeze_graph.py
--input_binary=false
--input_graph=graph.pbtxt
--input_checkpoint=model.ckpt-60000
--output_graph=ssd300frozen_graph.pb
--output_node_names=?

what are the correct names of the "output_node_names"

liuyan20062010 avatar Jan 17 '18 02:01 liuyan20062010

do you know the input_node_name of ssd_300_vgg

liuyan20062010 avatar Jan 24 '18 06:01 liuyan20062010

do you know the input_node_name of ssd_300_vgg

Hi,I am struggling in this problem, have you sovled this? please help!

lucky-xu-1994 avatar Aug 04 '20 02:08 lucky-xu-1994

The matter is the input, I just need a placeholder, not a queue

LeeBC2298 avatar Aug 05 '20 09:08 LeeBC2298