-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_unPickle.py
More file actions
85 lines (53 loc) · 1.9 KB
/
new_unPickle.py
File metadata and controls
85 lines (53 loc) · 1.9 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- 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, the_relation_file ):
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()
for eachSample in unpickleList:
inputMatrix.append(eachSample[:])
lengthOfInput = len(inputMatrix[0])
relation = load(the_relation_file)
targetResult = next(relation)
#targetResultNDarray = np.array(targetResult, dtype=np.int64)
inputMatrixNDarray = np.array(inputMatrix, dtype=np.float64)
targetResultNDarray = np.array(targetResult, dtype=np.int64)
theanoMatchedInput = (inputMatrixNDarray, targetResultNDarray)
return (theanoMatchedInput, lengthOfInput)
#
# 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('valid','valid_relation')
print (b)
#c = mnistCompare ('mnist.pkl.gz')