fork download
  1. #!/usr/bin/env python3
  2.  
  3. import sys
  4. import numpy as np
  5. from random import randrange
  6. from matplotlib import pyplot as plt
  7. from matplotlib import image
  8. from scipy.special import expit
  9. import gzip
  10. import struct
  11.  
  12. HIDDEN = 200
  13.  
  14. files = [
  15. "../t10k-images-idx3-ubyte.gz",
  16. "../train-images-idx3-ubyte.gz",
  17. "../t10k-labels-idx1-ubyte.gz",
  18. "../train-labels-idx1-ubyte.gz"
  19. ]
  20.  
  21. def train():
  22.  
  23. with gzip.open(files[1],'rb') as fd:
  24. all = fd.read()
  25.  
  26. eoh = 16
  27. header = struct.unpack('>iiii',all[:eoh])
  28. print("header " + str(header))
  29.  
  30. imagesize = header[2]*header[3]
  31. #imagesize = 28*28 # 784 pixels
  32. print("imagesize " + str(imagesize) )
  33.  
  34.  
  35. #initializing
  36. pixno = 0
  37. startpos = eoh + imagesize * pixno
  38. endpos = startpos + imagesize
  39. trainImages = np.empty([60000, 28, 28])
  40.  
  41.  
  42. for i in range(0, header[1]):
  43. a1 = all[startpos:endpos]
  44. a2 = struct.unpack('784B', a1)
  45. a3 = np.array(a2).reshape(28,28)
  46. trainImages[i] = a3
  47. startpos = endpos + 1
  48. endpos = startpos + imagesize
  49. # print("count = =" + str(count))
Success #stdin #stdout 2.3s 63652KB
stdin
Standard input is empty
stdout
Standard output is empty