Is there an example on how to generate protobuf files holding trained TensorFlow graphs

前端 未结 6 1869
情话喂你
情话喂你 2020-11-28 19:45

I am looking at Google\'s example on how to deploy and use a pre-trained Tensorflow graph (model) on Android. This example uses a .pb file at:

6条回答
  •  隐瞒了意图╮
    2020-11-28 19:58

    Here's another take on @Mostafa's answer. A somewhat cleaner way to run the tf.assign ops is to store them in a tf.group. Here's my Python code:

      ops = []
      for v in tf.trainable_variables():
        vc = tf.constant(v.eval())
        ops.append(tf.assign(v, vc));
      tf.group(*ops, name="assign_trained_variables")
    

    And in C++:

      std::vector tmp;
      status = session.Run({}, {}, { "assign_trained_variables" }, &tmp);
      if (!status.ok()) {
        // Handle error
      }
    

    This way you have only one named op to run on the C++ side, so you don't have to mess around with iterating over nodes.

提交回复
热议问题