forked from hitersyw/Hybrid-MPNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_loader_r3d.py
170 lines (148 loc) · 4.75 KB
/
data_loader_r3d.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
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
import torch
import torch.utils.data as data
import os
import pickle
import numpy as np
#import nltk
#from PIL import Image
import os.path
import random
from torch.autograd import Variable
import torch.nn as nn
import math
import gc
#N=number of environments; NP=Number of Paths
def load_dataset(N=100,NP=4000,folder='../data/simple/',s=0):
# load data as [path]
# for each path, it is
# [[input],[target],[env_id]]
obs = []
# add start s
for i in range(0,N):
#load obstacle point cloud
temp=np.fromfile(folder+'obs_cloud/obc'+str(i+s)+'.dat')
obs.append(temp)
obs = np.array(obs)
## calculating length of the longest trajectory
max_length=0
path_lengths=np.zeros((N,NP),dtype=np.int8)
for i in range(0,N):
for j in range(0,NP):
fname=folder+'e'+str(i+s)+'/path'+str(j)+'.dat'
if os.path.isfile(fname):
path=np.fromfile(fname)
path=path.reshape(len(path)//3,3)
path_lengths[i][j]=len(path)
if len(path)> max_length:
max_length=len(path)
paths=np.zeros((N,NP,max_length,3), dtype=np.float32) ## padded paths
for i in range(0,N):
for j in range(0,NP):
fname=folder+'e'+str(i+s)+'/path'+str(j)+'.dat'
if os.path.isfile(fname):
path=np.fromfile(fname)
path=path.reshape(len(path)//3,3)
for k in range(0,len(path)):
paths[i][j][k]=path[k]
path_data = []
for i in range(0,N):
for j in range(0,NP):
dataset=[]
targets=[]
env_indices=[]
if path_lengths[i][j]>0:
for m in range(0, path_lengths[i][j]-1):
data = np.concatenate( (paths[i][j][m], paths[i][j][path_lengths[i][j]-1]) ).astype(np.float32)
targets.append(paths[i][j][m+1])
dataset.append(data)
env_indices.append(i)
path_data.append([dataset, targets, env_indices])
# only return raw data (in order), follow below to randomly shuffle
return obs, path_data
# data=list(zip(dataset,targets))
# random.shuffle(data)
# dataset,targets=list(zip(*data))
# dataset and targets are both list
# here the first item of data is index in obs
# return obs, list(zip(*data))
def load_raw_dataset(N=100,NP=4000,s=0,sp=0,folder='../data/simple/'):
obc=np.zeros((N,10,3),dtype=np.float32)
temp=np.fromfile(folder+'obs.dat')
obs=temp.reshape(len(temp)//3,3)
temp=np.fromfile(folder+'obs_perm2.dat',np.int32)
perm=temp.reshape(184756,10)
## loading obstacles
for i in range(0,N):
for j in range(0,10):
for k in range(0,3):
obc[i][j][k]=obs[perm[i+s][j]][k]
obs = []
k=0
for i in range(s,s+N):
temp=np.fromfile(folder+'obs_cloud/obc'+str(i)+'.dat')
obs.append(temp)
obs = np.array(obs).astype(np.float32)
## calculating length of the longest trajectory
max_length=0
path_lengths=np.zeros((N,NP),dtype=np.int8)
for i in range(0,N):
for j in range(0,NP):
fname=folder+'e'+str(i+s)+'/path'+str(j+sp)+'.dat'
if os.path.isfile(fname):
path=np.fromfile(fname)
path=path.reshape(len(path)//3,3)
path_lengths[i][j]=len(path)
if len(path)> max_length:
max_length=len(path)
paths=np.zeros((N,NP,max_length,3), dtype=np.float32) ## padded paths
for i in range(0,N):
for j in range(0,NP):
fname=folder+'e'+str(i+s)+'/path'+str(j+sp)+'.dat'
if os.path.isfile(fname):
path=np.fromfile(fname)
path=path.reshape(len(path)//3,3)
for k in range(0,len(path)):
paths[i][j][k]=path[k]
return obc,obs,paths,path_lengths
#N=number of environments; NP=Number of Paths; s=starting environment no.; sp=starting_path_no
#Unseen_environments==> N=10, NP=2000,s=100, sp=0
#seen_environments==> N=100, NP=200,s=0, sp=4000
def load_test_dataset(N=100,NP=200, s=0,sp=4000, folder='../data/simple/'):
obc=np.zeros((N,10,3),dtype=np.float32)
temp=np.fromfile(folder+'obs.dat')
obs=temp.reshape(len(temp)//3,3)
temp=np.fromfile(folder+'obs_perm2.dat',np.int32)
perm=temp.reshape(184756,10)
## loading obstacles
for i in range(0,N):
for j in range(0,10):
for k in range(0,3):
obc[i][j][k]=obs[perm[i+s][j]][k]
obs = []
k=0
for i in range(s,s+N):
temp=np.fromfile(folder+'obs_cloud/obc'+str(i)+'.dat')
obs.append(temp)
obs = np.array(obs).astype(np.float32)
## calculating length of the longest trajectory
max_length=0
path_lengths=np.zeros((N,NP),dtype=np.int8)
for i in range(0,N):
for j in range(0,NP):
fname=folder+'e'+str(i+s)+'/path'+str(j+sp)+'.dat'
if os.path.isfile(fname):
path=np.fromfile(fname)
path=path.reshape(len(path)//3,3)
path_lengths[i][j]=len(path)
if len(path)> max_length:
max_length=len(path)
paths=np.zeros((N,NP,max_length,3), dtype=np.float32) ## padded paths
for i in range(0,N):
for j in range(0,NP):
fname=folder+'e'+str(i+s)+'/path'+str(j+sp)+'.dat'
if os.path.isfile(fname):
path=np.fromfile(fname)
path=path.reshape(len(path)//3,3)
for k in range(0,len(path)):
paths[i][j][k]=path[k]
return obc,obs,paths,path_lengths