Weight and offset from processed metagraph

I have successfully exported the reprocessed InceptionV3 NN as a TensorFlow metagraph. I have successfully read this protobuf in python, but I'm struggling to find a way to export the values ​​and offset values ​​of each level, which I assume is stored in the protobuf metafactor to recreate nn outside of TensorFlow.

My workflow is this:

Retrain final layer for new categories
Export meta graph tf.train.export_meta_graph(filename='model.meta')
Build python pb2.py using Protoc and meta_graph.proto
Load Protobuf:

import meta_graph_pb2
saved = meta_graph_pb2.CollectionDef()
with open('model.meta', 'rb') as f:
  saved.ParseFromString(f.read())

From here I can view most aspects of the graph, for example, node names, etc., but I think that my inexperience makes it difficult to find the right way to access the weight and offset values ​​for each corresponding layer.

+4
source share
1 answer

MetaGraphDef . GraphDef , , tf.train.Saver. MetaGraphDef , :

  • tf.train.Saver. MetaGraphDef .meta .

    saver = tf.train.Saver(...)
    # ...
    saver.save(sess, "model")
    

    model.meta model-NNNN ( NNNN).

  • MetaGraphDef .

    saver = tf.train.import_meta_graph("model.meta")
    saver.restore("model-NNNN")  # Or whatever checkpoint filename was written.
    

    , () tf.all_variables() sess.run(), . , , :

    for var in tf.all_variables():
      print var.name, sess.run(var)
    

    tf.all_variables(), , .

+7

Source: https://habr.com/ru/post/1652390/


All Articles