from tensorflow.keras.preprocessing.image import img_to_array, load_img
img = load_img('datasets/images/food5k/evaluation/food/0.jpg', target_size=(150,150))
img = img_to_array(img)
img.shape
(150, 150, 3)
import os
def input_target_split(train_dir,labels):
    dataset = []
    count = 0
    for label in labels:
        folder = os.path.join(train_dir,label)
        for image in os.listdir(folder):
            if os.path.isfile(os.path.join(folder,image)):
                img=load_img(os.path.join(folder,image), target_size=(150,150))
                img=img_to_array(img)
                img=img/255.0
                dataset.append((img,count))
        print(f'\rCompleted: {label}',end='')
        count+=1
    random.shuffle(dataset)
    return dataset
    #X, y = zip(*dataset)
    
    #return np.array(X),np.array(y)

dataset = input_target_split('datasets/images/rockpaperscissors', ['rock', 'paper', 'scissors'])
Completed: scissors
X,y = zip(*dataset)
y
(0,
 2,
 0,
 2,
 1,
 0,
 2,
 1,
 1,
 2,
 0,
 1,
 0,
 0,
 1,
 1,
 0,
 2,
 0,
 0,
 1,
 2,
 2,
 2,
 0,
 1,
 2,
 0,
 0,
 0,
 1,
 2,
 2,
 1,
 1,
 1,
 1,
 0,
 0,
 0,
 1,
 2,
 2,
 1,
 1,
 1,
 1,
 1,
 0,
 1,
 1,
 2,
 2,
 2,
 1,
 1,
 2,
 1,
 1,
 1,
 1,
 0,
 2,
 0,
 0,
 0,
 2,
 2,
 0,
 1,
 0,
 0,
 2,
 1,
 1,
 0,
 2,
 0,
 0,
 1,
 1,
 2,
 1,
 1,
 1,
 1,
 1,
 2,
 2,
 1,
 0,
 0,
 1,
 2,
 1,
 2,
 2,
 0,
 0,
 0,
 1,
 1,
 2,
 0,
 2,
 2,
 0,
 1,
 2,
 2,
 2,
 2,
 2,
 2,
 0,
 0,
 2,
 1,
 1,
 2,
 2,
 0,
 1,
 2,
 0,
 1,
 0,
 0,
 1,
 1,
 2,
 0,
 2,
 1,
 0,
 0,
 1,
 0,
 1,
 0,
 2,
 1,
 2,
 0,
 0,
 2,
 0,
 1,
 0,
 1,
 1,
 1,
 1,
 0,
 1,
 1,
 2,
 1,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