forked from yfzhang/vehicle-motion-forecasting
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
201 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
*.pyc | ||
.ipynb_checkpoints/ | ||
__pycache__/ | ||
data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import logging | ||
from torch.utils.data import Dataset | ||
import os | ||
import scipy.io as sio | ||
#from skimage.transform import resize | ||
#from skimage.transform import rotate | ||
from PIL import Image | ||
import numpy as np | ||
from scipy import optimize | ||
|
||
np.set_printoptions(threshold=np.inf, suppress=True) | ||
import random | ||
import copy | ||
import math | ||
|
||
|
||
class OffroadLoader(Dataset): | ||
def __init__(self, grid_size, train=True, demo=None, datadir='/root/medirl/data/', pre_train=False, tangent=False, | ||
more_kinematic=None): | ||
assert grid_size % 2 == 0, "grid size must be even number" | ||
self.grid_size = grid_size | ||
if train: | ||
self.data_dir = datadir + 'train_data/' | ||
else: | ||
self.data_dir = datadir + 'test_data/' | ||
|
||
if demo is not None: | ||
self.data_dir = datadir + '/irl_data/' + demo | ||
|
||
items = os.listdir(self.data_dir) | ||
self.data_list = [] | ||
for item in items: | ||
self.data_list.append(self.data_dir + '/' + item) | ||
|
||
#self.data_normalization = sio.loadmat(datadir + '/irl_data/train-data-mean-std.mat') | ||
self.pre_train = pre_train | ||
|
||
# kinematic related feature | ||
self.center_idx = self.grid_size / 2 | ||
|
||
|
||
def __getitem__(self, index): | ||
data_mat = sio.loadmat(self.data_list[index]) | ||
feat, robot_state_feat, past_traj, future_traj = data_mat['feat'].copy(), data_mat['robot_state_data'], data_mat['past_traj'], data_mat['future_traj'] | ||
# visualize rgb | ||
feat = np.vstack((feat, np.expand_dims(feat[2], axis=0))) | ||
feat = np.vstack((feat, np.expand_dims(feat[3], axis=0))) | ||
feat = np.vstack((feat, np.expand_dims(feat[4], axis=0))) | ||
# normalize features locally | ||
for i in range(5): | ||
feat[i] = (feat[i] - np.mean(feat[i])) / np.std(feat[i]) | ||
# normalize robot state feature locally | ||
robot_state_feat = (robot_state_feat - np.mean(robot_state_feat, axis=0, keepdims=True)) / np.std(robot_state_feat, axis=0, keepdims=True) | ||
|
||
|
||
if self.pre_train: | ||
target = data_mat['feat'][1].copy() # copy the variance layer first | ||
target[target < 0.5] = 0.0 | ||
target[target >= 0.5] = -1.0 | ||
return feat, target | ||
|
||
future_traj = self.auto_pad_future(future_traj[:, :2]) | ||
past_traj = self.auto_pad_past(past_traj[:, :2]) | ||
|
||
return feat, past_traj, future_traj, robot_state_feat | ||
|
||
def __len__(self): | ||
return len(self.data_list) | ||
|
||
def auto_pad_past(self, traj): | ||
""" | ||
add padding (NAN) to traj to keep traj length fixed. | ||
traj shape needs to be fixed in order to use batch sampling | ||
:param traj: numpy array. (traj_len, 2) | ||
:return: | ||
""" | ||
fixed_len = self.grid_size | ||
if traj.shape[0] >= self.grid_size: | ||
traj = traj[traj.shape[0]-self.grid_size:, :] | ||
#raise ValueError('traj length {} must be less than grid_size {}'.format(traj.shape[0], self.grid_size)) | ||
pad_len = self.grid_size - traj.shape[0] | ||
pad_array = np.full((pad_len, 2), np.nan) | ||
output = np.vstack((traj, pad_array)) | ||
return output | ||
|
||
def auto_pad_future(self, traj): | ||
""" | ||
add padding (NAN) to traj to keep traj length fixed. | ||
traj shape needs to be fixed in order to use batch sampling | ||
:param traj: numpy array. (traj_len, 2) | ||
:return: | ||
""" | ||
fixed_len = self.grid_size | ||
if traj.shape[0] >= self.grid_size: | ||
traj = traj[:self.grid_size, :] | ||
#raise ValueError('traj length {} must be less than grid_size {}'.format(traj.shape[0], self.grid_size)) | ||
pad_len = self.grid_size - traj.shape[0] | ||
pad_array = np.full((pad_len, 2), np.nan) | ||
output = np.vstack((traj, pad_array)) | ||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import logging | ||
from torch.utils.data import Dataset | ||
import os | ||
import scipy.io as sio | ||
#from skimage.transform import resize | ||
#from skimage.transform import rotate | ||
from PIL import Image | ||
import numpy as np | ||
from scipy import optimize | ||
from IPython import embed | ||
np.set_printoptions(threshold=np.inf, suppress=True) | ||
import random | ||
import copy | ||
import math | ||
|
||
|
||
class OffroadLoader(Dataset): | ||
def __init__(self, grid_size, train=True, demo=None, datadir='/root/medirl/data/', pre_train=False, tangent=False, | ||
more_kinematic=None): | ||
assert grid_size % 2 == 0, "grid size must be even number" | ||
self.grid_size = grid_size | ||
self.image_fol = datadir + "demo_0" | ||
#self.data_normalization = sio.loadmat(datadir + '/irl_data/train-data-mean-std.mat') | ||
self.pre_train = pre_train | ||
|
||
# kinematic related feature | ||
self.center_idx = self.grid_size / 2 | ||
|
||
|
||
def __getitem__(self, index): | ||
goal_sink_feat = np.array(Image.open(self.image_fol+"/goal_sink.png")) | ||
semantic_img_feat = np.array(Image.open(self.image_fol+"/semantic_img.png"))[:,:,0:3] | ||
with open(self.image_fol+"/trajectory.npy", 'rb') as f: | ||
traj = np.load(f) | ||
# visualize rgb | ||
feat = np.concatenate((goal_sink_feat, semantic_img_feat), axis = 2).T | ||
# normalize features locally | ||
for i in range(6): | ||
feat[i] = (feat[i] - np.mean(feat[i])) / np.std(feat[i]) | ||
|
||
|
||
|
||
|
||
return feat, traj | ||
|
||
def __len__(self): | ||
return len(self.data_list) | ||
|
||
def auto_pad_past(self, traj): | ||
""" | ||
add padding (NAN) to traj to keep traj length fixed. | ||
traj shape needs to be fixed in order to use batch sampling | ||
:param traj: numpy array. (traj_len, 2) | ||
:return: | ||
""" | ||
fixed_len = self.grid_size | ||
if traj.shape[0] >= self.grid_size: | ||
traj = traj[traj.shape[0]-self.grid_size:, :] | ||
#raise ValueError('traj length {} must be less than grid_size {}'.format(traj.shape[0], self.grid_size)) | ||
pad_len = self.grid_size - traj.shape[0] | ||
pad_array = np.full((pad_len, 2), np.nan) | ||
output = np.vstack((traj, pad_array)) | ||
return output | ||
|
||
def auto_pad_future(self, traj): | ||
""" | ||
add padding (NAN) to traj to keep traj length fixed. | ||
traj shape needs to be fixed in order to use batch sampling | ||
:param traj: numpy array. (traj_len, 2) | ||
:return: | ||
""" | ||
fixed_len = self.grid_size | ||
if traj.shape[0] >= self.grid_size: | ||
traj = traj[:self.grid_size, :] | ||
#raise ValueError('traj length {} must be less than grid_size {}'.format(traj.shape[0], self.grid_size)) | ||
pad_len = self.grid_size - traj.shape[0] | ||
pad_array = np.full((pad_len, 2), np.nan) | ||
output = np.vstack((traj, pad_array)) | ||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
-- jupyter | ||
-- cython | ||
-- numpy=1.15.4 | ||
-- numpy==1.15.4 | ||
-- numba==0.50.1 | ||
-- matplotlib=2.1.2 | ||
-- scipy=1.0.0 | ||
-- matplotlib==2.1.2 | ||
-- scipy==1.0.0 | ||
-- seaborn==0.9.0 | ||
-- tqdm=4.19.4 | ||
-- visdom==0.1.8.3 | ||
-- tqdm==4.19.4 | ||
-- visdom==0.1.8.3 | ||
-- scikit-image==0.14.1 |