(path, sz=None)
return [X,y]
Reads the images in a given folder, resizes images on the fly if size is given.

    Args:
        path: Path to a folder with subfolders representing the subjects (persons).
        sz: A tuple with the size Resizes 

    Returns:
        A list [X,y]

            X: The images, which is a Python list of numpy arrays.
            y: The corresponding labels (the unique number of the subject, person) in a Python list.
Reads the images in a given folder, resizes images on the fly if size is given.
Reads the images in a given folder resizes images on the fly if size is given .
def read_images(path, sz=None):
    """Reads the images in a given folder, resizes images on the fly if size is given.

    Args:
        path: Path to a folder with subfolders representing the subjects (persons).
        sz: A tuple with the size Resizes 

    Returns:
        A list [X,y]

            X: The images, which is a Python list of numpy arrays.
            y: The corresponding labels (the unique number of the subject, person) in a Python list.
    """
    c = 0
    X,y = [], []
    for dirname, dirnames, filenames in os.walk(path):
        for subdirname in dirnames:
            subject_path = os.path.join(dirname, subdirname)
            for filename in os.listdir(subject_path):
                try:
                    im = Image.open(os.path.join(subject_path, filename))
                    im = im.convert("L")
                    # resize to given size (if given)
                    if (sz is not None):
                        im = im.resize(sz, Image.ANTIALIAS)
                    X.append(np.asarray(im, dtype=np.uint8))
                    y.append(c)
                except IOError as e:
                    print("I/O error: {0}".format(e))
                    raise e
                except:
                    print("Unexpected error: {0}".format(sys.exc_info()[0]))
                    raise
            c = c+1
    return [X,y]
def read_images ( path , sz = None ) : c = 0 X , y = [ ] , [ ] for dirname , dirnames , filenames in os . walk ( path ) : for subdirname in dirnames : subject_path = os . path . join ( dirname , subdirname ) for filename in os . listdir ( subject_path ) : try : im = Image . open ( os . path . join ( subject_path , filename ) ) im = im . convert ( "L" ) # resize to given size (if given) if ( sz is not None ) : im = im . resize ( sz , Image . ANTIALIAS ) X . append ( np . asarray ( im , dtype = np . uint8 ) ) y . append ( c ) except IOError as e : print ( "I/O error: {0}" . format ( e ) ) raise e except : print ( "Unexpected error: {0}" . format ( sys . exc_info ( ) [ 0 ] ) ) raise c = c + 1 return [ X , y ]