-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCSVHelper.py
More file actions
182 lines (131 loc) · 5.22 KB
/
CSVHelper.py
File metadata and controls
182 lines (131 loc) · 5.22 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
"""
@File: CSVHelper.py
@Date: Long long ago.
@Desc: CSVHelper.py by Dr. Marc Habermann; super cool stuff so that I decided directly to copy it from the original DeepCharacters Repo.
"""
########################################################################################################################
# Imports
########################################################################################################################
import numpy as np
########################################################################################################################
# 2D csv
########################################################################################################################
# Okey there is some minor changes
def load_csv_sequence_2D(filePath, type='int', skipRows=0, skipColumns=0, end_frame = 1145141919):
csvfile = open(filePath, 'rb')
dataset = []
length = 0
lineCounter = 0
realCounter = 0
for line in csvfile:
if lineCounter >= skipRows:
values = line.split()
length = len(values) - skipColumns
for column, valueString in enumerate(values):
if column >=skipColumns:
if(type == 'int'):
value = int(valueString)
else:
value = float(valueString)
dataset.append(value)
lineCounter = lineCounter + 1
realCounter += 1
if realCounter > (end_frame):
break
dataset = np.array(dataset)
dataset=np.reshape(dataset,(-1,length))
csvfile.close()
return dataset
########################################################################################################################
# 3D csv
########################################################################################################################
def load_csv_sequence_3D(filePath, batch1, type='int'):
csvfile = []
for b in range(0,batch1):
csvfile.append(open(filePath + str(b) + '.csv', 'rb'))
dataset = []
lineLength = 0
#go over the lines in all files in parallel
while 1:
#go over the files
for b in range(0, batch1):
line = csvfile[b].readline()
if not line:
break
values = line.split()
lineLength = len(values)
for valueString in values:
if (type == 'int'):
value = int(valueString)
else:
value = float(valueString)
dataset.append(value)
if not line:
break
dataset = np.array(dataset)
dataset = np.reshape(dataset, (-1, batch1, lineLength))
return dataset
########################################################################################################################
# 4D csv
########################################################################################################################
def load_csv_sequence_4D(filePath, batch1, batch2, batch3, type='int'):
csvfile = []
for b in range(0, batch1):
csvfile.append(open(filePath + str(b) + '.csv', 'rb'))
dataset = []
# go over the lines in all files in parallel
counter =0
while 1:
# go over the files
for b in range(0, batch1):
line = csvfile[b].readline()
if not line:
break
values = line.split()
for valueString in values:
if (type == 'int'):
try:
value = int(valueString)
except ValueError:
print(line)
else:
value = float(valueString)
dataset.append(value)
if not line:
break
counter = counter + 1
dataset = np.array(dataset)
dataset = np.reshape(dataset, (-1, batch1, batch2, batch3))
return dataset
########################################################################################################################
# 4D csv compact
########################################################################################################################
def load_csv_compact_4D(filePath, batch1, batch2, batch3, skipRows=0, skipColumns=0, type='int', end_frame = 1145141919):
csvfile = open(filePath, 'rb')
dataset = []
lineCounter = 0
realCounter = 0
# go over the lines in the file
while 1:
line = csvfile.readline()
if not line:
break
#skip first rows
if lineCounter >= skipRows:
values = line.split()
for c2, valueString in enumerate(values):
#skip columns
if c2 >= skipColumns:
if (type == 'int'):
value = int(valueString)
else:
value = float(valueString)
dataset.append(value)
lineCounter = lineCounter + 1
realCounter += 1
if realCounter > (end_frame):
break
dataset = np.array(dataset)
dataset = np.reshape(dataset, (-1, batch1, batch2, batch3))
csvfile.close()
return dataset