Trying to load Images and labels into a 2D array

Viewed 39

I have a folder of images I am trying to load into a 2D numpy array. The first dimension is the images and the 2nd dimension is the binary labels (1 or 0)

img_labels = []

for img in os.listdir(open_dir):
    open_img = cv2.imread(os.path.join(open_dir,img))
    open_img = cv2.resize(open_img,(IMAGE_SHAPE))
    np.append(img_labels, open_img, axis=0)
    np.append(img_labels, 1, axis=1)

for img in os.listdir(closed_dir):
    closed_img = cv2.imread(os.path.join(closed_dir ,img))
    closed_img = cv2.resize(closed_img,(IMAGE_SHAPE))
    np.append(img_labels, closed_img, axis=0)
    np.append(img_labels, 0, axis=1)

However when I try to do this i get the below ValueError

ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 2 dimension(s) and the array at index 1 has 3 dimension(s)

0 Answers
Related