#NEWLINE# def _cohn_kanade( datadir , im_shape , na_val = ( - 1 ) ) : #NEWLINE# #INDENT# 'Creates dataset (pair of X and y) from Cohn-Kanade\n    image data (CK+)' #NEWLINE# images = [ ] #NEWLINE# labels = [ ] #NEWLINE# for name in os . listdir ( os . path . join ( datadir , 'faces' ) ) : #NEWLINE# #INDENT# impath = os . path . join ( datadir , 'faces' , name ) #NEWLINE# labelpath = os . path . join ( datadir , 'labels' , name . replace ( '.png' , '_emotion.txt' ) ) #NEWLINE# im = imread ( impath ) #NEWLINE# if ( len ( im . shape ) > 2 ) : #NEWLINE# #INDENT# im = cv2 . cvtColor ( im , cv2 . COLOR_BGR2GRAY ) #NEWLINE# #UNINDENT# im = cv2 . resize ( im , im_shape ) #NEWLINE# im = cv2 . equalizeHist ( im ) #NEWLINE# im = ( im . astype ( np . float32 ) / im . max ( ) ) #NEWLINE# images . append ( im . reshape ( 1 , ( - 1 ) ) ) #NEWLINE# if os . path . exists ( labelpath ) : #NEWLINE# #INDENT# with open ( labelpath ) as lf : #NEWLINE# #INDENT# label = int ( float ( lf . read ( ) . strip ( ) ) ) #NEWLINE# labels . append ( label ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# labels . append ( na_val ) #NEWLINE# #UNINDENT# #UNINDENT# return ( np . vstack ( images ) , np . array ( labels ) )