1

I am referring https://github.com/dennybritz/cnn-text-classification-tf as a reference. My goal is to build frozen graph from model files. I want to know input and output node in the signature to effectively build the frozen graph. I am printing the proto file from the graph definition using the following code.

saver=tf.train.import_meta_graph('some_path/model.ckpt.meta')
imported_graph = tf.get_default_graph() 
graph_op = imported_graph.get_operations() with open('output.txt', 'w') as f:
        for i in graph_op:
            f.write(str(i))

The output I am getting is as follows: https://drive.google.com/drive/folders/1iZQqohx8jAWbSw7XV3vFJuLkaUp0Dt2s?usp=sharing

How do I know which is the output node and which is the input node there are plathora of input and outputs in this file?

Ajinkya
  • 1,797
  • 3
  • 24
  • 54

1 Answers1

2

I recommend to use Tensorboard to visualize graph structure instead of using text file with nodes. You can find more details here.

However the graph itself doesn't have notion of inputs or outputs. You can treat nodes without input connections as good candidates for being input nodes, especially placeholder nodes. Nodes that are connected to loss function are good candidates for being output nodes.

To sum up: In general you need to guess which nodes are the input and which are the output by analyzing network architecture.

As for the repository you referenced, you can read eval.py code and find these lines:

input_x = graph.get_operation_by_name("input_x").outputs[0]
# input_y = graph.get_operation_by_name("input_y").outputs[0]
dropout_keep_prob = graph.get_operation_by_name("dropout_keep_prob").outputs[0]

# Tensors we want to evaluate
predictions = graph.get_operation_by_name("output/predictions").outputs[0]

So it is likely that the input node is "input_x" and the output node is "output/predictions".

dm0_
  • 2,146
  • 1
  • 16
  • 22
  • Thank you that worked ! I now have input and output tensors and a '.pb' graph. Is there any script I can lookup to generate predictions directly from this graph – Ajinkya Aug 22 '18 at 04:25
  • 1
    @Ajinkya, if you are looking for a simple usage example, then `eval.py` from the repository is simple enough. With frozen graph you don't need to call `saver.restore`. Also you may find [Tensorflow Serving](https://www.tensorflow.org/serving/) useful. – dm0_ Aug 22 '18 at 06:45