daily pastebin goal
30%
SHARE
TWEET

Untitled

a guest Jul 12th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. with tf.Session(graph=graph) as sess:
  2.     while True:
  3.         a = []
  4.         try:
  5.             files = os.listdir(folder_name)
  6.  
  7.             for f in files:
  8.                 try:
  9.                     #CALLING IMAGE READ FUNCTION
  10.                     t = sess.run(read_tensor_from_image_file(
  11.                         (folder_name+"/"+f),
  12.                         input_height=input_height,
  13.                         input_width=input_width,
  14.                         input_mean=input_mean,
  15.                         input_std=input_std))
  16.  
  17.                     #GETTING INFERENCE
  18.                     results = sess.run(output_operation.outputs[0], {
  19.                         input_operation.outputs[0]: t
  20.                     })
  21.  
  22.  
  23.  
  24.                     results = np.squeeze(results)
  25.  
  26.                     top_k = results.argsort()[-5:][::-1]
  27.    
  28. def read_tensor_from_image_file(file_name,
  29.                             input_height=299,
  30.                             input_width=299,
  31.                             input_mean=0,
  32.                             input_std=255):
  33. input_name = "file_reader"
  34. output_name = "normalized"
  35. file_reader = tf.read_file(file_name, input_name)
  36. if file_name.endswith(".png"):
  37.     image_reader = tf.image.decode_png(
  38.         file_reader, channels=3, name="png_reader")
  39. elif file_name.endswith(".gif"):
  40.     image_reader = tf.squeeze(
  41.         tf.image.decode_gif(file_reader, name="gif_reader"))
  42. elif file_name.endswith(".bmp"):
  43.     image_reader = tf.image.decode_bmp(file_reader, name="bmp_reader")
  44. else:
  45.     image_reader = tf.image.decode_jpeg(
  46.         file_reader, channels=3, name="jpeg_reader")
  47. float_caster = tf.cast(image_reader, tf.float32)
  48. dims_expander = tf.expand_dims(float_caster, 0)
  49. resized = tf.image.resize_bilinear(
  50.     dims_expander, [input_height, input_width])
  51. normalized = tf.divide(tf.subtract(resized, [input_mean]), [input_std])
  52.  
  53.  
  54. return normalized
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top