Guest User

Untitled

a guest
Jan 23rd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. import commentjson
  2. import os
  3. import sys
  4.  
  5. import collections
  6.  
  7. import numpy as np
  8. import scipy as scp
  9. import scipy.misc
  10. import tensorflow as tf
  11.  
  12. sys.path.insert(1,'incl')
  13.  
  14. try:
  15. # Check whether setup was done correctly
  16.  
  17. import tensorvision.utils as tv_utils
  18. import tensorvision.core as core
  19. import tensorvision.train
  20. import tensorflow_fcn.utils
  21. except ImportError:
  22. # You forgot to initialize submodules
  23. logging.error("Could not import the submodules.")
  24. logging.error("Please execute:"
  25. "'git submodule update --init --recursive'")
  26. exit(1)
  27.  
  28.  
  29.  
  30. # load the network from the working directory
  31. # for some reason I can't get this to work without
  32. # using tensorvision - TODO figure this out so we can
  33. # use any checkpoint from the run directory
  34. logdir = 'CHANGE_THIS'
  35. image_pl = tf.placeholder(tf.float32)
  36.  
  37. hypes = tv_utils.load_hypes_from_logdir(logdir)
  38. modules = tv_utils.load_modules_from_logdir(logdir)
  39.  
  40. image_pl = tf.placeholder(tf.float32)
  41. image = tf.expand_dims(image_pl, 0)
  42. pred = core.build_inference_graph(hypes, modules,
  43. image=image)
  44.  
  45. # load the weights
  46. sess = tf.Session()
  47. saver = tf.train.Saver()
  48. core.load_weights(logdir, sess, saver)
  49.  
  50. # freeze the graph
  51. frozen_graph_def = tf.graph_util.convert_variables_to_constants(
  52. sess, sess.graph.as_graph_def(), ['Validation/decoder/Softmax'])
  53.  
  54. # remove training only nodes
  55. frozen_graph_def = tf.graph_util.remove_training_nodes(frozen_graph_def)
  56.  
  57. # save the model
  58. with tf.gfile.GFile('test_frozen_model.pb', 'wb') as f:
  59. f.write(frozen_graph_def.SerializeToString())
Add Comment
Please, Sign In to add comment