| 35 | return imgs |
| 36 | |
| 37 | def loadLabelSet(which=0): |
| 38 | print "load label set" |
| 39 | binfile=None |
| 40 | if which==0: |
| 41 | binfile = open("data/train-labels.idx1-ubyte", 'rb') |
| 42 | else: |
| 43 | binfile= open("data/t10k-labels.idx1-ubyte", 'rb') |
| 44 | buffers = binfile.read() |
| 45 | |
| 46 | head = struct.unpack_from('>II' , buffers ,0) |
| 47 | print "head,",head |
| 48 | imgNum=head[1] |
| 49 | |
| 50 | offset = struct.calcsize('>II') |
| 51 | numString='>'+str(imgNum)+"B" |
| 52 | labels= struct.unpack_from(numString , buffers , offset) |
| 53 | binfile.close() |
| 54 | labels=np.reshape(labels,[imgNum,1]) |
| 55 | |
| 56 | #print labels |
| 57 | print 'load label finished' |
| 58 | return labels |
| 59 | |
| 60 | def get_features(imgs): |
| 61 | features = [] |