# Collecting file directories into a dictionary oral_disease_file_names_dict = {} for img_dir in img_dirs: disease_name = img_dir.split('/')[-1] oral_disease_file_names_dict[disease_name] = [] for root, dirs, files in os.walk(img_dir): for file in files: if file.endswith(('.jpg', '.jpeg', '.png', '.bmp', '.gif')): file_path = os.path.join(root, file) oral_disease_file_names_dict[disease_name].append(file_path)