daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Feb 21st, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import tensorflow as tf
  2. import numpy as np
  3. import os
  4. import cv2
  5. import argparse
  6.  
  7. def read_img(name):
  8.     x = cv2.imread(name, cv2.IMREAD_COLOR)
  9.     x = cv2.cvtColor(x, cv2.COLOR_BGR2RGB)
  10.     return x
  11.  
  12. def dir_images(path):
  13.     img_arr = [path + x for x in os.listdir(path)]
  14.     return img_arr
  15.  
  16. parser = argparse.ArgumentParser()
  17. parser.add_argument("mode")
  18. args = parser.parse_args()
  19. mode = args.mode
  20.  
  21. tf.enable_eager_execution()
  22.  
  23. true_arr = dir_images('./test/truth/')
  24. sn_arr = dir_images('./test/snsrgan/')
  25. sr_arr = dir_images('./test/srgan/')
  26. bi_arr = dir_images('./test/bicubic/')
  27.  
  28. print(len(true_arr), len(sn_arr), len(sr_arr), len(bi_arr))
  29. sr_sim_arr = []
  30. sn_sim_arr = []
  31. bi_sim_arr = []
  32.  
  33. for t, bi, sr, sn in zip(true_arr, bi_arr, sr_arr, sn_arr):
  34.     print(t)
  35.     t_img  = read_img(t)
  36.     bi_img = read_img(bi)
  37.     sr_img = read_img(sr)
  38.     sn_img = read_img(sn)
  39.  
  40.     if mode == 'psnr':
  41.         bi_sim = tf.image.psnr(bi_img, t_img, max_val=255).numpy()
  42.         sr_sim = tf.image.psnr(sr_img, t_img, max_val=255).numpy()
  43.         sn_sim = tf.image.psnr(sn_img, t_img, max_val=255).numpy()
  44.     else:
  45.         t_img = tf.convert_to_tensor(t_img)
  46.  
  47.         bi_sim = tf.image.ssim(tf.convert_to_tensor(bi_img), t_img, max_val=255).numpy()
  48.         sr_sim = tf.image.ssim(tf.convert_to_tensor(sr_img), t_img, max_val=255).numpy()
  49.         sn_sim = tf.image.ssim(tf.convert_to_tensor(sn_img), t_img, max_val=255).numpy()
  50.    
  51.     bi_sim_arr.append(bi_sim)
  52.     sr_sim_arr.append(sr_sim)
  53.     sn_sim_arr.append(sn_sim)
  54.  
  55. print('bi: ', sum(bi_sim_arr) / len(bi_sim_arr))
  56. print('sr: ', sum(sr_sim_arr) / len(sr_sim_arr))
  57. print('sn: ', sum(sn_sim_arr) / len(sn_sim_arr))
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