-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheil_train.py
97 lines (82 loc) · 2.67 KB
/
eil_train.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
""" EIL training script. """
import os.path as osp
import subprocess
from absl import app
from absl import flags
from absl import logging
from configs.constants import ALGORITHMS
from torchkit.experiment import unique_id
import yaml
# pylint: disable=logging-fstring-interpolation
# Mapping from pretraining algorithm to config file.
ALGO_TO_CONFIG = {
"eil": "configs/xmagical/pretraining/eil.py",
"xirl": "configs/xmagical/pretraining/tcc.py",
"lifs": "configs/xmagical/pretraining/lifs.py",
"tcn": "configs/xmagical/pretraining/tcn.py",
"goal_classifier": "configs/xmagical/pretraining/classifier.py",
"raw_imagenet": "configs/xmagical/pretraining/imagenet.py",
}
# We want to pretrain on the entire demonstrations.
MAX_DEMONSTRATIONS = -1
FLAGS = flags.FLAGS
flags.DEFINE_enum("algo", None, ALGORITHMS, "The pretraining algorithm to use.")
flags.DEFINE_string("dataset", None, "Dataset to train on.")
flags.DEFINE_string("train_id", None, "Train id.")
flags.DEFINE_bool("unique_name", False,
"Whether to append a unique ID to the experiment name.")
def main(_):
dataset = FLAGS.dataset
# Generate a unique experiment name.
kwargs = {
"dataset": "fetch_env_tasks",
"mode": "same",
"algo": FLAGS.algo,
"embodiment": dataset,
}
if FLAGS.unique_name:
kwargs["uid"] = unique_id()
experiment_name = FLAGS.train_id
logging.info("Experiment name: %s", experiment_name)
subprocess.run(
[
"python",
"pretrain.py",
"--experiment_name",
experiment_name,
"--raw_imagenet" if FLAGS.algo == "raw_imagenet" else "",
"--config",
f"{ALGO_TO_CONFIG[FLAGS.algo]}:{FLAGS.train_id}",
"--config.data.pretrain_action_class",
f"({repr(dataset)},)",
"--config.data.downstream_action_class",
f"({repr(dataset)},)",
"--config.data.task",
dataset,
"--config.data.max_vids_per_class",
f"{MAX_DEMONSTRATIONS}",
],
check=True,
)
exp_path = osp.join("/tmp/eil/runs/", f"alignment_logs_{experiment_name}")
subprocess.run([
"python",
"graph_alignment.py",
"--embs_path_root",
osp.join(exp_path, "embeddings"),
"--labels_path",
osp.join(
"/tmp/xirl_format_datasets/train",
dataset,
"labels.npy"
),
"--nouse_ref",
])
# Dump experiment metadata as yaml file.
with open(osp.join(exp_path, "metadata.yaml"), "w") as fp:
yaml.dump(kwargs, fp)
if __name__ == "__main__":
flags.mark_flag_as_required("algo")
flags.mark_flag_as_required("train_id")
flags.mark_flag_as_required("dataset")
app.run(main)