#NEWLINE# def load_dataset( basepath , datadir , shuffle ) : #NEWLINE# #INDENT# path = os . path . join ( basepath , datadir ) #NEWLINE# if ( not os . path . exists ( path ) ) : #NEWLINE# #INDENT# process ( basepath ) #NEWLINE# #UNINDENT# subdirs = glob ( os . path . join ( path , '*' ) ) #NEWLINE# labelnames = sorted ( map ( ( lambda x : os . path . basename ( x ) ) , subdirs ) ) #NEWLINE# inds = range ( len ( labelnames ) ) #NEWLINE# labeldict = { key : val for ( key , val ) in zip ( labelnames , inds ) } #NEWLINE# lines = [ ] #NEWLINE# for subdir in subdirs : #NEWLINE# #INDENT# subdirlabel = labeldict [ os . path . basename ( subdir ) ] #NEWLINE# files = glob ( os . path . join ( subdir , '*.png' ) ) #NEWLINE# lines += [ ( filename , subdirlabel ) for filename in files ] #NEWLINE# #UNINDENT# assert ( len ( lines ) > 0 ) #NEWLINE# data = None #NEWLINE# if shuffle : #NEWLINE# #INDENT# np . random . seed ( 0 ) #NEWLINE# np . random . shuffle ( lines ) #NEWLINE# #UNINDENT# for idx in range ( len ( lines ) ) : #NEWLINE# #INDENT# im = np . asarray ( Image . open ( lines [ idx ] [ 0 ] ) ) [ : , : , : : ( - 1 ) ] #NEWLINE# im = np . transpose ( im , axes = [ 2 , 0 , 1 ] ) . ravel ( ) #NEWLINE# if ( data is None ) : #NEWLINE# #INDENT# data = np . empty ( ( len ( lines ) , im . shape [ 0 ] ) , dtype = 'float32' ) #NEWLINE# labels = np . empty ( ( len ( lines ) , 1 ) , dtype = 'int32' ) #NEWLINE# #UNINDENT# data [ idx ] = im #NEWLINE# labels [ idx ] = lines [ idx ] [ 1 ] #NEWLINE# #UNINDENT# return ( data , shuffle )