Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the name of the tensorflow output nodes in a Keras Model?

I'm trying to create a pb file from my Keras (tensorflow backend) model so I can build it on iOS. I'm using freeze.py and I need to pass the output nodes. How do i get the names of the output nodes of my Keras model?

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py

like image 651
agsolid Avatar asked Oct 13 '16 18:10

agsolid


People also ask

How do I get a model summary in TensorFlow?

Model summaryCall model. summary() to print a useful summary of the model, which includes: Name and type of all layers in the model. Output shape for each layer.

What is TensorFlow keras model?

Keras is a neural network Application Programming Interface (API) for Python that is tightly integrated with TensorFlow, which is used to build machine learning models. Keras' models offer a simple, user-friendly way to define a neural network, which will then be built for you by TensorFlow.

What is sequential in TensorFlow?

A Sequential model is appropriate for a plain stack of layers where each layer has exactly one input tensor and one output tensor. Schematically, the following Sequential model: # Define Sequential model with 3 layers. model = keras.


1 Answers

You can use Keras model.summary() to get the name of the last layer.

If model.outputs is not empty you can get the node names via:

[node.op.name for node in model.outputs] 

you get the session via

session = keras.backend.get_session() 

and you convert all training variables to consts via

min_graph = convert_variables_to_constants(session, session.graph_def, [node.op.name for node in model.outputs]) 

after that you can write a protobuf-file via

tensorflow.train.write_graph(min_graph, "/logdir/", "file.pb", as_text=True) 
like image 195
BerndSchmitt Avatar answered Sep 19 '22 14:09

BerndSchmitt