-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunPickle.py
More file actions
67 lines (35 loc) · 1.26 KB
/
unPickle.py
File metadata and controls
67 lines (35 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 29 14:39:24 2016
@author: yiz613
"""
import pickle
import numpy as np
import gzip
def convertData( inputDataFile ):
def load(filename):
with open(filename, "rb") as f:
while True:
try:
yield pickle.load(f)
except EOFError:
break
items = load(inputDataFile)
unpickleList=list(items)
inputMatrix=list()
targetResult = list()
for eachSample in unpickleList:
targetResult.append(eachSample[0])
inputMatrix.append(eachSample[1:])
lengthOfInput = len(inputMatrix[0])
targetResultNDarray = np.array(targetResult, dtype=np.int64)
inputMatrixNDarray = np.array(inputMatrix, dtype=np.float64)
theanoMatchedInput = (inputMatrixNDarray, targetResultNDarray)
return (theanoMatchedInput, lengthOfInput)
def mnistCompare (inputFile):
with gzip.open(inputFile, 'rb') as f:
a = pickle.load(f, encoding='latin1')
return a
if __name__ == "__main__":
a,b = convertData('encoded_test_pickle')
c = mnistCompare ('mnist.pkl.gz')