forked from matterport/Mask_RCNN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_reader.py
72 lines (68 loc) · 2.46 KB
/
data_reader.py
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
import csv
import numpy as np
import cv2
def read_data(file_path,header=True,delimiter=','):
# The read-in data should be a N*W matrix,
# where N is the length of the time sequences,
# W is the number of sensors/data features
i = 0
with open(file_path, 'r') as file:
reader = csv.reader(file, delimiter = delimiter)
data=[]
for line in reader:
if i == 0 and header:
i += +1
else:
line = np.array(line, dtype = 'float') # str2float
if i == 0 or (i == 1 and header):
data = line
else:
data = np.vstack((data, line))
i += 1
return data
def read_binary(file_path,header=True,delimiter=','):
# The read-in data should be a N*W matrix,
# where N is the length of the time sequences,
# W is the number of sensors/data features
i = 0
with open(file_path, 'r') as file:
reader = csv.reader(file, delimiter = delimiter)
data=[]
for line in reader:
if i == 0 and header:
i += +1
else:
for j, element in enumerate(line):
if element == 'True':
line[j] = True
elif element == 'False':
line[j] = False
else:
raise ValueError("Data type is not boolean!!")
line = np.array(line) # str2float
if i == 0 or (i == 1 and header):
data = line
else:
data = np.vstack((data, line))
i += 1
return data
def read_human_data(file_path,num_header=2,delimiter='\t'):
data = []
with open(file_path, 'r') as file:
reader = csv.reader(file, delimiter=delimiter)
for i,line in enumerate(reader):
if i >= num_header:
act = int(line[1])
x = float(line[3])
y = float(line[5])
vx = float(line[7])
# vy = float(line[8])
ax = float(line[9])
# ay = float(line[11])
# yaw =float([line[13]])
# yaw_dot =float([line[14]])
if i == num_header:
data = np.array([act,x,y,vx,ax])
else:
data = np.vstack([data, np.array([act,x,y,vx,ax])])
return data