MCPcopy Create free account
hub / github.com/WenDesi/lihang_book_algorithm / loadImageSet

Function loadImageSet

main.py:7–32  ·  view source on GitHub ↗
(which=0)

Source from the content-addressed store, hash-verified

5from perceptron import *
6
7def 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
34def loadLabelSet(which=0):
35 print "load label set"

Callers 1

main.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected