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
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)
所有评论(0)