Guest User

Untitled

a guest
Jun 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. import tensorflow as tf
  2. from tensorflow.python.saved_model import builder as saved_model_builder
  3. from tensorflow.python.saved_model import signature_constants
  4. from tensorflow.python.saved_model import signature_def_utils
  5. from tensorflow.python.saved_model import tag_constants
  6. from tensorflow.python.saved_model.utils import build_tensor_info
  7.  
  8. model_path = './frozen/inception_v3_2016_08_28_frozen.pb'
  9. target_dir = './models/inception/3'
  10.  
  11. # (1)
  12. with tf.gfile.FastGFile(model_path, 'rb') as f:
  13. graph_def = tf.GraphDef()
  14. graph_def.ParseFromString(f.read())
  15. _ = tf.import_graph_def(graph_def, name='')
  16.  
  17. input_name = 'input'
  18. output_name = 'InceptionV3/Predictions/Reshape_1'
  19.  
  20. with tf.Session() as sess:
  21. # (2)
  22. model_input = build_tensor_info(sess.graph.get_tensor_by_name(input_name + ':0'))
  23. model_output = build_tensor_info(sess.graph.get_tensor_by_name(output_name + ':0'))
  24.  
  25. # (3)
  26. signature_definition = signature_def_utils.build_signature_def(
  27. inputs={input_name: model_input},
  28. outputs={output_name: model_output},
  29. method_name=signature_constants.PREDICT_METHOD_NAME)
  30.  
  31. # (4)
  32. builder = saved_model_builder.SavedModelBuilder(target_dir)
  33. builder.add_meta_graph_and_variables(sess, [tag_constants.SERVING], signature_def_map={
  34. signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: signature_definition
  35. }, clear_devices=True)
  36. builder.save()
Add Comment
Please, Sign In to add comment