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')
     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' ) 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 ]
reads the images in a given folder .