test_align.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import facenet
  2. import os
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. def main():
  6. image_size = 96
  7. old_dataset = '/home/david/datasets/facescrub/fs_aligned_new_oean/'
  8. new_dataset = '/home/david/datasets/facescrub/facescrub_110_96/'
  9. eq = 0
  10. num = 0
  11. l = []
  12. dataset = facenet.get_dataset(old_dataset)
  13. for cls in dataset:
  14. new_class_dir = os.path.join(new_dataset, cls.name)
  15. for image_path in cls.image_paths:
  16. try:
  17. filename = os.path.splitext(os.path.split(image_path)[1])[0]
  18. new_filename = os.path.join(new_class_dir, filename+'.png')
  19. #print(image_path)
  20. if os.path.exists(new_filename):
  21. a = facenet.load_data([image_path, new_filename], False, False, image_size, do_prewhiten=False)
  22. if np.array_equal(a[0], a[1]):
  23. eq+=1
  24. num+=1
  25. err = np.sum(np.square(np.subtract(a[0], a[1])))
  26. #print(err)
  27. l.append(err)
  28. if err>2000:
  29. fig = plt.figure(1)
  30. p1 = fig.add_subplot(121)
  31. p1.imshow(a[0])
  32. p2 = fig.add_subplot(122)
  33. p2.imshow(a[1])
  34. print('%6.1f: %s\n' % (err, new_filename))
  35. pass
  36. else:
  37. pass
  38. #print('File not found: %s' % new_filename)
  39. except:
  40. pass
  41. if __name__ == '__main__':
  42. main()