Guest User

Untitled

a guest
Jun 21st, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. # /////////////////////////// Custom Dataset ///////////////////////////#
  2. import numpy as np
  3. import os.path
  4. import cv2
  5. import matplotlib.pyplot as plt
  6.  
  7. class IdentityMetadata():
  8. def __init__(self, base, name, file):
  9. # dataset base directory
  10. self.base = base
  11. # identity name
  12. self.name = name
  13. # image file name
  14. self.file = file
  15.  
  16. def __repr__(self):
  17. return self.image_path()
  18.  
  19. def image_path(self):
  20. return os.path.join(self.base, self.name, self.file)
  21.  
  22.  
  23. def load_metadata(path):
  24. metadata = []
  25. for i in os.listdir(path):
  26. for f in os.listdir(os.path.join(path, i)):
  27. metadata.append(IdentityMetadata(path, i, f))
  28. return np.array(metadata)
  29.  
  30.  
  31. metadata = load_metadata('Kaggle Dataset/Train')
  32.  
  33.  
  34.  
  35. def load_image(path):
  36. img = cv2.imread(path, 1)
  37. # OpenCV loads images with color channels
  38. # in BGR order. So we need to reverse them
  39. return img[...,::-1]
  40.  
  41. # Load and Plot an image from Dataset
  42. sample_image = load_image(metadata[11].image_path())
  43. plt.imshow(sample_image)
  44.  
  45. for i in range(metadata.size):
  46. print(i)
  47. #current_image = load_image(metadata[11].image_path())
  48. #plt.imshow(current_image)
Add Comment
Please, Sign In to add comment