text_plain_output_1.png
from sklearn.utils import shuffle

import cv2

import os

labels = ['0', '1']
def load_images_from_directory(main_dirictory):
    total_labels = []
    images = []
    pathes = []
    total_normal = 0
    total_infected = 0
    folders = os.listdir(main_dirictory)
    for i, file in enumerate(folders):
        if file == 'IDC_regular_ps50_idx5':
            continue
        for lab in labels:
            full_path = main_dirictory + os.path.join(file, lab)
            for image in os.listdir(full_path):
                img = cv2.imread(full_path + '/' + image)
                img = cv2.resize(img, (50, 50))
                images.append(img)
                pathes.append(full_path + '/' + image)
                if lab == '0':
                    label = 0
                    total_normal += 1
                elif lab == '1':
                    label = 1
                    total_infected += 1
                total_labels.append(label)
    return shuffle(images, total_labels, pathes, random_state=756349782)
def get_Label(number):
    labels = {0: 'Uninfected', 1: 'Infected'}
    return labels[number]

images = images[0:150000]
all_labels = all_labels[0:150000]
pathes = pathes[0:150000]
print('Total Images :', len(images))
print('Total Labels :', len(all_labels))
print('Total Pathes', len(pathes))