-
Notifications
You must be signed in to change notification settings - Fork 6
/
get_data_pkl.py
68 lines (57 loc) · 2.73 KB
/
get_data_pkl.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
import importlib
import torch
from dataloader import Dataloader
from utils import seed, get_rng_state
import ipdb
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--train", nargs='+', default=[])
parser.add_argument("--test", nargs='+', default=[])
parser.add_argument("--frameskip", type=int, default=1)
parser.add_argument("--config", type=str, default=None)
parser.add_argument("--device", type=str, default=None)
parser.add_argument("--seed", type=int, default=1)
# python get_data_pkl.py --train data/eth/train --test data/eth/test --config config/eth.py
if __name__ == "__main__":
settings = parser.parse_args()
spec = importlib.util.spec_from_file_location("config", settings.config)
config = importlib.util.module_from_spec(spec)
spec.loader.exec_module(config)
if settings.device is None:
settings.device = "cuda" if torch.cuda.is_available() else "cpu"
settings.device = torch.device(settings.device)
seed(settings.seed)
init_rng_state = get_rng_state(settings.device)
rng_state = init_rng_state
###############################################################################
##### ######
##### prepare datasets ######
##### ######
###############################################################################
kwargs = dict(
batch_first=False, frameskip=settings.frameskip,
ob_horizon=config.OB_HORIZON, pred_horizon=config.PRED_HORIZON,
device=settings.device, seed=settings.seed)
train_data, test_data = None, None
if settings.test:
print(settings.test)
if config.INCLUSIVE_GROUPS is not None:
inclusive = [config.INCLUSIVE_GROUPS for _ in range(len(settings.test))]
else:
inclusive = None
test_dataset = Dataloader(
settings.test, **kwargs, inclusive_groups=inclusive,
batch_size=config.batch_size, shuffle=False, dataset_type='test', dataset_name=str(settings.test[0]).split('/')[1]
)
if settings.train:
print(settings.train)
if config.INCLUSIVE_GROUPS is not None:
inclusive = [config.INCLUSIVE_GROUPS for _ in range(len(settings.train))]
else:
inclusive = None
train_dataset = Dataloader(
settings.train, **kwargs, inclusive_groups=inclusive,
flip=True, rotate=True, scale=True,
batch_size=config.batch_size, shuffle=True, batches_per_epoch=config.EPOCH_BATCHES, dataset_type='train',
dataset_name=str(settings.train[0]).split('/')[1]
)