Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # /////////////////////////// Custom Dataset ///////////////////////////#
- import numpy as np
- import os.path
- import cv2
- import matplotlib.pyplot as plt
- class IdentityMetadata():
- def __init__(self, base, name, file):
- # dataset base directory
- self.base = base
- # identity name
- self.name = name
- # image file name
- self.file = file
- def __repr__(self):
- return self.image_path()
- def image_path(self):
- return os.path.join(self.base, self.name, self.file)
- def load_metadata(path):
- metadata = []
- for i in os.listdir(path):
- for f in os.listdir(os.path.join(path, i)):
- metadata.append(IdentityMetadata(path, i, f))
- return np.array(metadata)
- metadata = load_metadata('Kaggle Dataset/Train')
- def load_image(path):
- img = cv2.imread(path, 1)
- # OpenCV loads images with color channels
- # in BGR order. So we need to reverse them
- return img[...,::-1]
- # Load and Plot an image from Dataset
- sample_image = load_image(metadata[11].image_path())
- plt.imshow(sample_image)
- for i in range(metadata.size):
- print(i)
- #current_image = load_image(metadata[11].image_path())
- #plt.imshow(current_image)
Add Comment
Please, Sign In to add comment