Skip to content

Instantly share code, notes, and snippets.

@AmrutaKoshe
Created July 13, 2021 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmrutaKoshe/bdf092b823186da9b1f9ca32af977908 to your computer and use it in GitHub Desktop.
Save AmrutaKoshe/bdf092b823186da9b1f9ca32af977908 to your computer and use it in GitHub Desktop.
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