| 5 | from perceptron import * |
| 6 | |
| 7 | def loadImageSet(which=0): |
| 8 | print "load image set" |
| 9 | binfile=None |
| 10 | if which==0: |
| 11 | binfile = open("data/train-images.idx3-ubyte", 'rb') |
| 12 | else: |
| 13 | binfile= open("data/t10k-images.idx3-ubyte", 'rb') |
| 14 | buffers = binfile.read() |
| 15 | |
| 16 | head = struct.unpack_from('>IIII' , buffers ,0) |
| 17 | print "head,",head |
| 18 | |
| 19 | offset=struct.calcsize('>IIII') |
| 20 | imgNum=head[1] |
| 21 | width=head[2] |
| 22 | height=head[3] |
| 23 | #[60000]*28*28 |
| 24 | bits=imgNum*width*height |
| 25 | bitsString='>'+str(bits)+'B' #like '>47040000B' |
| 26 | |
| 27 | imgs=struct.unpack_from(bitsString,buffers,offset) |
| 28 | |
| 29 | binfile.close() |
| 30 | imgs=np.reshape(imgs,[imgNum,width,height]) |
| 31 | print "load imgs finished" |
| 32 | return imgs |
| 33 | |
| 34 | def loadLabelSet(which=0): |
| 35 | print "load label set" |