<s> import numpy as np <EOL> import os <EOL> class DataLoader : <EOL> def __init__ ( self , filedir , rawsize , imgsize ) : <EOL> self . filedir = filedir <EOL> self . rawsize = rawsize <EOL> self . imgsize = imgsize <EOL> def loadDataFile ( self , filenum ) : <EOL> keyfile = self . filedir + '<STR_LIT>' % filenum <EOL> alisfile = self . filedir + '<STR_LIT>' % filenum <EOL> datafile = self . filedir + '<STR_LIT>' % filenum <EOL> keys = None <EOL> sizes = None <EOL> if os . path . exists ( keyfile ) : <EOL> keyf = open ( keyfile , '<STR_LIT:r>' ) <EOL> uttdat = [ u . split ( ) for u in keyf . readlines ( ) ] <EOL> keyf . close ( ) <EOL> sizes = [ int ( u [ <NUM_LIT:1> ] ) for u in uttdat ] <EOL> sizes = np . array ( sizes ) <EOL> keys = [ u [ <NUM_LIT:0> ] for u in uttdat ] <EOL> left = ( self . rawsize - self . imgsize ) / <NUM_LIT:2> <EOL> right = left + self . imgsize <EOL> data = np . fromfile ( datafile , np . float32 ) . reshape ( - <NUM_LIT:1> , self . rawsize ) <EOL> data = data [ : np . sum ( sizes ) , left : right ] <EOL> alis = np . loadtxt ( alisfile , np . int32 , usecols = [ <NUM_LIT:0> ] ) <EOL> alis = alis [ : np . sum ( sizes ) ] <EOL> return data . T , alis , keys , sizes <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> dataDir = "<STR_LIT>" <EOL> rawSize = <NUM_LIT> * <NUM_LIT> <EOL> inputSize = rawSize <EOL> dl = DataLoader ( dataDir , rawSize , inputSize ) <EOL> filenum = <NUM_LIT:1> <EOL> data , alis , _ , _ = dl . loadDataFile ( filenum ) <EOL> print data . shape <EOL> print alis . shape </s>
