'**SUMMARY**
This function loads up files automatically from the directory you pass
it.  If you give it an extension it will only load that extension
otherwise it will try to load all know file types in that directory.
extension should be in the format:
extension = \'png\'
**PARAMETERS**
* *directory* - The path or directory from which to load images.
* *extension* - The extension to use. If none is given png is the default.
* *sort_by* - Sort the directory based on one of the following parameters passed as strings.
* *time* - the modification time of the file.
* *name* - the name of the file.
* *size* - the size of the file.
The default behavior is to leave the directory unsorted.
**RETURNS**
The number of images in the image set.
**EXAMPLE**
>>> imgs = ImageSet()
>>> imgs.load("images/faces")
>>> imgs.load("images/eyes", "png")'

def load(self, directory=None, extension=None, sort_by=None):

    if (not directory):
        logger.warning('You    need    to    give    a    directory    to    load    files    from.')
        return
    if (not os.path.exists(directory)):
        logger.warning('Invalid    image    path    given.')
        return
    if extension:
        regexList = [((('[' + letter) + letter.upper()) + ']') for letter in extension]
        regex = ''.join(regexList)
        regex = ('*.' + regex)
        formats = [os.path.join(directory, regex)]
    else:
        formats = [os.path.join(directory, x) for x in IMAGE_FORMATS]
    file_set = [glob.glob(p) for p in formats]
    full_set = []
    for f in file_set:
        for i in f:
            full_set.append(i)
    file_set = full_set
    if (sort_by is not None):
        if (sort_by.lower() == 'time'):
            file_set = sorted(file_set, key=os.path.getmtime)
        if (sort_by.lower() == 'name'):
            file_set = sorted(file_set)
        if (sort_by.lower() == 'size'):
            file_set = sorted(file_set, key=os.path.getsize)
    self.filelist = dict()
    for i in file_set:
        tmp = None
        try:
            tmp = Image(i)
            if ((tmp is not None) and (tmp.width > 0) and (tmp.height > 0)):
                if ((sys.platform.lower() == 'win32') or (sys.platform.lower() == 'win64')):
                    self.filelist[tmp.filename.split('\\')[(-1)]] = tmp
                else:
                    self.filelist[tmp.filename.split('/')[(-1)]] = tmp
                self.append(tmp)
        except:
            continue
    return len(self)
