(path, image_size=None)
return [X,y,folder_names]
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, folder_names]

            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.
            folder_names: The names of the folder, so you can display it in a prediction.
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, image_size=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, folder_names]

            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.
            folder_names: The names of the folder, so you can display it in a prediction.
    """
    c = 0
    X = []
    y = []
    folder_names = []
    for dirname, dirnames, filenames in os.walk(path):
        for subdirname in dirnames:
            folder_names.append(subdirname)
            subject_path = os.path.join(dirname, subdirname)
            for filename in os.listdir(subject_path):
                try:
                    im = cv2.imread(os.path.join(subject_path, filename), cv2.IMREAD_GRAYSCALE)
                    # resize to given size (if given)
                    if (image_size is not None):
                        im = cv2.resize(im, image_size)
                    X.append(np.asarray(im, dtype=np.uint8))
                    y.append(c)
                except IOError, (errno, strerror):
                    print "I/O error({0}): {1}".format(errno, strerror)
                except:
                    print "Unexpected error:", sys.exc_info()[0]
                    raise
            c = c+1
    return [X,y,folder_names]
def read_images ( path , image_size = None ) : c = 0 X = [ ] y = [ ] folder_names = [ ] for dirname , dirnames , filenames in os . walk ( path ) : for subdirname in dirnames : folder_names . append ( subdirname ) subject_path = os . path . join ( dirname , subdirname ) for filename in os . listdir ( subject_path ) : try : im = cv2 . imread ( os . path . join ( subject_path , filename ) , cv2 . IMREAD_GRAYSCALE ) # resize to given size (if given) if ( image_size is not None ) : im = cv2 . resize ( im , image_size ) X . append ( np . asarray ( im , dtype = np . uint8 ) ) y . append ( c ) except IOError , ( errno , strerror ) : print "I/O error({0}): {1}" . format ( errno , strerror ) except : print "Unexpected error:" , sys . exc_info ( ) [ 0 ] raise c = c + 1 return [ X , y , folder_names ]