import os  # for reading files and directories
import numpy as np  # for arrays

"""DatasetReader: reads dataset images and texts into numpy arrays.
Also, an optional normalization can be applied over all the data."""


class DatasetReader:

    def __init__(self, dataset, path=None, normalize=True):
        """ __dataset = (str) dataset type: ['cub',  'oxford-102']
            __path = (str) path to the dataset. If not specified, it will look to './datasets/{cub | oxford-102}'
            __normalization = (bool) if True, normalizes all the images of the dataset to be [-1, 1]."""

        # Check that dataset type is valid
        dataset = dataset.lower()
        assert dataset == 'cub' or dataset == 'oxford-102', \
            "Dataset not recognized: %s. Must be 'cub' or 'oxford-102'" % dataset

        self.__dataset = dataset

        # Initialize path, if not specified
        if path is None:
            self.__path =  os.path.abspath(__file__ + "/../../") + '/datasets/' + self.__dataset

        # Check if path exists
        assert os.path.exists(self.__path), "Path %s does not exist" % self.__path

        self.__normalize = normalize

    def read(self):
        """Reads the images and texts of the dataset found in self.__path.
        Output:
            · images: numpy array N x height x width x color, where N is the number of samples
            · texts: numpy array NxM, where M is the dimensionality of the texts.
            · labels: """

        if self.__dataset == 'cub':
            images, texts, labels = self.__read_cub_dataset()
        else:
            images, texts, labels = self.__read_oxford_dataset()

        # The normalization can be performed here as long as the image format of both datasets is the same.
        # If not, normalization will be performed inside each dataset specific methods.

        return images, texts, labels

    def method(self):
        """Input:
                - blabla:
           Output:
                - blabla: """
        pass

if __name__ == '__main__':
    pass
@@ -1886,16 +1886,1721 @@
 labels%0A%0A
+    def __read_cub_dataset(self):%0A%0A        assert self.__path + %22/images_and_texts%22, %22Didn't find images_and_texts folder in %25s%22 %25 self.__path%0A%0A        # List all files%0A        folder_list = os.listdir(self.__path + %22/images_and_texts%22)%0A        folder_list.sort()%0A        folder_iterator = filter(lambda element: os.path.isdir(self.__path + %22/images_and_texts/%22 + element), folder_list)%0A%0A        label_idx = 0%0A        for folder in folder_iterator: # Every folder contains images from the same label / class%0A%0A            # List all images and text files within the folder%0A            file_list = os.listdir(self.__path + %22/images_and_texts/%22 + folder)%0A            file_list.sort() # Order is important because image and text files need to match%0A%0A            # Filter images and texts using their extension%0A            im_iterator = filter(lambda x: x.endswith(('.jpg')), file_list)%0A            txt_iterator = filter(lambda x: x.endswith(('.txt')), file_list)%0A%0A            for im_file, txt_file in zip(im_iterator, txt_iterator):%0A%0A                # Sanity check: make sure image and text file match%0A                tmp1 = im_file%0A                tmp2 = txt_file%0A                assert tmp1.rsplit( %22.%22, 1)%5B0%5D == tmp2.rsplit( %22.%22, 1)%5B0%5D, (%22Image '%25s' and text file '%25s' don't %22 + %5C%0A                         %22have the same name.%5Cn%22 + %5C%0A                        %22 It seems that some file is missing, you should check or download again the CUB dataset.%22) %5C%0A                        %25 (im_file, txt_file)%0A%0A                # Read image%0A%0A                # Read texts%0A%0A                # Set label%0A%0A            label_idx += 1%0A%0A        return images, texts, labels%0A%0A%0A    def __read_oxford_dataset(self):%0A        pass%0A%0A
     def 

Add logic to iterate through folders and image / text files