Created
July 13, 2021 07:44
-
-
Save AmrutaKoshe/bdf092b823186da9b1f9ca32af977908 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_images(): | |
Images, Labels = [], [] | |
for root, dirs, files in os.walk('gems/train/'): | |
f = os.path.basename(root) # get class name - Amethyst, Onyx, etc | |
for file in files: | |
Labels.append(f) | |
try: | |
image = cv2.imread(root+'/'+file) # read the image (OpenCV) | |
image = cv2.resize(image,(int(img_w), int(img_h))) # resize the image (images are different sizes) | |
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # converts an image from BGR color space to RGB | |
Images.append(image) | |
except Exception as e: | |
print(e) | |
Images = np.array(Images) | |
return (Images,Labels) | |
def get_class_index(Labels): | |
for i, n in enumerate(Labels): | |
for j, k in enumerate(Name): # foreach CLASSES | |
if n == k: | |
Labels[i] = j | |
Labels = np.array(Labels) | |
return Labels |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment