├── .VERSION
├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
├── allenact
├── __init__.py
├── _constants.py
├── algorithms
│ ├── __init__.py
│ ├── offpolicy_sync
│ │ ├── __init__.py
│ │ └── losses
│ │ │ ├── __init__.py
│ │ │ └── abstract_offpolicy_loss.py
│ └── onpolicy_sync
│ │ ├── __init__.py
│ │ ├── engine.py
│ │ ├── losses
│ │ ├── __init__.py
│ │ ├── a2cacktr.py
│ │ ├── abstract_loss.py
│ │ ├── grouped_action_imitation.py
│ │ ├── imitation.py
│ │ └── ppo.py
│ │ ├── misc.py
│ │ ├── policy.py
│ │ ├── runner.py
│ │ ├── storage.py
│ │ └── vector_sampled_tasks.py
├── base_abstractions
│ ├── __init__.py
│ ├── callbacks.py
│ ├── distributions.py
│ ├── experiment_config.py
│ ├── misc.py
│ ├── preprocessor.py
│ ├── sensor.py
│ └── task.py
├── embodiedai
│ ├── __init__.py
│ ├── aux_losses
│ │ ├── __init__.py
│ │ └── losses.py
│ ├── mapping
│ │ ├── __init__.py
│ │ ├── mapping_losses.py
│ │ ├── mapping_models
│ │ │ ├── __init__.py
│ │ │ └── active_neural_slam.py
│ │ └── mapping_utils
│ │ │ ├── __init__.py
│ │ │ ├── map_builders.py
│ │ │ └── point_cloud_utils.py
│ ├── models
│ │ ├── __init__.py
│ │ ├── aux_models.py
│ │ ├── basic_models.py
│ │ ├── fusion_models.py
│ │ ├── resnet.py
│ │ └── visual_nav_models.py
│ ├── preprocessors
│ │ ├── __init__.py
│ │ └── resnet.py
│ ├── sensors
│ │ ├── __init__.py
│ │ └── vision_sensors.py
│ └── storage
│ │ ├── __init__.py
│ │ └── vdr_storage.py
├── main.py
├── setup.py
└── utils
│ ├── __init__.py
│ ├── cache_utils.py
│ ├── cacheless_frcnn.py
│ ├── experiment_utils.py
│ ├── inference.py
│ ├── misc_utils.py
│ ├── model_utils.py
│ ├── multi_agent_viz_utils.py
│ ├── spaces_utils.py
│ ├── system.py
│ ├── tensor_utils.py
│ └── viz_utils.py
├── allenact_plugins
├── __init__.py
├── callbacks
│ ├── __init__.py
│ ├── callback_sensors.py
│ ├── extra_requirements.txt
│ └── wandb_callback.py
├── clip_plugin
│ ├── __init__.py
│ ├── clip_preprocessors.py
│ ├── extra_environment.yml
│ └── extra_requirements.txt
├── distributions
│ ├── __init__.py
│ └── distributions.py
├── ithor_plugin
│ ├── __init__.py
│ ├── extra_environment.yml
│ ├── extra_requirements.txt
│ ├── ithor_constants.py
│ ├── ithor_environment.py
│ ├── ithor_sensors.py
│ ├── ithor_task_samplers.py
│ ├── ithor_tasks.py
│ ├── ithor_util.py
│ ├── ithor_viz.py
│ └── scripts
│ │ ├── __init__.py
│ │ ├── make_objectnav_debug_dataset.py
│ │ └── make_pointnav_debug_dataset.py
├── models
│ ├── __init__.py
│ ├── actor_critic_RND.py
│ ├── actor_critic_models.py
│ ├── actor_critic_visual.py
│ ├── discrete_actor_critic.py
│ ├── nn
│ │ ├── __init__.py
│ │ ├── cnn.py
│ │ ├── mlp.py
│ │ ├── resnet.py
│ │ └── visual_base.py
│ └── visuomotor_with_prompt.py
├── navigation_plugin
│ ├── __init__.py
│ ├── objectnav
│ │ ├── __init__.py
│ │ └── models.py
│ └── pointnav
│ │ ├── __init__.py
│ │ └── models.py
├── robothor_plugin
│ ├── __init__.py
│ ├── configs
│ │ └── __init__.py
│ ├── extra_environment.yml
│ ├── extra_requirements.txt
│ ├── robothor_constants.py
│ ├── robothor_distributions.py
│ ├── robothor_environment.py
│ ├── robothor_models.py
│ ├── robothor_preprocessors.py
│ ├── robothor_sensors.py
│ ├── robothor_task_samplers.py
│ ├── robothor_tasks.py
│ ├── robothor_viz.py
│ └── scripts
│ │ ├── __init__.py
│ │ ├── make_objectnav_debug_dataset.py
│ │ └── make_pointnav_debug_dataset.py
├── sawyer_peg_plugin
│ ├── __init__.py
│ ├── base.py
│ ├── constants.py
│ ├── registered_envs.py
│ ├── sawyer_peg_assets
│ │ ├── objects
│ │ │ ├── assets
│ │ │ │ ├── peg_block.xml
│ │ │ │ ├── peg_block_dependencies.xml
│ │ │ │ ├── peg_block_random_hole.xml
│ │ │ │ ├── peg_insert.xml
│ │ │ │ ├── peg_insert_dependencies.xml
│ │ │ │ ├── xyz_base.xml
│ │ │ │ └── xyz_base_dependencies.xml
│ │ │ ├── meshes
│ │ │ │ ├── peg_block
│ │ │ │ │ ├── block_inner.stl
│ │ │ │ │ └── block_outer.stl
│ │ │ │ ├── table
│ │ │ │ │ ├── table_hole.stl
│ │ │ │ │ ├── table_hole2.stl
│ │ │ │ │ ├── tablebody.stl
│ │ │ │ │ └── tabletop.stl
│ │ │ │ └── xyz_base
│ │ │ │ │ ├── base.stl
│ │ │ │ │ ├── eGripperBase.stl
│ │ │ │ │ ├── head.stl
│ │ │ │ │ ├── l0.stl
│ │ │ │ │ ├── l1.stl
│ │ │ │ │ ├── l2.stl
│ │ │ │ │ ├── l3.stl
│ │ │ │ │ ├── l4.stl
│ │ │ │ │ ├── l5.stl
│ │ │ │ │ ├── l6.stl
│ │ │ │ │ └── pedestal.stl
│ │ │ ├── peg_insert.xml
│ │ │ └── xyz_base.xml
│ │ ├── sawyer_xyz
│ │ │ ├── sawyer_peg_insertion_side.xml
│ │ │ └── sawyer_peg_insertion_side_small_table.xml
│ │ └── scene
│ │ │ ├── basic_scene.xml
│ │ │ ├── basic_scene_b.xml
│ │ │ ├── basic_scene_c.xml
│ │ │ └── basic_scene_small_table.xml
│ ├── sawyer_peg_env.py
│ ├── sawyer_peg_plugins.py
│ └── state_distribution_wrapper.py
├── setup.py
├── stretch_manipulathor_plugin
│ ├── __init__.py
│ ├── categories.py
│ ├── dataset_utils.py
│ ├── strech_sensors.py
│ ├── strech_task_sampler_exproom.py
│ ├── stretch_arm_environment.py
│ ├── stretch_constants.py
│ ├── stretch_sim2real_utils.py
│ ├── stretch_tasks
│ │ ├── __init__.py
│ │ ├── strech_pick_place.py
│ │ └── stretch_task_base.py
│ └── stretch_utils.py
├── utils
│ ├── __init__.py
│ ├── array_tensor_utils.py
│ ├── config_utils.py
│ ├── env_utils.py
│ ├── file_utils.py
│ ├── measure_buffer.py
│ ├── metics.py
│ ├── plt_utils.py
│ ├── video_utils.py
│ └── wandb_utils.py
└── wrappers
│ ├── __init__.py
│ ├── env_wrappers.py
│ ├── exp_wrappers.py
│ ├── sensor_wrappers.py
│ ├── task_sampler_wrappers.py
│ └── task_wrappers.py
├── conda
├── environment-base.yml
└── environment-dev.yml
├── datasets
├── .gitignore
├── .habitat_datasets_download_info.json
├── .habitat_downloader_helper.py
├── download_habitat_datasets.sh
└── download_navigation_datasets.sh
├── dev_requirements.txt
├── main.py
├── projects
├── __init__.py
├── objectnav
│ ├── README.md
│ ├── __init__.py
│ └── experiments
│ │ ├── __init__.py
│ │ ├── clip
│ │ ├── __init__.py
│ │ ├── cfg
│ │ │ └── clip_resnet50_gru.yaml
│ │ ├── mixins.py
│ │ ├── objectnav_robothor_rgb_clipresnet50gru_ddppo.py
│ │ └── objnav_not_terminate_if_incorrect_done.py
│ │ └── rmrl
│ │ ├── 1e4.py
│ │ ├── __init__.py
│ │ ├── inf.py
│ │ └── std.py
├── sawyer_peg
│ ├── __init__.py
│ └── experiments
│ │ ├── __init__.py
│ │ ├── cfg
│ │ ├── low_dim.yaml
│ │ ├── visual.yaml
│ │ └── visual_4_proc.yaml
│ │ ├── measure_variations
│ │ ├── __init__.py
│ │ ├── visual_dtw.py
│ │ ├── visual_entropy.py
│ │ ├── visual_euclidean.py
│ │ └── visual_std.py
│ │ ├── method
│ │ ├── __init__.py
│ │ ├── visual.py
│ │ ├── visual_adv.py
│ │ └── visual_random_1e4.py
│ │ ├── tests
│ │ ├── __init__.py
│ │ ├── dtw
│ │ │ ├── __init__.py
│ │ │ ├── visual_test_in_domain.py
│ │ │ ├── visual_test_novel_box.py
│ │ │ └── visual_test_small_table.py
│ │ ├── entropy
│ │ │ ├── __init__.py
│ │ │ ├── visual_test_in_domain.py
│ │ │ ├── visual_test_novel_box.py
│ │ │ └── visual_test_small_table.py
│ │ ├── euclidean
│ │ │ ├── __init__.py
│ │ │ ├── visual_test_in_domain.py
│ │ │ ├── visual_test_novel_box.py
│ │ │ └── visual_test_small_table.py
│ │ ├── others
│ │ │ ├── __init__.py
│ │ │ ├── visual_adv_1e4_in_domain.py
│ │ │ ├── visual_adv_1e4_novel_box.py
│ │ │ ├── visual_random_1e4_in_domain.py
│ │ │ └── visual_random_1e4_novel_box.py
│ │ └── std
│ │ │ ├── __init__.py
│ │ │ ├── visual_test_in_domain.py
│ │ │ ├── visual_test_novel_box.py
│ │ │ └── visual_test_small_table.py
│ │ └── visual_base.py
└── strech_manipulation
│ ├── __init__.py
│ └── experiments
│ ├── __init__.py
│ ├── budget_measure_ablation
│ ├── __init__.py
│ ├── base.py
│ ├── cfg
│ │ └── rgb.yaml
│ ├── dtw_random.py
│ ├── dtw_random_four_combo.py
│ ├── dtw_random_sixteen_combo.py
│ ├── entropy_random.py
│ ├── entropy_random_four_combo.py
│ ├── entropy_random_sixteen.py
│ ├── euclidean_random.py
│ ├── euclidean_random_four_combos.py
│ ├── euclidean_random_sixteen_combos.py
│ ├── random_irr_four_combos.py
│ ├── random_irr_single_combo.py
│ └── random_irr_sixteen_combos.py
│ ├── episodic_variations
│ ├── 1e3.py
│ ├── 1e3_four_combos.py
│ ├── 1e3_sixteen_combos.py
│ ├── 1e4.py
│ ├── 1e4_four_combos.py
│ ├── 1e4_sixteen_combos.py
│ ├── 250k.py
│ ├── 5e3.py
│ ├── 5e3_four_combos.py
│ ├── 5e3_sixteen_combos.py
│ └── __init__.py
│ └── tests
│ ├── __init__.py
│ ├── budegt_and_measurement
│ ├── __init__.py
│ ├── measure_random_novel_objects.py
│ ├── measure_random_novel_pos.py
│ ├── measure_random_novel_scene.py
│ └── measure_random_novel_texture_lightning.py
│ └── episodic
│ ├── __init__.py
│ ├── random_5e3_single_combo_novel_objects.py
│ ├── random_5e3_single_combo_novel_pos.py
│ ├── random_5e3_single_combo_novel_scene.py
│ └── random_5e3_single_combo_novel_texture_lightning.py
├── requirements.txt
├── scripts
├── Stretch-P&P.ipynb
├── __init__.py
└── startx.py
└── setup.py
/.VERSION:
--------------------------------------------------------------------------------
1 | 0.5.3a
2 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 | *wandb
9 |
10 | # Distribution / packaging
11 | .Python
12 | docs/build/
13 | develop-eggs/
14 | dist/
15 | downloads/
16 | eggs/
17 | .eggs/
18 | lib/
19 | lib64/
20 | parts/
21 | sdist/
22 | var/
23 | wheels/
24 | pip-wheel-metadata/
25 | share/python-wheels/
26 | *.egg-info/
27 | .installed.cfg
28 | *.egg
29 | MANIFEST
30 |
31 | # PyInstaller
32 | # Usually these files are written by a python script from a template
33 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
34 | *.manifest
35 | *.spec
36 |
37 | # Installer logs
38 | pip-log.txt
39 | pip-delete-this-directory.txt
40 |
41 | # Unit test / coverage reports
42 | htmlcov/
43 | .tox/
44 | .nox/
45 | .coverage
46 | .coverage.*
47 | .cache
48 | nosetests.xml
49 | coverage.xml
50 | *.cover
51 | *.py,cover
52 | .hypothesis/
53 | .pytest_cache/
54 |
55 | # Translations
56 | *.mo
57 | *.pot
58 |
59 | # Django stuff:
60 | *.log
61 | local_settings.py
62 | db.sqlite3
63 | db.sqlite3-journal
64 |
65 | # Flask stuff:
66 | instance/
67 | .webassets-cache
68 |
69 | # Scrapy stuff:
70 | .scrapy
71 |
72 | # Sphinx documentation
73 | docs/_build/
74 |
75 | # PyBuilder
76 | target/
77 |
78 | # Jupyter Notebook
79 | .ipynb_checkpoints
80 |
81 | # IPython
82 | profile_default/
83 | ipython_config.py
84 |
85 | # pyenv
86 | .python-version
87 |
88 | # pipenv
89 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
90 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
91 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
92 | # install all needed dependencies.
93 | #Pipfile.lock
94 |
95 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
96 | __pypackages__/
97 |
98 | # Celery stuff
99 | celerybeat-schedule
100 | celerybeat.pid
101 |
102 | # SageMath parsed files
103 | *.sage.py
104 |
105 | # Environments
106 | .env
107 | .venv
108 | env/
109 | venv/
110 | ENV/
111 | env.bak/
112 | venv.bak/
113 |
114 | # Spyder project settings
115 | .spyderproject
116 | .spyproject
117 |
118 | # Rope project settings
119 | .ropeproject
120 |
121 | # mkdocs documentation
122 | /site
123 |
124 | # mypy
125 | .mypy_cache/
126 | .dmypy.json
127 | dmypy.json
128 |
129 | # Pyre type checker
130 | .pyre/
131 |
132 | # pycharm
133 | .idea/
134 |
135 | # pytorch
136 | *.pt
137 |
138 | # Default output dir
139 | experiment_output
140 | *_out
141 |
142 | # PDFs
143 | *.pdf
144 |
145 | # PNGs
146 | *.png
147 |
148 | # JPEGs
149 | *.jpeg
150 |
151 | # CSVs
152 | *.csv
153 |
154 | # Tensorboard logs
155 | events.out.tfevents.*
156 |
157 | # TSV files
158 | *.tsv
159 |
160 | # tmp directory
161 | tmp/
162 |
163 | # Pickle files
164 | *.pkl
165 | *.pkl.gz
166 |
167 | # Zip files
168 | *.zip
169 |
170 | # VSCode
171 | .vscode/
172 |
173 | # MacOS
174 | .DS_Store
175 |
176 | # Docs
177 | docs/index.md
178 | docs/CONTRIBUTING.md
179 | docs/LICENSE.md
180 |
181 | # Metrics
182 | metrics__*.json
183 |
184 | # Robothor
185 | allenact_plugins/robothor_plugin/data/*
186 |
187 | # ithor
188 | allenact_plugins/ithor_plugin/data/*
189 |
190 | # Habitat
191 | external_projects/habitat-lab
192 |
193 | # Local pip installations
194 | src
195 | .pip_src
196 |
197 | # Files created when running training
198 | **/used_configs
199 | *.patch
200 |
201 | # Package building
202 | *.egg_info
203 | *.egg-info
204 |
205 | # Additional allenact-specific locks and hidden files
206 | *.allenact_last_start_time_string
207 | *.allenact_start_time_string.lock
208 | *.lock
209 | rsync-*
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Original work Copyright (c) 2017 Ilya Kostrikov
4 |
5 | Original work Copyright (c) Facebook, Inc. and its affiliates.
6 |
7 | Modified work Copyright (c) 2020 Allen Institute for Artificial Intelligence
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a copy
10 | of this software and associated documentation files (the "Software"), to deal
11 | in the Software without restriction, including without limitation the rights
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | copies of the Software, and to permit persons to whom the Software is
14 | furnished to do so, subject to the following conditions:
15 |
16 | The above copyright notice and this permission notice shall be included in all
17 | copies or substantial portions of the Software.
18 |
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | SOFTWARE.
26 |
--------------------------------------------------------------------------------
/allenact/__init__.py:
--------------------------------------------------------------------------------
1 | try:
2 | # noinspection PyProtectedMember,PyUnresolvedReferences
3 | from allenact._version import __version__
4 | except ModuleNotFoundError:
5 | __version__ = None
6 |
--------------------------------------------------------------------------------
/allenact/_constants.py:
--------------------------------------------------------------------------------
1 | import os
2 | from pathlib import Path
3 |
4 | ALLENACT_INSTALL_DIR = os.path.abspath(os.path.dirname(Path(__file__)))
5 |
--------------------------------------------------------------------------------
/allenact/algorithms/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact/algorithms/__init__.py
--------------------------------------------------------------------------------
/allenact/algorithms/offpolicy_sync/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact/algorithms/offpolicy_sync/__init__.py
--------------------------------------------------------------------------------
/allenact/algorithms/offpolicy_sync/losses/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact/algorithms/offpolicy_sync/losses/__init__.py
--------------------------------------------------------------------------------
/allenact/algorithms/offpolicy_sync/losses/abstract_offpolicy_loss.py:
--------------------------------------------------------------------------------
1 | """Defining abstract loss classes for actor critic models."""
2 |
3 | import abc
4 | from typing import Dict, Tuple, TypeVar, Generic
5 |
6 | import torch
7 |
8 | from allenact.algorithms.onpolicy_sync.policy import ObservationType
9 | from allenact.base_abstractions.misc import Loss, Memory
10 |
11 | ModelType = TypeVar("ModelType")
12 |
13 |
14 | class AbstractOffPolicyLoss(Generic[ModelType], Loss):
15 | """Abstract class representing an off-policy loss function used to train a
16 | model."""
17 |
18 | # noinspection PyMethodOverriding
19 | @abc.abstractmethod
20 | def loss( # type: ignore
21 | self,
22 | *, # No positional arguments
23 | step_count: int,
24 | model: ModelType,
25 | batch: ObservationType,
26 | memory: Memory,
27 | **kwargs,
28 | ) -> Tuple[torch.FloatTensor, Dict[str, float], Memory, int]:
29 | """Computes the loss.
30 |
31 | Loss after processing a batch of data with (part of) a model (possibly with memory).
32 |
33 | # Parameters
34 |
35 | model: model to run on data batch (both assumed to be on the same device)
36 | batch: data to use as input for model (already on the same device as model)
37 | memory: model memory before processing current data batch
38 |
39 | # Returns
40 |
41 | A tuple with:
42 |
43 | current_loss: total loss
44 | current_info: additional information about the current loss
45 | memory: model memory after processing current data batch
46 | bsize: batch size
47 | """
48 | raise NotImplementedError()
49 |
--------------------------------------------------------------------------------
/allenact/algorithms/onpolicy_sync/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact/algorithms/onpolicy_sync/__init__.py
--------------------------------------------------------------------------------
/allenact/algorithms/onpolicy_sync/losses/__init__.py:
--------------------------------------------------------------------------------
1 | from .a2cacktr import A2C, ACKTR, A2CACKTR
2 | from .ppo import PPO, RNDPPO
3 |
4 | losses_map = {"ppo_loss": PPO, "rnd_ppo_loss": RNDPPO}
5 |
--------------------------------------------------------------------------------
/allenact/algorithms/onpolicy_sync/losses/abstract_loss.py:
--------------------------------------------------------------------------------
1 | """Defining abstract loss classes for actor critic models."""
2 |
3 | import abc
4 | from typing import Dict, Tuple, Union
5 |
6 | import torch
7 |
8 | from allenact.algorithms.onpolicy_sync.policy import ObservationType
9 | from allenact.base_abstractions.distributions import CategoricalDistr
10 | from allenact.base_abstractions.misc import Loss, ActorCriticOutput
11 |
12 |
13 | class AbstractActorCriticLoss(Loss):
14 | """Abstract class representing a loss function used to train an
15 | ActorCriticModel."""
16 |
17 | # noinspection PyMethodOverriding
18 | @abc.abstractmethod
19 | def loss( # type: ignore
20 | self,
21 | step_count: int,
22 | batch: ObservationType,
23 | actor_critic_output: ActorCriticOutput[CategoricalDistr],
24 | *args,
25 | **kwargs,
26 | ) -> Union[
27 | Tuple[torch.FloatTensor, Dict[str, float]],
28 | Tuple[torch.FloatTensor, Dict[str, float], Dict[str, float]],
29 | ]:
30 | """Computes the loss.
31 |
32 | # Parameters
33 |
34 | batch : A batch of data corresponding to the information collected when rolling out (possibly many) agents
35 | over a fixed number of steps. In particular this batch should have the same format as that returned by
36 | `RolloutStorage.batched_experience_generator`.
37 | actor_critic_output : The output of calling an ActorCriticModel on the observations in `batch`.
38 | args : Extra args.
39 | kwargs : Extra kwargs.
40 |
41 | # Returns
42 |
43 | A (0-dimensional) torch.FloatTensor corresponding to the computed loss. `.backward()` will be called on this
44 | tensor in order to compute a gradient update to the ActorCriticModel's parameters.
45 | A Dict[str, float] with scalar values corresponding to sub-losses.
46 | An optional Dict[str, float] with scalar values corresponding to extra info to be processed per epoch and
47 | combined across epochs by the engine.
48 | """
49 | # TODO: The above documentation is missing what the batch dimensions are.
50 |
51 | raise NotImplementedError()
52 |
--------------------------------------------------------------------------------
/allenact/algorithms/onpolicy_sync/losses/grouped_action_imitation.py:
--------------------------------------------------------------------------------
1 | import functools
2 | from typing import Dict, cast, Sequence, Set
3 |
4 | import torch
5 |
6 | from allenact.algorithms.onpolicy_sync.losses.abstract_loss import (
7 | AbstractActorCriticLoss,
8 | )
9 | from allenact.algorithms.onpolicy_sync.policy import ObservationType
10 | from allenact.base_abstractions.distributions import CategoricalDistr
11 | from allenact.base_abstractions.misc import ActorCriticOutput
12 |
13 |
14 | class GroupedActionImitation(AbstractActorCriticLoss):
15 | def __init__(
16 | self, nactions: int, action_groups: Sequence[Set[int]], *args, **kwargs
17 | ):
18 | super().__init__(*args, **kwargs)
19 |
20 | assert (
21 | sum(len(ag) for ag in action_groups) == nactions
22 | and len(functools.reduce(lambda x, y: x | y, action_groups)) == nactions
23 | ), f"`action_groups` (==`{action_groups}`) must be a partition of `[0, 1, 2, ..., nactions - 1]`"
24 |
25 | self.nactions = nactions
26 | self.action_groups_mask = torch.FloatTensor(
27 | [
28 | [i in action_group for i in range(nactions)]
29 | for action_group in action_groups
30 | ]
31 | + [[1] * nactions] # type:ignore
32 | )
33 |
34 | def loss( # type: ignore
35 | self,
36 | step_count: int,
37 | batch: ObservationType,
38 | actor_critic_output: ActorCriticOutput[CategoricalDistr],
39 | *args,
40 | **kwargs,
41 | ):
42 | observations = cast(Dict[str, torch.Tensor], batch["observations"])
43 |
44 | assert "expert_group_action" in observations
45 |
46 | expert_group_actions = observations["expert_group_action"]
47 |
48 | # expert_group_actions = expert_group_actions + (expert_group_actions == -1).long() * (
49 | # 1 + self.action_groups_mask.shape[0]
50 | # )
51 |
52 | if self.action_groups_mask.get_device() != expert_group_actions.get_device():
53 | self.action_groups_mask = cast(
54 | torch.FloatTensor,
55 | self.action_groups_mask.cuda(expert_group_actions.get_device()),
56 | )
57 |
58 | expert_group_actions_reshaped = expert_group_actions.view(-1, 1)
59 |
60 | expert_group_actions_mask = self.action_groups_mask[
61 | expert_group_actions_reshaped
62 | ]
63 |
64 | probs_tensor = actor_critic_output.distributions.probs_tensor
65 | expert_group_actions_mask = expert_group_actions_mask.view(probs_tensor.shape)
66 |
67 | total_loss = -(
68 | torch.log((probs_tensor * expert_group_actions_mask).sum(-1))
69 | ).mean()
70 |
71 | return total_loss, {"grouped_action_cross_entropy": total_loss.item(),}
72 |
--------------------------------------------------------------------------------
/allenact/algorithms/onpolicy_sync/misc.py:
--------------------------------------------------------------------------------
1 | from enum import Enum
2 | from typing import Dict, Any, Optional
3 |
4 | import attr
5 |
6 |
7 | class TrackingInfoType(Enum):
8 | LOSS = "loss"
9 | TEACHER_FORCING = "teacher_forcing"
10 | UPDATE_INFO = "update_info"
11 |
12 |
13 | @attr.s(kw_only=True)
14 | class TrackingInfo:
15 | type: TrackingInfoType = attr.ib()
16 | info: Dict[str, Any] = attr.ib()
17 | n: int = attr.ib()
18 | storage_uuid: Optional[str] = attr.ib()
19 | stage_component_uuid: Optional[str] = attr.ib()
20 |
--------------------------------------------------------------------------------
/allenact/base_abstractions/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact/base_abstractions/__init__.py
--------------------------------------------------------------------------------
/allenact/base_abstractions/callbacks.py:
--------------------------------------------------------------------------------
1 | from typing import List, Dict, Any, Sequence, Optional
2 |
3 | from allenact.base_abstractions.experiment_config import ExperimentConfig
4 | from allenact.base_abstractions.sensor import Sensor
5 |
6 | try:
7 | from typing import Literal
8 | except ImportError:
9 | from typing_extensions import Literal
10 |
11 |
12 | class Callback:
13 | def setup(
14 | self,
15 | name: str,
16 | config: ExperimentConfig,
17 | mode: Literal["train", "valid", "test"],
18 | **kwargs,
19 | ) -> None:
20 | """Called once before training begins."""
21 |
22 | def on_train_log(
23 | self,
24 | metrics: List[Dict[str, Any]],
25 | metric_means: Dict[str, float],
26 | step: int,
27 | tasks_data: List[Any],
28 | **kwargs,
29 | ) -> None:
30 | """Called once train is supposed to log."""
31 |
32 | def on_valid_log(
33 | self,
34 | metrics: Dict[str, Any],
35 | metric_means: Dict[str, float],
36 | checkpoint_file_name: str,
37 | tasks_data: List[Any],
38 | step: int,
39 | **kwargs,
40 | ) -> None:
41 | """Called after validation ends."""
42 |
43 | def on_test_log(
44 | self,
45 | checkpoint_file_name: str,
46 | metrics: Dict[str, Any],
47 | metric_means: Dict[str, float],
48 | tasks_data: List[Any],
49 | step: int,
50 | **kwargs,
51 | ) -> None:
52 | """Called after test ends."""
53 |
54 | def after_save_project_state(self, base_dir: str) -> None:
55 | """Called after saving the project state in base_dir."""
56 |
57 | def callback_sensors(self) -> Optional[Sequence[Sensor]]:
58 | """Determines the data returned to the `tasks_data` parameter in the
59 | above *_log functions."""
60 |
--------------------------------------------------------------------------------
/allenact/embodiedai/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact/embodiedai/__init__.py
--------------------------------------------------------------------------------
/allenact/embodiedai/aux_losses/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact/embodiedai/aux_losses/__init__.py
--------------------------------------------------------------------------------
/allenact/embodiedai/mapping/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact/embodiedai/mapping/__init__.py
--------------------------------------------------------------------------------
/allenact/embodiedai/mapping/mapping_models/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact/embodiedai/mapping/mapping_models/__init__.py
--------------------------------------------------------------------------------
/allenact/embodiedai/mapping/mapping_utils/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact/embodiedai/mapping/mapping_utils/__init__.py
--------------------------------------------------------------------------------
/allenact/embodiedai/models/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact/embodiedai/models/__init__.py
--------------------------------------------------------------------------------
/allenact/embodiedai/models/aux_models.py:
--------------------------------------------------------------------------------
1 | # Original work Copyright (c) Facebook, Inc. and its affiliates.
2 | # Modified work Copyright (c) Allen Institute for AI
3 | # This source code is licensed under the MIT license found in the
4 | # LICENSE file in the root directory of this source tree.
5 | """Several of the models defined in this file are modified versions of those
6 | found in https://github.com/joel99/habitat-pointnav-
7 | aux/blob/master/habitat_baselines/"""
8 |
9 | import torch
10 | import torch.nn as nn
11 |
12 | from allenact.embodiedai.aux_losses.losses import (
13 | InverseDynamicsLoss,
14 | TemporalDistanceLoss,
15 | CPCALoss,
16 | CPCASoftMaxLoss,
17 | )
18 | from allenact.utils.model_utils import FeatureEmbedding
19 |
20 |
21 | class AuxiliaryModel(nn.Module):
22 | """The class of defining the models for all kinds of self-supervised
23 | auxiliary tasks."""
24 |
25 | def __init__(
26 | self,
27 | aux_uuid: str,
28 | action_dim: int,
29 | obs_embed_dim: int,
30 | belief_dim: int,
31 | action_embed_size: int = 4,
32 | cpca_classifier_hidden_dim: int = 32,
33 | cpca_softmax_dim: int = 128,
34 | ):
35 | super().__init__()
36 | self.aux_uuid = aux_uuid
37 | self.action_dim = action_dim
38 | self.obs_embed_dim = obs_embed_dim
39 | self.belief_dim = belief_dim
40 |
41 | if self.aux_uuid == InverseDynamicsLoss.UUID:
42 | self.decoder = nn.Linear(
43 | 2 * self.obs_embed_dim + self.belief_dim, self.action_dim
44 | )
45 | elif self.aux_uuid == TemporalDistanceLoss.UUID:
46 | self.decoder = nn.Linear(2 * self.obs_embed_dim + self.belief_dim, 1)
47 | elif CPCALoss.UUID in self.aux_uuid: # the CPCA family with various k
48 | ## Auto-regressive model to predict future context
49 | self.action_embedder = FeatureEmbedding(
50 | self.action_dim + 1, action_embed_size
51 | )
52 | # NOTE: add extra 1 in embedding dict cuz we will pad zero actions?
53 | self.context_model = nn.GRU(action_embed_size, self.belief_dim)
54 |
55 | ## Classifier to estimate mutual information
56 | self.classifier = nn.Sequential(
57 | nn.Linear(
58 | self.belief_dim + self.obs_embed_dim, cpca_classifier_hidden_dim
59 | ),
60 | nn.ReLU(),
61 | nn.Linear(cpca_classifier_hidden_dim, 1),
62 | )
63 |
64 | elif CPCASoftMaxLoss.UUID in self.aux_uuid:
65 | ###
66 | # same as CPCA with extra MLP for contrastive losses.
67 | ###
68 | self.action_embedder = FeatureEmbedding(
69 | self.action_dim + 1, action_embed_size
70 | )
71 | # NOTE: add extra 1 in embedding dict cuz we will pad zero actions?
72 | self.context_model = nn.GRU(action_embed_size, self.belief_dim)
73 |
74 | ## Classifier to estimate mutual information
75 | self.visual_mlp = nn.Sequential(
76 | nn.Linear(obs_embed_dim, cpca_classifier_hidden_dim),
77 | nn.ReLU(),
78 | nn.Linear(cpca_classifier_hidden_dim, cpca_softmax_dim),
79 | )
80 |
81 | self.belief_mlp = nn.Sequential(
82 | nn.Linear(self.belief_dim, cpca_classifier_hidden_dim),
83 | nn.ReLU(),
84 | nn.Linear(cpca_classifier_hidden_dim, cpca_softmax_dim),
85 | )
86 |
87 | else:
88 | raise ValueError("Unknown Auxiliary Loss UUID")
89 |
90 | def forward(self, features: torch.FloatTensor):
91 | if self.aux_uuid in [InverseDynamicsLoss.UUID, TemporalDistanceLoss.UUID]:
92 | return self.decoder(features)
93 | else:
94 | raise NotImplementedError(
95 | f"Auxiliary model with UUID {self.aux_uuid} does not support `forward` call."
96 | )
97 |
--------------------------------------------------------------------------------
/allenact/embodiedai/models/fusion_models.py:
--------------------------------------------------------------------------------
1 | # Original work Copyright (c) Facebook, Inc. and its affiliates.
2 | # Modified work Copyright (c) Allen Institute for AI
3 | # This source code is licensed under the MIT license found in the
4 | # LICENSE file in the root directory of this source tree.
5 | # Adapted from https://github.com/joel99/habitat-pointnav-aux/blob/master/habitat_baselines/
6 |
7 | import math
8 | from typing import Tuple
9 |
10 | import torch
11 | import torch.nn as nn
12 |
13 |
14 | class Fusion(nn.Module):
15 | """Base class of belief fusion model from Auxiliary Tasks Speed Up Learning
16 | PointGoal Navigation (Ye, 2020) Child class should implement
17 | `get_belief_weights` function to generate weights to fuse the beliefs from
18 | all the auxiliary task into one."""
19 |
20 | def __init__(self, hidden_size, obs_embed_size, num_tasks):
21 | super().__init__()
22 | self.hidden_size = hidden_size # H
23 | self.obs_embed_size = obs_embed_size # Z
24 | self.num_tasks = num_tasks # k
25 |
26 | def forward(
27 | self,
28 | all_beliefs: torch.FloatTensor, # (T, N, H, K)
29 | obs_embeds: torch.FloatTensor, # (T, N, Z)
30 | ) -> Tuple[torch.FloatTensor, torch.FloatTensor]: # (T, N, H), (T, N, K)
31 |
32 | num_steps, num_samplers, _, _ = all_beliefs.shape
33 | all_beliefs = all_beliefs.view(
34 | num_steps * num_samplers, self.hidden_size, self.num_tasks
35 | )
36 | obs_embeds = obs_embeds.view(num_steps * num_samplers, -1)
37 |
38 | weights = self.get_belief_weights(
39 | all_beliefs=all_beliefs, obs_embeds=obs_embeds, # (T*N, H, K) # (T*N, Z)
40 | ).unsqueeze(
41 | -1
42 | ) # (T*N, K, 1)
43 |
44 | beliefs = torch.bmm(all_beliefs, weights) # (T*N, H, 1)
45 |
46 | beliefs = beliefs.squeeze(-1).view(num_steps, num_samplers, self.hidden_size)
47 | weights = weights.squeeze(-1).view(num_steps, num_samplers, self.num_tasks)
48 |
49 | return beliefs, weights
50 |
51 | def get_belief_weights(
52 | self,
53 | all_beliefs: torch.FloatTensor, # (T*N, H, K)
54 | obs_embeds: torch.FloatTensor, # (T*N, Z)
55 | ) -> torch.FloatTensor: # (T*N, K)
56 | raise NotImplementedError()
57 |
58 |
59 | class AverageFusion(Fusion):
60 | UUID = "avg"
61 |
62 | def get_belief_weights(
63 | self,
64 | all_beliefs: torch.FloatTensor, # (T*N, H, K)
65 | obs_embeds: torch.FloatTensor, # (T*N, Z)
66 | ) -> torch.FloatTensor: # (T*N, K)
67 |
68 | batch_size = all_beliefs.shape[0]
69 | weights = torch.ones(batch_size, self.num_tasks).to(all_beliefs)
70 | weights /= self.num_tasks
71 | return weights
72 |
73 |
74 | class SoftmaxFusion(Fusion):
75 | """Situational Fusion of Visual Representation for Visual Navigation
76 | https://arxiv.org/abs/1908.09073."""
77 |
78 | UUID = "smax"
79 |
80 | def __init__(self, hidden_size, obs_embed_size, num_tasks):
81 | super().__init__(hidden_size, obs_embed_size, num_tasks)
82 | # mapping from rnn input to task
83 | # ignore beliefs
84 | self.linear = nn.Linear(obs_embed_size, num_tasks)
85 |
86 | def get_belief_weights(
87 | self,
88 | all_beliefs: torch.Tensor, # (T*N, H, K)
89 | obs_embeds: torch.Tensor, # (T*N, Z)
90 | ) -> torch.Tensor: # (T*N, K)
91 |
92 | scores = self.linear(obs_embeds) # (T*N, K)
93 | weights = torch.softmax(scores, dim=-1)
94 | return weights
95 |
96 |
97 | class AttentiveFusion(Fusion):
98 | """Attention is All You Need https://arxiv.org/abs/1706.03762 i.e. scaled
99 | dot-product attention."""
100 |
101 | UUID = "attn"
102 |
103 | def __init__(self, hidden_size, obs_embed_size, num_tasks):
104 | super().__init__(hidden_size, obs_embed_size, num_tasks)
105 | self.linear = nn.Linear(obs_embed_size, hidden_size)
106 |
107 | def get_belief_weights(
108 | self,
109 | all_beliefs: torch.Tensor, # (T*N, H, K)
110 | obs_embeds: torch.Tensor, # (T*N, Z)
111 | ) -> torch.Tensor: # (T*N, K)
112 |
113 | queries = self.linear(obs_embeds).unsqueeze(1) # (T*N, 1, H)
114 | scores = torch.bmm(queries, all_beliefs).squeeze(1) # (T*N, K)
115 | weights = torch.softmax(
116 | scores / math.sqrt(self.hidden_size), dim=-1
117 | ) # (T*N, K)
118 | return weights
119 |
--------------------------------------------------------------------------------
/allenact/embodiedai/preprocessors/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact/embodiedai/preprocessors/__init__.py
--------------------------------------------------------------------------------
/allenact/embodiedai/preprocessors/resnet.py:
--------------------------------------------------------------------------------
1 | from typing import List, Callable, Optional, Any, cast, Dict
2 |
3 | import gym
4 | import numpy as np
5 | import torch
6 | import torch.nn as nn
7 | from torchvision import models
8 |
9 | from allenact.base_abstractions.preprocessor import Preprocessor
10 | from allenact.utils.misc_utils import prepare_locals_for_super
11 |
12 |
13 | class ResNetEmbedder(nn.Module):
14 | def __init__(self, resnet, pool=True):
15 | super().__init__()
16 | self.model = resnet
17 | self.pool = pool
18 | self.eval()
19 |
20 | def forward(self, x):
21 | with torch.no_grad():
22 | x = self.model.conv1(x)
23 | x = self.model.bn1(x)
24 | x = self.model.relu(x)
25 | x = self.model.maxpool(x)
26 |
27 | x = self.model.layer1(x)
28 | x = self.model.layer2(x)
29 | x = self.model.layer3(x)
30 | x = self.model.layer4(x)
31 |
32 | if not self.pool:
33 | return x
34 | else:
35 | x = self.model.avgpool(x)
36 | x = torch.flatten(x, 1)
37 | return x
38 |
39 |
40 | class ResNetPreprocessor(Preprocessor):
41 | """Preprocess RGB or depth image using a ResNet model."""
42 |
43 | def __init__(
44 | self,
45 | input_uuids: List[str],
46 | output_uuid: str,
47 | input_height: int,
48 | input_width: int,
49 | output_height: int,
50 | output_width: int,
51 | output_dims: int,
52 | pool: bool,
53 | torchvision_resnet_model: Callable[..., models.ResNet] = models.resnet18,
54 | device: Optional[torch.device] = None,
55 | device_ids: Optional[List[torch.device]] = None,
56 | **kwargs: Any,
57 | ):
58 | def f(x, k):
59 | assert k in x, "{} must be set in ResNetPreprocessor".format(k)
60 | return x[k]
61 |
62 | def optf(x, k, default):
63 | return x[k] if k in x else default
64 |
65 | self.input_height = input_height
66 | self.input_width = input_width
67 | self.output_height = output_height
68 | self.output_width = output_width
69 | self.output_dims = output_dims
70 | self.pool = pool
71 | self.make_model = torchvision_resnet_model
72 |
73 | self.device = torch.device("cpu") if device is None else device
74 | self.device_ids = device_ids or cast(
75 | List[torch.device], list(range(torch.cuda.device_count()))
76 | )
77 |
78 | self._resnet: Optional[ResNetEmbedder] = None
79 |
80 | low = -np.inf
81 | high = np.inf
82 | shape = (self.output_dims, self.output_height, self.output_width)
83 |
84 | assert (
85 | len(input_uuids) == 1
86 | ), "resnet preprocessor can only consume one observation type"
87 |
88 | observation_space = gym.spaces.Box(low=low, high=high, shape=shape)
89 |
90 | super().__init__(**prepare_locals_for_super(locals()))
91 |
92 | @property
93 | def resnet(self) -> ResNetEmbedder:
94 | if self._resnet is None:
95 | self._resnet = ResNetEmbedder(
96 | self.make_model(pretrained=True).to(self.device), pool=self.pool
97 | )
98 | return self._resnet
99 |
100 | def to(self, device: torch.device) -> "ResNetPreprocessor":
101 | self._resnet = self.resnet.to(device)
102 | self.device = device
103 | return self
104 |
105 | def process(self, obs: Dict[str, Any], *args: Any, **kwargs: Any) -> Any:
106 | x = obs[self.input_uuids[0]].to(self.device).permute(0, 3, 1, 2) # bhwc -> bchw
107 | # If the input is depth, repeat it across all 3 channels
108 | if x.shape[1] == 1:
109 | x = x.repeat(1, 3, 1, 1)
110 | return self.resnet(x.to(self.device))
111 |
--------------------------------------------------------------------------------
/allenact/embodiedai/sensors/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact/embodiedai/sensors/__init__.py
--------------------------------------------------------------------------------
/allenact/embodiedai/storage/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact/embodiedai/storage/__init__.py
--------------------------------------------------------------------------------
/allenact/utils/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact/utils/__init__.py
--------------------------------------------------------------------------------
/allenact/utils/cacheless_frcnn.py:
--------------------------------------------------------------------------------
1 | from typing import List, Any
2 |
3 | import torch
4 | from torchvision.models.detection.backbone_utils import resnet_fpn_backbone
5 | from torchvision.models.detection.faster_rcnn import FasterRCNN
6 |
7 | # noinspection PyProtectedMember
8 | from torchvision.models.detection.faster_rcnn import model_urls
9 | from torchvision.models.detection.rpn import AnchorGenerator
10 | from torchvision.models.utils import load_state_dict_from_url
11 |
12 |
13 | class CachelessAnchorGenerator(AnchorGenerator):
14 | def forward(self, image_list: Any, feature_maps: Any):
15 | grid_sizes = list([feature_map.shape[-2:] for feature_map in feature_maps])
16 | image_size = image_list.tensors.shape[-2:]
17 | strides = [
18 | [int(image_size[0] / g[0]), int(image_size[1] / g[1])] for g in grid_sizes
19 | ]
20 | dtype, device = feature_maps[0].dtype, feature_maps[0].device
21 | self.set_cell_anchors(dtype, device)
22 | anchors_over_all_feature_maps = self.grid_anchors(grid_sizes, strides)
23 | anchors = torch.jit.annotate(List[List[torch.Tensor]], []) # type:ignore
24 | for i, (image_height, image_width) in enumerate(image_list.image_sizes):
25 | anchors_in_image = []
26 | for anchors_per_feature_map in anchors_over_all_feature_maps:
27 | anchors_in_image.append(anchors_per_feature_map)
28 | anchors.append(anchors_in_image)
29 | anchors = [torch.cat(anchors_per_image) for anchors_per_image in anchors]
30 |
31 | return anchors
32 |
33 |
34 | def fasterrcnn_resnet50_fpn(
35 | pretrained=False, progress=True, num_classes=91, pretrained_backbone=True, **kwargs
36 | ):
37 | if pretrained:
38 | # no need to download the backbone if pretrained is set
39 | pretrained_backbone = False
40 | backbone = resnet_fpn_backbone("resnet50", pretrained_backbone)
41 |
42 | anchor_sizes = ((32,), (64,), (128,), (256,), (512,))
43 | aspect_ratios = ((0.5, 1.0, 2.0),) * len(anchor_sizes)
44 | rpn_anchor_generator = CachelessAnchorGenerator(anchor_sizes, aspect_ratios)
45 | model = FasterRCNN(
46 | backbone, num_classes, rpn_anchor_generator=rpn_anchor_generator, **kwargs
47 | )
48 |
49 | # min_size = 300
50 | # max_size = 400
51 | # anchor_sizes = ((12,), (24,), (48,), (96,), (192,))
52 | # aspect_ratios = ((0.5, 1.0, 2.0),) * len(anchor_sizes)
53 | # rpn_anchor_generator = CachelessAnchorGenerator(
54 | # anchor_sizes, aspect_ratios
55 | # )
56 | # model = FasterRCNN(backbone, num_classes, rpn_anchor_generator=rpn_anchor_generator, min_size=min_size, max_size=max_size, **kwargs)
57 |
58 | if pretrained:
59 | state_dict = load_state_dict_from_url(
60 | model_urls["fasterrcnn_resnet50_fpn_coco"], progress=progress
61 | )
62 | model.load_state_dict(state_dict)
63 | return model
64 |
--------------------------------------------------------------------------------
/allenact_plugins/__init__.py:
--------------------------------------------------------------------------------
1 | try:
2 | # noinspection PyProtectedMember,PyUnresolvedReferences
3 | from allenact_plugins._version import __version__
4 | except ModuleNotFoundError:
5 | __version__ = None
6 |
7 | # setting mujoco path variable
8 | import os
9 |
10 | os.environ[
11 | "LD_LIBRARY_PATH"
12 | ] = f":{os.environ['HOME']}/.mujoco/mujoco210/bin:/usr/lib/nvidia"
13 |
--------------------------------------------------------------------------------
/allenact_plugins/callbacks/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/callbacks/__init__.py
--------------------------------------------------------------------------------
/allenact_plugins/callbacks/extra_requirements.txt:
--------------------------------------------------------------------------------
1 | wandb==0.13.9
2 |
--------------------------------------------------------------------------------
/allenact_plugins/clip_plugin/__init__.py:
--------------------------------------------------------------------------------
1 | from allenact.utils.system import ImportChecker
2 |
3 | with ImportChecker(
4 | "Cannot `import clip`. Please install clip from the openai/CLIP git repository:"
5 | "\n`pip install git+https://github.com/openai/CLIP.git@b46f5ac7587d2e1862f8b7b1573179d80dcdd620`"
6 | ):
7 | # noinspection PyUnresolvedReferences
8 | import clip
9 |
--------------------------------------------------------------------------------
/allenact_plugins/clip_plugin/extra_environment.yml:
--------------------------------------------------------------------------------
1 | channels:
2 | - pytorch
3 | - defaults
4 | - conda-forge
5 | dependencies:
6 | - pytorch>=1.7.1
7 | - torchvision
8 | - pip:
9 | - ftfy
10 | - regex
11 | - tqdm
12 | - "--editable=git+https://github.com/openai/CLIP.git@e184f608c5d5e58165682f7c332c3a8b4c1545f2#egg=clip"
13 |
--------------------------------------------------------------------------------
/allenact_plugins/clip_plugin/extra_requirements.txt:
--------------------------------------------------------------------------------
1 | torch>=1.7.1
2 | torchvision
3 | ftfy
4 | regex
5 | tqdm
6 | clip @ git+https://github.com/openai/clip@e184f608c5d5e58165682f7c332c3a8b4c1545f2#egg=clip
7 |
--------------------------------------------------------------------------------
/allenact_plugins/distributions/__init__.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.distributions.distributions import (
2 | GaussianDistr,
3 | TruncatedNormal,
4 | DictActionSpaceDistr,
5 | StateDependentNoiseDistribution,
6 | )
7 |
8 | POSSIBLE_DIST = {
9 | "TruncatedNormal": TruncatedNormal,
10 | "GaussianDistr": GaussianDistr,
11 | "gSDE": StateDependentNoiseDistribution,
12 | }
13 |
--------------------------------------------------------------------------------
/allenact_plugins/ithor_plugin/__init__.py:
--------------------------------------------------------------------------------
1 | from allenact.utils.system import ImportChecker
2 |
3 | with ImportChecker(
4 | "Cannot `import ai2thor`, please install `ai2thor` (`pip install ai2thor`)."
5 | ):
6 | # noinspection PyUnresolvedReferences
7 | import ai2thor
8 |
--------------------------------------------------------------------------------
/allenact_plugins/ithor_plugin/extra_environment.yml:
--------------------------------------------------------------------------------
1 | channels:
2 | - defaults
3 | - conda-forge
4 | dependencies:
5 | - ai2thor>=2.5.3
6 | - numba
7 | - pip
8 | - colour
9 | - packaging
10 | - pip:
11 | - numpy-quaternion
12 | - pyquaternion>=0.9.9
13 | - python-xlib
14 |
--------------------------------------------------------------------------------
/allenact_plugins/ithor_plugin/extra_requirements.txt:
--------------------------------------------------------------------------------
1 | ai2thor>=2.5.3
2 | numpy-quaternion
3 | pyquaternion>=0.9.9
4 | colour
5 | numba
6 | packaging
7 | python-xlib
8 |
--------------------------------------------------------------------------------
/allenact_plugins/ithor_plugin/ithor_util.py:
--------------------------------------------------------------------------------
1 | import glob
2 | import math
3 | import os
4 | import platform
5 | import traceback
6 | import warnings
7 | from contextlib import contextmanager
8 | from typing import Sequence
9 |
10 | import Xlib
11 | import Xlib.display
12 | import ai2thor.controller
13 |
14 |
15 | @contextmanager
16 | def include_object_data(controller: ai2thor.controller.Controller):
17 | needs_reset = len(controller.last_event.metadata["objects"]) == 0
18 | try:
19 | if needs_reset:
20 | controller.step("ResetObjectFilter")
21 | assert controller.last_event.metadata["lastActionSuccess"]
22 | yield None
23 | finally:
24 | if needs_reset:
25 | controller.step("SetObjectFilter", objectIds=[])
26 | assert controller.last_event.metadata["lastActionSuccess"]
27 |
28 |
29 | def vertical_to_horizontal_fov(
30 | vertical_fov_in_degrees: float, height: float, width: float
31 | ):
32 | assert 0 < vertical_fov_in_degrees < 180
33 | aspect_ratio = width / height
34 | vertical_fov_in_rads = (math.pi / 180) * vertical_fov_in_degrees
35 | return (
36 | (180 / math.pi)
37 | * math.atan(math.tan(vertical_fov_in_rads * 0.5) * aspect_ratio)
38 | * 2
39 | )
40 |
41 |
42 | def horizontal_to_vertical_fov(
43 | horizontal_fov_in_degrees: float, height: float, width: float
44 | ):
45 | return vertical_to_horizontal_fov(
46 | vertical_fov_in_degrees=horizontal_fov_in_degrees, height=width, width=height,
47 | )
48 |
49 |
50 | def round_to_factor(num: float, base: int) -> int:
51 | """Rounds floating point number to the nearest integer multiple of the
52 | given base. E.g., for floating number 90.1 and integer base 45, the result
53 | is 90.
54 |
55 | # Attributes
56 |
57 | num : floating point number to be rounded.
58 | base: integer base
59 | """
60 | return round(num / base) * base
61 |
62 |
63 | def get_open_x_displays(throw_error_if_empty: bool = False) -> Sequence[str]:
64 | assert platform.system() == "Linux", "Can only get X-displays for Linux systems."
65 |
66 | displays = []
67 |
68 | open_display_strs = [
69 | os.path.basename(s)[1:] for s in glob.glob("/tmp/.X11-unix/X*")
70 | ]
71 |
72 | for open_display_str in sorted(open_display_strs):
73 | try:
74 | open_display_str = str(int(open_display_str))
75 | display = Xlib.display.Display(f":{open_display_str}")
76 | except Exception:
77 | warnings.warn(
78 | f"Encountered error when attempting to open display :{open_display_str},"
79 | f" error message:\n{traceback.format_exc()}"
80 | )
81 | continue
82 |
83 | displays.extend(
84 | [f"{open_display_str}.{i}" for i in range(display.screen_count())]
85 | )
86 |
87 | if throw_error_if_empty and len(displays) == 0:
88 | raise IOError(
89 | "Could not find any open X-displays on which to run AI2-THOR processes. "
90 | " Please see the AI2-THOR installation instructions at"
91 | " https://allenact.org/installation/installation-framework/#installation-of-ithor-ithor-plugin"
92 | " for information as to how to start such displays."
93 | )
94 |
95 | return displays
96 |
--------------------------------------------------------------------------------
/allenact_plugins/ithor_plugin/scripts/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/ithor_plugin/scripts/__init__.py
--------------------------------------------------------------------------------
/allenact_plugins/ithor_plugin/scripts/make_objectnav_debug_dataset.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | from allenact_plugins.robothor_plugin.scripts.make_objectnav_debug_dataset import (
4 | create_debug_dataset_from_train_dataset,
5 | )
6 |
7 | if __name__ == "__main__":
8 | CURRENT_PATH = os.getcwd()
9 |
10 | SCENE = "FloorPlan1"
11 | TARGET = "Apple"
12 | EPISODES = [0, 7, 11, 12]
13 | BASE_OUT = os.path.join(CURRENT_PATH, "datasets", "ithor-objectnav", "debug")
14 |
15 | create_debug_dataset_from_train_dataset(
16 | scene=SCENE,
17 | target_object_type=TARGET,
18 | episodes_subset=EPISODES,
19 | train_dataset_path=os.path.join(
20 | CURRENT_PATH, "datasets", "ithor-objectnav", "train"
21 | ),
22 | base_debug_output_path=BASE_OUT,
23 | )
24 |
--------------------------------------------------------------------------------
/allenact_plugins/ithor_plugin/scripts/make_pointnav_debug_dataset.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | from allenact_plugins.robothor_plugin.scripts.make_objectnav_debug_dataset import (
4 | create_debug_dataset_from_train_dataset,
5 | )
6 |
7 | if __name__ == "__main__":
8 | CURRENT_PATH = os.getcwd()
9 | SCENE = "FloorPlan1"
10 | EPISODES = [0, 7, 11, 12]
11 | BASE_OUT = os.path.join(CURRENT_PATH, "datasets", "ithor-pointnav", "debug")
12 |
13 | create_debug_dataset_from_train_dataset(
14 | scene=SCENE,
15 | target_object_type=None,
16 | episodes_subset=EPISODES,
17 | train_dataset_path=os.path.join(
18 | CURRENT_PATH, "datasets", "ithor-pointnav", "train"
19 | ),
20 | base_debug_output_path=BASE_OUT,
21 | )
22 |
--------------------------------------------------------------------------------
/allenact_plugins/models/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/models/__init__.py
--------------------------------------------------------------------------------
/allenact_plugins/models/nn/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/models/nn/__init__.py
--------------------------------------------------------------------------------
/allenact_plugins/models/nn/resnet.py:
--------------------------------------------------------------------------------
1 | from typing import Optional, Dict, Literal, Union
2 |
3 | import numpy as np
4 | import torch
5 | import torch.nn as nn
6 | from torchvision import models
7 |
8 | from allenact.base_abstractions.sensor import SpaceDict
9 | from allenact_plugins.models.nn.visual_base import VisualBase
10 |
11 |
12 | class ResNetEncoder(VisualBase):
13 | def __init__(
14 | self,
15 | observation_space: SpaceDict,
16 | *,
17 | output_size: int,
18 | rgb_uuid: Optional[str],
19 | num_stacked_frames: Optional[int] = None,
20 | channel_first: bool = True,
21 | resnet_name: str = "resnet18",
22 | pretrained: bool = False,
23 | freeze: bool = False,
24 | **kwargs,
25 | ):
26 | assert (
27 | resnet_name in models.resnet.__all__
28 | ), f"{resnet_name} not in {models.resnet.__all__}"
29 | self._pretrained = pretrained
30 | self._freeze = freeze
31 | super().__init__(
32 | observation_space=observation_space,
33 | output_size=output_size,
34 | rgb_uuid=rgb_uuid,
35 | num_stacked_frames=num_stacked_frames,
36 | channel_first=channel_first,
37 | resnet_name=resnet_name,
38 | **kwargs,
39 | )
40 | self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
41 | self.fc = nn.Linear(self.in_planes, output_size)
42 |
43 | def setup_model(
44 | self,
45 | output_size: int,
46 | input_dims: np.ndarray,
47 | input_channels: int,
48 | resnet_name: Literal["resnet18", "resnet18_gn"] = "resnet18",
49 | **kwargs,
50 | ) -> nn.Module:
51 | resnet = getattr(models.resnet, resnet_name)(pretrained=self._pretrained)
52 | if input_channels != 3: # if frame-stacking
53 | resnet.conv1 = nn.Conv2d(
54 | input_channels, 64, kernel_size=7, stride=2, padding=3, bias=False
55 | )
56 |
57 | self.in_planes = resnet.inplanes
58 | resnet = nn.Sequential(*(list(resnet.children())[:-2]))
59 |
60 | if self._freeze:
61 | for param in resnet.parameters():
62 | param.requires_grad = False
63 | resnet.eval()
64 |
65 | return resnet
66 |
67 | def forward(self, x: Union[torch.Tensor, Dict[str, torch.Tensor]]) -> torch.Tensor:
68 | if isinstance(x, dict):
69 | x = x[self.rgb_uuid]
70 | leading_dim = x.shape[:-3]
71 |
72 | nagents: Optional[int] = x.shape[3] if len(x.shape) == 6 else None
73 | # Make FLAT_BATCH = nsteps * nsamplers (* nagents)
74 | x = x.view((-1,) + x.shape[2 + int(nagents is not None) :])
75 |
76 | if self._freeze:
77 | with torch.no_grad():
78 | x = self.model(x)
79 | else:
80 | x = self.model(x)
81 |
82 | x = self.avgpool(x)
83 | x = torch.flatten(x, 1)
84 | x = self.fc(x)
85 | x = x.view(*leading_dim, self.output_size)
86 | return x
87 |
--------------------------------------------------------------------------------
/allenact_plugins/models/nn/visual_base.py:
--------------------------------------------------------------------------------
1 | from typing import Dict, Optional, Union
2 |
3 | import numpy as np
4 | import torch
5 | import torch.nn as nn
6 |
7 | from allenact.base_abstractions.sensor import SpaceDict
8 |
9 |
10 | class VisualBase(nn.Module):
11 | """Base class of visual backbone followed by a fc layer for encoding rgb
12 | obs. Takes in observations (of type gym.spaces.dict) and produces an
13 | embedding of the `rgb_uuid` component.
14 |
15 | # Attributes
16 | observation_space: The observation_space of the agent, should have `rgb_uuid` component.
17 | output_size : The size of the embedding vector to produce.
18 | rgb_uuid: key in observation space for visual observation
19 | num_stacked_frames: num of frames that stacked in the color channel. None for no frame-stacking
20 | channel_first: whether chw dim for rgb obs
21 | flatten: whether flatten for final embedding
22 | output_relu: whether include relu for the final embedding
23 | """
24 |
25 | def __init__(
26 | self,
27 | observation_space: SpaceDict,
28 | *,
29 | output_size: int,
30 | rgb_uuid: str,
31 | num_stacked_frames: Optional[int] = None,
32 | channel_first: bool = True,
33 | # flatten: bool = True,
34 | # output_relu: bool = True,
35 | **kwargs,
36 | ):
37 | super().__init__()
38 | self.rgb_uuid = rgb_uuid
39 | self.channel_first = channel_first
40 | assert (
41 | self.rgb_uuid in observation_space.spaces
42 | ), f"{self.rgb_uuid} not in {observation_space.spaces}"
43 | self._n_input_rgb = observation_space.spaces[self.rgb_uuid].shape[
44 | 0 if channel_first else 2
45 | ] * (num_stacked_frames or 1)
46 | assert self._n_input_rgb >= 0
47 | input_rgb_dims = (
48 | observation_space.spaces[self.rgb_uuid].shape[1:]
49 | if channel_first
50 | else observation_space.spaces[self.rgb_uuid].shape[:2]
51 | )
52 | self.output_size = output_size
53 | self.model = self.setup_model(
54 | output_size=output_size,
55 | input_dims=np.array(input_rgb_dims, dtype=np.float32),
56 | input_channels=self._n_input_rgb,
57 | # flatten=flatten,
58 | # output_relu=output_relu,
59 | **kwargs,
60 | )
61 |
62 | def setup_model(
63 | self,
64 | output_size: int,
65 | input_dims: np.ndarray,
66 | input_channels: int,
67 | flatten: bool = True,
68 | output_relu: bool = True,
69 | **kwargs,
70 | ) -> nn.Module:
71 | """function for initialize a visual encoder."""
72 | raise NotImplementedError
73 |
74 | def forward(
75 | self, observations: Union[torch.Tensor, Dict[str, torch.Tensor]]
76 | ) -> torch.Tensor:
77 | raise NotImplementedError
78 |
--------------------------------------------------------------------------------
/allenact_plugins/navigation_plugin/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/navigation_plugin/__init__.py
--------------------------------------------------------------------------------
/allenact_plugins/navigation_plugin/objectnav/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/navigation_plugin/objectnav/__init__.py
--------------------------------------------------------------------------------
/allenact_plugins/navigation_plugin/pointnav/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/navigation_plugin/pointnav/__init__.py
--------------------------------------------------------------------------------
/allenact_plugins/robothor_plugin/__init__.py:
--------------------------------------------------------------------------------
1 | from allenact.utils.system import ImportChecker
2 |
3 | with ImportChecker(
4 | "Cannot `import ai2thor`, please install `ai2thor` (`pip install ai2thor`)."
5 | ):
6 | # noinspection PyUnresolvedReferences
7 | import ai2thor
8 |
--------------------------------------------------------------------------------
/allenact_plugins/robothor_plugin/configs/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/robothor_plugin/configs/__init__.py
--------------------------------------------------------------------------------
/allenact_plugins/robothor_plugin/extra_environment.yml:
--------------------------------------------------------------------------------
1 | channels:
2 | - defaults
3 | - conda-forge
4 | dependencies:
5 | - ai2thor>=2.5.3
6 | - numba
7 | - pip
8 | - colour
9 | - packaging
10 | - pip:
11 | - numpy-quaternion
12 | - pyquaternion>=0.9.9
13 | - python-xlib
14 |
--------------------------------------------------------------------------------
/allenact_plugins/robothor_plugin/extra_requirements.txt:
--------------------------------------------------------------------------------
1 | ai2thor>=2.5.3
2 | numpy-quaternion
3 | pyquaternion>=0.9.9
4 | colour
5 | numba
6 | packaging
7 | python-xlib
8 |
--------------------------------------------------------------------------------
/allenact_plugins/robothor_plugin/robothor_constants.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.ithor_plugin.ithor_util import horizontal_to_vertical_fov
2 |
3 | MOVE_AHEAD = "MoveAhead"
4 | ROTATE_LEFT = "RotateLeft"
5 | ROTATE_RIGHT = "RotateRight"
6 | LOOK_DOWN = "LookDown"
7 | LOOK_UP = "LookUp"
8 | END = "End"
9 | PASS = "Pass"
10 |
11 | CAMERA_WIDTH = 400
12 | CAMERA_HEIGHT = 300
13 | HORIZONTAL_FIELD_OF_VIEW = 79
14 |
15 |
16 | DEFAULT_REWARD_CONFIG = {
17 | "step_penalty": -0.01,
18 | "goal_success_reward": 10.0,
19 | "failed_stop_reward": 0.0, # TODO for RF/RM
20 | "reached_max_steps_reward": 0.0,
21 | "shaping_weight": 1.0,
22 | }
23 |
24 | THOR_COMMIT_ID = "5ca1d87decf19ff0d473d4430029a2f3bcd2eaab"
25 | OBJNAV_DEFAULT_ENV_ARGS = dict(
26 | width=CAMERA_WIDTH,
27 | height=CAMERA_HEIGHT,
28 | continuousMode=True,
29 | applyActionNoise=True,
30 | rotateStepDegrees=30.0,
31 | visibilityDistance=1.0, # 1.5,
32 | gridSize=0.25,
33 | snapToGrid=False,
34 | agentMode="locobot",
35 | fieldOfView=horizontal_to_vertical_fov(
36 | horizontal_fov_in_degrees=HORIZONTAL_FIELD_OF_VIEW,
37 | width=CAMERA_WIDTH,
38 | height=CAMERA_HEIGHT,
39 | ),
40 | include_private_scenes=False,
41 | commit_id=THOR_COMMIT_ID,
42 | )
43 |
44 | OBJ_NAV_TARGET_TYPES = tuple(
45 | sorted(
46 | [
47 | "AlarmClock",
48 | "Apple",
49 | "BaseballBat",
50 | "BasketBall",
51 | "Bowl",
52 | "GarbageCan",
53 | "HousePlant",
54 | "Laptop",
55 | "Mug",
56 | "SprayBottle",
57 | "Television",
58 | "Vase",
59 | ]
60 | )
61 | )
62 |
63 |
64 | # For state irreversible measure
65 | STATE_MEASURE_CONFIGS = dict(
66 | std=dict(
67 | history=dict(agent=[]),
68 | thresholds=dict(agent=0.1, num_phases_irr_tolerance=2),
69 | metrics=dict(name="std", agent=None),
70 | ),
71 | euclidean=dict(
72 | history=dict(agent=[]),
73 | thresholds=dict(agent=0.1),
74 | metrics=dict(name="euclidean", agent=None),
75 | time_horizons=dict(memory=500, measure_steps=100),
76 | ),
77 | )
78 |
--------------------------------------------------------------------------------
/allenact_plugins/robothor_plugin/robothor_distributions.py:
--------------------------------------------------------------------------------
1 | from typing import Tuple
2 |
3 | import torch
4 |
5 | from allenact.base_abstractions.distributions import CategoricalDistr, Distr
6 |
7 |
8 | class TupleCategoricalDistr(Distr):
9 | def __init__(self, probs=None, logits=None, validate_args=None):
10 | self.dists = CategoricalDistr(
11 | probs=probs, logits=logits, validate_args=validate_args
12 | )
13 |
14 | def log_prob(self, actions: Tuple[torch.LongTensor, ...]) -> torch.FloatTensor:
15 | # flattened output [steps, samplers, num_agents]
16 | return self.dists.log_prob(torch.stack(actions, dim=-1))
17 |
18 | def entropy(self) -> torch.FloatTensor:
19 | # flattened output [steps, samplers, num_agents]
20 | return self.dists.entropy()
21 |
22 | def sample(self, sample_shape=torch.Size()) -> Tuple[torch.LongTensor, ...]:
23 | # split and remove trailing singleton dim
24 | res = self.dists.sample(sample_shape).split(1, dim=-1)
25 | return tuple([r.view(r.shape[:2]) for r in res])
26 |
27 | def mode(self) -> Tuple[torch.LongTensor, ...]:
28 | # split and remove trailing singleton dim
29 | res = self.dists.mode().split(1, dim=-1)
30 | return tuple([r.view(r.shape[:2]) for r in res])
31 |
--------------------------------------------------------------------------------
/allenact_plugins/robothor_plugin/robothor_models.py:
--------------------------------------------------------------------------------
1 | from typing import Tuple, Optional
2 |
3 | import gym
4 | import torch
5 | from gym.spaces import Dict as SpaceDict
6 |
7 | from allenact.algorithms.onpolicy_sync.policy import (
8 | ActorCriticModel,
9 | LinearActorCriticHead,
10 | DistributionType,
11 | Memory,
12 | ObservationType,
13 | )
14 | from allenact.base_abstractions.misc import ActorCriticOutput
15 | from allenact.embodiedai.models.basic_models import RNNStateEncoder, SimpleCNN
16 | from allenact_plugins.robothor_plugin.robothor_distributions import (
17 | TupleCategoricalDistr,
18 | )
19 |
20 |
21 | class TupleLinearActorCriticHead(LinearActorCriticHead):
22 | def forward(self, x):
23 | out = self.actor_and_critic(x)
24 |
25 | logits = out[..., :-1]
26 | values = out[..., -1:]
27 | # noinspection PyArgumentList
28 | return (
29 | TupleCategoricalDistr(logits=logits), # [steps, samplers, ...]
30 | values.view(*values.shape[:2], -1), # [steps, samplers, flattened]
31 | )
32 |
33 |
34 | class NavToPartnerActorCriticSimpleConvRNN(ActorCriticModel[TupleCategoricalDistr]):
35 | action_space: gym.spaces.Tuple
36 |
37 | def __init__(
38 | self,
39 | action_space: gym.spaces.Tuple,
40 | observation_space: SpaceDict,
41 | rgb_uuid: Optional[str] = "rgb",
42 | hidden_size=512,
43 | num_rnn_layers=1,
44 | rnn_type="GRU",
45 | ):
46 | super().__init__(action_space=action_space, observation_space=observation_space)
47 |
48 | self._hidden_size = hidden_size
49 |
50 | self.rgb_uuid = rgb_uuid
51 |
52 | self.visual_encoder = SimpleCNN(
53 | observation_space=observation_space,
54 | output_size=hidden_size,
55 | rgb_uuid=self.rgb_uuid,
56 | depth_uuid=None,
57 | )
58 |
59 | self.state_encoder = RNNStateEncoder(
60 | 0 if self.is_blind else self.recurrent_hidden_state_size,
61 | self._hidden_size,
62 | num_layers=num_rnn_layers,
63 | rnn_type=rnn_type,
64 | )
65 |
66 | self.actor_critic = TupleLinearActorCriticHead(
67 | self._hidden_size, action_space[0].n
68 | )
69 |
70 | self.train()
71 |
72 | @property
73 | def output_size(self):
74 | return self._hidden_size
75 |
76 | @property
77 | def is_blind(self):
78 | return self.visual_encoder.is_blind
79 |
80 | @property
81 | def num_recurrent_layers(self):
82 | return self.state_encoder.num_recurrent_layers
83 |
84 | @property
85 | def recurrent_hidden_state_size(self):
86 | return self._hidden_size
87 |
88 | @property
89 | def num_agents(self):
90 | return len(self.action_space)
91 |
92 | def _recurrent_memory_specification(self):
93 | return dict(
94 | rnn=(
95 | (
96 | ("layer", self.num_recurrent_layers),
97 | ("sampler", None),
98 | ("agent", self.num_agents),
99 | ("hidden", self.recurrent_hidden_state_size),
100 | ),
101 | torch.float32,
102 | )
103 | )
104 |
105 | def forward( # type:ignore
106 | self,
107 | observations: ObservationType,
108 | memory: Memory,
109 | prev_actions: torch.Tensor,
110 | masks: torch.FloatTensor,
111 | ) -> Tuple[ActorCriticOutput[DistributionType], Optional[Memory]]:
112 | if not self.is_blind:
113 | perception_embed = self.visual_encoder(observations)
114 | else:
115 | # TODO manage blindness for all agents simultaneously or separate?
116 | raise NotImplementedError()
117 |
118 | # TODO alternative where all agents consume all observations
119 | x, rnn_hidden_states = self.state_encoder(
120 | perception_embed, memory.tensor("rnn"), masks
121 | )
122 |
123 | dists, vals = self.actor_critic(x)
124 |
125 | return (
126 | ActorCriticOutput(distributions=dists, values=vals, extras={},),
127 | memory.set_tensor("rnn", rnn_hidden_states),
128 | )
129 |
--------------------------------------------------------------------------------
/allenact_plugins/robothor_plugin/scripts/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/robothor_plugin/scripts/__init__.py
--------------------------------------------------------------------------------
/allenact_plugins/robothor_plugin/scripts/make_objectnav_debug_dataset.py:
--------------------------------------------------------------------------------
1 | import gzip
2 | import json
3 | import os
4 | from typing import Sequence, Optional
5 |
6 | from allenact_plugins.robothor_plugin.robothor_task_samplers import (
7 | ObjectNavDatasetTaskSampler,
8 | )
9 |
10 |
11 | def create_debug_dataset_from_train_dataset(
12 | scene: str,
13 | target_object_type: Optional[str],
14 | episodes_subset: Sequence[int],
15 | train_dataset_path: str,
16 | base_debug_output_path: str,
17 | ):
18 | downloaded_episodes = os.path.join(
19 | train_dataset_path, "episodes", scene + ".json.gz"
20 | )
21 |
22 | assert os.path.exists(downloaded_episodes), (
23 | "'{}' doesn't seem to exist or is empty. Make sure you've downloaded to download the appropriate"
24 | " training dataset with"
25 | " datasets/download_navigation_datasets.sh".format(downloaded_episodes)
26 | )
27 |
28 | # episodes
29 | episodes = ObjectNavDatasetTaskSampler.load_dataset(
30 | scene=scene, base_directory=os.path.join(train_dataset_path, "episodes")
31 | )
32 |
33 | if target_object_type is not None:
34 | ids = {
35 | "{}_{}_{}".format(scene, target_object_type, epit)
36 | for epit in episodes_subset
37 | }
38 | else:
39 | ids = {"{}_{}".format(scene, epit) for epit in episodes_subset}
40 | debug_episodes = [ep for ep in episodes if ep["id"] in ids]
41 | assert len(ids) == len(debug_episodes), (
42 | f"Number of input ids ({len(ids)}) does not equal"
43 | f" number of output debug tasks ({len(debug_episodes)})"
44 | )
45 |
46 | # sort by episode_ids
47 | debug_episodes = [
48 | idep[1]
49 | for idep in sorted(
50 | [(int(ep["id"].split("_")[-1]), ep) for ep in debug_episodes],
51 | key=lambda x: x[0],
52 | )
53 | ]
54 | assert len(debug_episodes) == len(episodes_subset)
55 |
56 | episodes_dir = os.path.join(base_debug_output_path, "episodes")
57 | os.makedirs(episodes_dir, exist_ok=True)
58 | episodes_file = os.path.join(episodes_dir, scene + ".json.gz")
59 |
60 | json_str = json.dumps(debug_episodes)
61 | json_bytes = json_str.encode("utf-8")
62 | with gzip.GzipFile(episodes_file, "w") as fout:
63 | fout.write(json_bytes)
64 | assert os.path.exists(episodes_file)
65 |
66 |
67 | if __name__ == "__main__":
68 | CURRENT_PATH = os.getcwd()
69 | SCENE = "FloorPlan_Train1_1"
70 | TARGET = "Television"
71 | EPISODES = [0, 7, 11, 12]
72 | BASE_OUT = os.path.join(CURRENT_PATH, "datasets", "robothor-objectnav", "debug")
73 |
74 | create_debug_dataset_from_train_dataset(
75 | scene=SCENE,
76 | target_object_type=TARGET,
77 | episodes_subset=EPISODES,
78 | train_dataset_path=os.path.join(
79 | CURRENT_PATH, "datasets", "robothor-objectnav", "train"
80 | ),
81 | base_debug_output_path=BASE_OUT,
82 | )
83 |
--------------------------------------------------------------------------------
/allenact_plugins/robothor_plugin/scripts/make_pointnav_debug_dataset.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | from allenact_plugins.robothor_plugin.scripts.make_objectnav_debug_dataset import (
4 | create_debug_dataset_from_train_dataset,
5 | )
6 |
7 | if __name__ == "__main__":
8 | CURRENT_PATH = os.getcwd()
9 | SCENE = "FloorPlan_Train1_1"
10 | EPISODES = [3, 4, 5, 6]
11 | BASE_OUT = os.path.join(CURRENT_PATH, "datasets", "robothor-pointnav", "debug")
12 |
13 | create_debug_dataset_from_train_dataset(
14 | scene=SCENE,
15 | target_object_type=None,
16 | episodes_subset=EPISODES,
17 | train_dataset_path=os.path.join(
18 | CURRENT_PATH, "datasets", "robothor-pointnav", "train"
19 | ),
20 | base_debug_output_path=BASE_OUT,
21 | )
22 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/__init__.py:
--------------------------------------------------------------------------------
1 | from .registered_envs import *
2 | from .sawyer_peg_env import *
3 | from .sawyer_peg_plugins import *
4 | from .state_distribution_wrapper import *
5 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/constants.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 |
4 | STATE_MEASURE_CONFIGS = dict(
5 | std=dict(
6 | history=dict(tcp_center=[], obj_pos=[]),
7 | thresholds=dict(tcp_center=0.01, obj_pos=0.001, num_phases_irr_tolerance=2),
8 | metrics=dict(name="std", tcp_center=0.0, obj_pos=0.0),
9 | ),
10 | euclidean=dict(
11 | history=dict(tcp_and_obj=[]),
12 | thresholds=dict(tcp_and_obj=0.01), # 0.01 for max(mean()) is good
13 | metrics=dict(name="euclidean", tcp_and_obj=0.0),
14 | time_horizons=dict(memory=500, measure_steps=100),
15 | schedule=dict(min=500, max=1000, schedule_steps=1e4), # not necessary tho
16 | ),
17 | dtw=dict(
18 | history=dict(tcp_and_obj=[]),
19 | thresholds=dict(tcp_and_obj=0.05),
20 | metrics=dict(name="dtw", tcp_and_obj=0.0),
21 | time_horizons=dict(memory=500, measure_steps=100),
22 | ),
23 | entropy=dict(
24 | history=dict(tcp_and_obj=[]),
25 | thresholds=dict(tcp_and_obj=1.4, num_phases_irr_tolerance=2),
26 | metrics=dict(name="entropy", tcp_and_obj=0.0),
27 | grid_size=[20, 20, 10],
28 | ),
29 | )
30 |
31 | BASIC_SPACE = dict(
32 | obj_low=(0.0, 0.5, 0.02),
33 | obj_high=(0.2, 0.7, 0.02),
34 | goal_low=(-0.35, 0.5, -0.001),
35 | goal_high=(-0.25, 0.7, 0.001),
36 | )
37 | WIDER_SPACE = dict(
38 | obj_low=(-0.3, 0.35, 0.02),
39 | obj_high=(0.1, 0.85, 0.02),
40 | goal_low=(-0.525, 0.3, -0.001), # 0.4
41 | goal_high=(-0.525, 0.75, 0.001), # 0.7
42 | )
43 |
44 | COMPUTER_REWARD_KWARGS_FULL = dict(
45 | obj_to_target_reward_coef=100.0,
46 | tcp_to_obj_reward_coef=100.0,
47 | gripper_width_reward_coef=2.0,
48 | z_reward_coef=2.0,
49 | use_z_reward=True,
50 | obj_to_target_scale=np.array([1.0, 2.0, 2.0]),
51 | use_first_grasped_reward=True,
52 | use_gripper_reward=True,
53 | )
54 | COMPUTER_REWARD_KWARGS_MIN = dict(
55 | obj_to_target_reward_coef=100.0,
56 | tcp_to_obj_reward_coef=100.0,
57 | use_z_reward=False,
58 | obj_to_target_scale=1,
59 | use_first_grasped_reward=False,
60 | use_gripper_reward=False,
61 | )
62 | POSSIBLE_REWARD_KWARGS = dict(
63 | full=COMPUTER_REWARD_KWARGS_FULL, min=COMPUTER_REWARD_KWARGS_MIN
64 | )
65 |
66 |
67 | # Copy from EARL
68 | INITIAL_STATES = np.array(
69 | [
70 | [0.00615235, 0.6001898, 0.19430117, 1.0, 0.00313463, 0.68326396, 0.02],
71 | [0.00615235, 0.6001898, 0.19430117, 1.0, -0.04035005, 0.67949003, 0.02],
72 | [0.00615235, 0.6001898, 0.19430117, 1.0, 0.02531051, 0.6074387, 0.02],
73 | [0.00615235, 0.6001898, 0.19430117, 1.0, 0.05957219, 0.6271171, 0.02],
74 | [0.00615235, 0.6001898, 0.19430117, 1.0, -0.07566337, 0.62575287, 0.02],
75 | [0.00615235, 0.6001898, 0.19430117, 1.0, -0.01177235, 0.55206996, 0.02],
76 | [0.00615235, 0.6001898, 0.19430117, 1.0, 0.02779735, 0.54707706, 0.02],
77 | [0.00615235, 0.6001898, 0.19430117, 1.0, 0.01835314, 0.5329686, 0.02],
78 | [0.00615235, 0.6001898, 0.19430117, 1.0, 0.02690855, 0.6263067, 0.02],
79 | [0.00615235, 0.6001898, 0.19430117, 1.0, 0.01766127, 0.59630984, 0.02],
80 | [0.00615235, 0.6001898, 0.19430117, 1.0, 0.0560186, 0.6634998, 0.02],
81 | [0.00615235, 0.6001898, 0.19430117, 1.0, -0.03950658, 0.6323736, 0.02],
82 | [0.00615235, 0.6001898, 0.19430117, 1.0, -0.03216827, 0.5247563, 0.02],
83 | [0.00615235, 0.6001898, 0.19430117, 1.0, 0.01265727, 0.69466716, 0.02],
84 | [0.00615235, 0.6001898, 0.19430117, 1.0, 0.05076993, 0.6025737, 0.02],
85 | ]
86 | )
87 |
88 | GOAL_STATES = np.array([[0.0, 0.6, 0.2, 1.0, -0.3 + 0.03, 0.6, 0.0 + 0.13]])
89 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/assets/peg_block.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/assets/peg_block_dependencies.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/assets/peg_block_random_hole.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/assets/peg_insert.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/assets/peg_insert_dependencies.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/assets/xyz_base_dependencies.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/peg_block/block_inner.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/peg_block/block_inner.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/peg_block/block_outer.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/peg_block/block_outer.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/table/table_hole.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/table/table_hole.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/table/table_hole2.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/table/table_hole2.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/table/tablebody.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/table/tablebody.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/table/tabletop.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/table/tabletop.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/base.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/base.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/eGripperBase.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/eGripperBase.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/head.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/head.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/l0.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/l0.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/l1.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/l1.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/l2.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/l2.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/l3.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/l3.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/l4.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/l4.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/l5.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/l5.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/l6.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/l6.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/pedestal.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/meshes/xyz_base/pedestal.stl
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/peg_insert.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/objects/xyz_base.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/sawyer_xyz/sawyer_peg_insertion_side.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/sawyer_xyz/sawyer_peg_insertion_side_small_table.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/scene/basic_scene.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
8 |
9 |
10 |
11 |
12 |
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 |
40 |
41 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
52 |
54 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/scene/basic_scene_b.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/scene/basic_scene_c.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
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 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_assets/scene/basic_scene_small_table.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
8 |
9 |
10 |
11 |
12 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
37 |
38 |
40 |
41 |
43 |
45 |
47 |
48 |
49 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/sawyer_peg_plugins.py:
--------------------------------------------------------------------------------
1 | from typing import Union, List
2 |
3 | from allenact_plugins.wrappers import (
4 | TaskWrapper,
5 | Phase0TaskWrapper,
6 | Phase1TaskWrapper,
7 | SinglePhaseTaskSampler,
8 | AdvTaskSampler,
9 | MultiDiscretizeEnvWrapper,
10 | )
11 | from .sawyer_peg_env import SawyerPegV2Base
12 |
13 | __all__ = [
14 | "SawyerPegMultiDiscretizeEnv",
15 | "MultiDiscretizeSawyerPegTaskSampler",
16 | "TwoPhasesSawyerPegMultiDiscreteTaskSampler",
17 | ]
18 |
19 |
20 | class SawyerPegMultiDiscretizeEnv(MultiDiscretizeEnvWrapper):
21 | def __init__(self, env_name: str, num_bins: int = 7, **kwargs):
22 | super().__init__(env_name=env_name, num_bins=num_bins, **kwargs)
23 |
24 |
25 | def task_selector(env_name: Union[str, SawyerPegV2Base]) -> Union[type, List[type]]:
26 | if isinstance(env_name, str):
27 | two_phases = (
28 | "RF" in env_name or "Adv" in env_name
29 | ) and "Random" not in env_name
30 | else:
31 | two_phases = env_name.two_phases and env_name.reset_free
32 | if two_phases:
33 | return [Phase0TaskWrapper, Phase1TaskWrapper]
34 | else:
35 | return TaskWrapper
36 |
37 |
38 | class TwoPhasesSawyerPegMultiDiscreteTaskSampler(AdvTaskSampler):
39 | """Two adversarial RF Sawyer Peg w/ multi discrete action space."""
40 |
41 | def __init__(self, **kwargs):
42 | super().__init__(
43 | task_selector=task_selector,
44 | env_wrapper=SawyerPegMultiDiscretizeEnv,
45 | **kwargs
46 | )
47 |
48 |
49 | class MultiDiscretizeSawyerPegTaskSampler(SinglePhaseTaskSampler):
50 | """Random Goal or Episodic Sawyer Peg."""
51 |
52 | def __init__(self, **kwargs):
53 | super().__init__(
54 | task_selector=task_selector,
55 | env_wrapper=SawyerPegMultiDiscretizeEnv,
56 | **kwargs
57 | )
58 |
--------------------------------------------------------------------------------
/allenact_plugins/sawyer_peg_plugin/state_distribution_wrapper.py:
--------------------------------------------------------------------------------
1 | from typing import Any, Union
2 |
3 | import gym
4 | import numpy as np
5 |
6 |
7 | class StateDistributionViz(gym.Wrapper):
8 | """Example of usage of Point Cloud visualization wrapper for Sawyer Peg."""
9 |
10 | def __init__(self, env: Union[str, Any], num_steps_recording: int = 1e5):
11 | if isinstance(env, str):
12 | env = gym.make(env)
13 | super().__init__(env)
14 | self.env = env
15 | self.num_accumulate_steps = 0
16 | self.num_steps_recording = num_steps_recording
17 | self.points = []
18 | self.traj_points = []
19 | self._init_peg = None
20 | self.log_point_cloud = False
21 |
22 | self.env.table_space = (
23 | gym.spaces.Box(
24 | high=np.array([0.45, 0.75, 0.0]), low=np.array([-0.45, 0.45, -0.027])
25 | )
26 | if self.env.small_table
27 | else gym.spaces.Box(
28 | high=np.array([0.65, 1.0, 0.0]), low=np.array([-0.65, 0.2, -0.027])
29 | )
30 | )
31 |
32 | def start_new_recording_point_cloud(self):
33 | self.log_point_cloud = False
34 | self.points = []
35 |
36 | def reset(self, **kwargs):
37 | obs = super().reset(**kwargs)
38 | if self.num_accumulate_steps >= self.num_steps_recording:
39 | self.log_point_cloud = True
40 | self.num_accumulate_steps = 0
41 | else:
42 | self.log_point_cloud = False
43 | self._init_peg = self.env.obj_pos
44 | if isinstance(self._init_peg, np.ndarray):
45 | self._init_peg = self._init_peg.tolist()
46 | self.traj_points = [self._init_peg]
47 | return obs
48 |
49 | def step(self, action: np.ndarray) -> tuple:
50 | rtn = super().step(action)
51 |
52 | self.num_accumulate_steps += 1
53 | peg_pos = self.env.obj_pos
54 | if isinstance(peg_pos, np.ndarray):
55 | peg_pos = peg_pos.tolist()
56 | self.traj_points.append(peg_pos)
57 | if self.env.done:
58 | color = [0, 255, 0] if self.env.info["success"] else [255, 0, 0]
59 | for point in self.traj_points:
60 | self.points.append(point + color)
61 | self.points.append(self.env._target_pos.tolist() + [255, 255, 255])
62 | return rtn
63 |
--------------------------------------------------------------------------------
/allenact_plugins/stretch_manipulathor_plugin/__init__.py:
--------------------------------------------------------------------------------
1 | # from .categories import *
2 | # from .dataset_utils import *
3 | # from .strech_sensors import *
4 | # from .strech_task_sampler_exproom import *
5 | # from .stretch_arm_environment import *
6 | # from .stretch_constants import *
7 | # from .stretch_sim2real_utils import *
8 | # from .stretch_tasks import *
9 | # from .stretch_utils import *
10 |
--------------------------------------------------------------------------------
/allenact_plugins/stretch_manipulathor_plugin/stretch_tasks/__init__.py:
--------------------------------------------------------------------------------
1 | from .strech_pick_place import *
2 | from .stretch_task_base import *
3 |
--------------------------------------------------------------------------------
/allenact_plugins/utils/__init__.py:
--------------------------------------------------------------------------------
1 | from .array_tensor_utils import *
2 | from .config_utils import *
3 | from .env_utils import *
4 | from .file_utils import *
5 | from .measure_buffer import *
6 | from .metics import *
7 | from .plt_utils import *
8 | from .video_utils import *
9 | from .wandb_utils import *
10 |
--------------------------------------------------------------------------------
/allenact_plugins/utils/env_utils.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | import gym
4 | import numpy as np
5 |
6 | __all__ = [
7 | "register_gym_env",
8 | "get_file",
9 | "dict_space_to_gym_space",
10 | "dict_space_to_gym_Box_space",
11 | ]
12 |
13 |
14 | def register_gym_env(env_id: str, **kwargs):
15 | """decorator for gym env registration."""
16 |
17 | def _register(cls):
18 | gym.register(
19 | id=env_id, entry_point=f"{cls.__module__}:{cls.__name__}", kwargs=kwargs
20 | )
21 | return cls
22 |
23 | return _register
24 |
25 |
26 | def get_file(f_cur: str, tar_dir: str, tar_name: str):
27 | """return abs path of the target file in terms of current file.
28 |
29 | Example: get f_name file abs path in current file.
30 | - parent_dir
31 | - tar_dir
32 | - tar_name
33 | - f_cur
34 | or
35 | - parent_dir
36 | - tar_dir
37 | - tar_name
38 | - cur_dir
39 | f_cur
40 | """
41 | parent_dir = os.path.dirname(os.path.realpath(f_cur))
42 | tar_dir_path = os.path.join(parent_dir, tar_dir)
43 | if not os.path.exists(tar_dir_path):
44 | tar_dir_path = os.path.join(os.path.dirname(parent_dir), tar_dir)
45 | return os.path.join(tar_dir_path, tar_name)
46 |
47 |
48 | def dict_space_to_gym_space(space) -> gym.spaces.Dict:
49 | _space = space if isinstance(space, dict) else space.to_dict()
50 | return gym.spaces.Dict(
51 | {
52 | i: gym.spaces.Box(
53 | low=_space["low"][i],
54 | high=_space["high"][i],
55 | shape=(1,),
56 | dtype=np.float32,
57 | )
58 | for i in ["x", "y", "z"]
59 | }
60 | )
61 |
62 |
63 | def dict_space_to_gym_Box_space(space) -> gym.spaces.Box:
64 | _space = space if isinstance(space, dict) else space.to_dict()
65 | return gym.spaces.Box(
66 | low=np.array([_space["low"][i] for i in ["x", "y", "z"]]),
67 | high=np.array([_space["high"][i] for i in ["x", "y", "z"]]),
68 | shape=(3,),
69 | dtype=np.float32,
70 | )
71 |
--------------------------------------------------------------------------------
/allenact_plugins/utils/file_utils.py:
--------------------------------------------------------------------------------
1 | import errno
2 | import glob
3 | import json
4 | import os
5 | import shutil
6 |
7 |
8 | __all__ = [
9 | "f_expand",
10 | "f_join",
11 | "f_listdir",
12 | "f_mkdir",
13 | "f_remove",
14 | "load_json",
15 | "dump_json",
16 | ]
17 |
18 |
19 | def f_expand(fpath):
20 | return os.path.expandvars(os.path.expanduser(fpath))
21 |
22 |
23 | def f_exists(*fpaths):
24 | return os.path.exists(f_join(*fpaths))
25 |
26 |
27 | def f_join(*fpaths):
28 | """join file paths and expand special symbols like `~` for home dir."""
29 | return f_expand(os.path.join(*fpaths))
30 |
31 |
32 | def f_listdir(*fpaths, filter=None, sort=False, full_path=False, nonexist_ok=True):
33 | """
34 | Args:
35 | full_path: True to return full paths to the dir contents
36 | filter: function that takes in file name and returns True to include
37 | nonexist_ok: True to return [] if the dir is non-existent, False to raise
38 | sort: sort the file names by alphabetical
39 | """
40 | dir_path = f_join(*fpaths)
41 | if not os.path.exists(dir_path) and nonexist_ok:
42 | return []
43 | files = os.listdir(dir_path)
44 | if filter is not None:
45 | files = [f for f in files if filter(f)]
46 | if sort:
47 | files.sort()
48 | if full_path:
49 | return [os.path.join(dir_path, f) for f in files]
50 | else:
51 | return files
52 |
53 |
54 | def f_mkdir(*fpaths):
55 | """Recursively creates all the subdirs If exist, do nothing."""
56 | fpath = f_join(*fpaths)
57 | os.makedirs(fpath, exist_ok=True)
58 | return fpath
59 |
60 |
61 | def f_remove(fpath, verbose=False, dry_run=False):
62 | """If exist, remove.
63 |
64 | Supports both dir and file. Supports glob wildcard.
65 | """
66 | assert isinstance(verbose, bool)
67 | fpath = f_expand(fpath)
68 | if dry_run:
69 | print("Dry run, delete:", fpath)
70 | return
71 | for f in glob.glob(fpath):
72 | try:
73 | shutil.rmtree(f)
74 | except OSError as e:
75 | if e.errno == errno.ENOTDIR:
76 | try:
77 | os.remove(f)
78 | except: # final resort safeguard
79 | pass
80 | if verbose:
81 | print(f'Deleted "{fpath}"')
82 |
83 |
84 | def load_json(*file_path, **kwargs):
85 | file_path = f_join(*file_path)
86 |
87 | with open(file_path, "r") as fp:
88 | return json.load(fp, **kwargs)
89 |
90 |
91 | def dump_json(data, *file_path, convert_to_primitive=False, **kwargs):
92 | if convert_to_primitive:
93 | from .array_tensor_utils import any_to_primitive
94 |
95 | data = any_to_primitive(data)
96 | file_path = f_join(*file_path)
97 | with open(file_path, "w") as fp:
98 | json.dump(data, fp, **kwargs)
99 |
--------------------------------------------------------------------------------
/allenact_plugins/utils/plt_utils.py:
--------------------------------------------------------------------------------
1 | from typing import List, Union, Any
2 |
3 | import cv2
4 | import numpy as np
5 |
6 | __all__ = ["round_metrics", "debug_texts_to_frame", "add_boundary_from_success"]
7 |
8 |
9 | def round_metrics(metrics: Any, n: int = 4) -> Any:
10 | if isinstance(metrics, (float, int)):
11 | return round(metrics, n)
12 | elif isinstance(metrics, dict):
13 | return {k: round_metrics(v) for k, v in metrics.items()}
14 | elif isinstance(metrics, (list, tuple)):
15 | return type(metrics)([round_metrics(m) for m in metrics])
16 | else:
17 | return metrics
18 |
19 |
20 | def debug_texts_to_frame(
21 | frame: np.ndarray, debug_text: Union[List[str], dict], **kwargs
22 | ) -> np.ndarray:
23 | if isinstance(debug_text, dict):
24 | text_list = [f"{k}: {v}" for k, v in debug_text.items()]
25 | else:
26 | text_list = debug_text
27 | org_x_init = kwargs.pop("org_x_init", 10)
28 | org_x_increment = kwargs.pop("org_x_increment", 0)
29 | org_y_init = kwargs.pop("org_y_init", 30)
30 | org_y_increment = kwargs.pop("org_y_increment", 20)
31 |
32 | cv2_kwargs = dict(
33 | fontFace=cv2.FONT_HERSHEY_SIMPLEX,
34 | fontScale=0.5,
35 | color=(0, 255, 0),
36 | thickness=1,
37 | lineType=cv2.LINE_AA,
38 | )
39 | cv2_kwargs.update(kwargs)
40 | for i, txt in enumerate(text_list):
41 | cv2.putText(
42 | frame,
43 | txt,
44 | (org_x_init + i * org_x_increment, org_y_init + i * org_y_increment),
45 | **cv2_kwargs,
46 | )
47 | return frame
48 |
49 |
50 | def add_boundary_from_success(
51 | frame: np.ndarray,
52 | success: bool,
53 | padding: int = 5,
54 | success_color: tuple = (0, 255, 0),
55 | fail_color: tuple = (255, 0, 0),
56 | ) -> np.ndarray:
57 | color = np.array(success_color) if success else np.array(fail_color)
58 | h, w, c = frame.shape
59 | new_h, new_w = h + 2 * padding, w + 2 * padding
60 | new_frame = np.full((new_h, new_w, c), color, dtype=np.uint8)
61 | new_frame[padding:-padding, padding:-padding] = frame
62 | return new_frame
63 |
--------------------------------------------------------------------------------
/allenact_plugins/utils/video_utils.py:
--------------------------------------------------------------------------------
1 | import subprocess
2 | from typing import Union, List, Optional
3 |
4 | import numpy as np
5 | import torch
6 |
7 | from allenact_plugins.utils.array_tensor_utils import (
8 | any_stack,
9 | any_to_torch_tensor,
10 | any_to_numpy,
11 | )
12 | from .file_utils import f_mkdir, f_join, f_remove
13 |
14 | __all__ = ["save_video", "compress_video", "VideoTensorWriter", "ffmpeg_save_video"]
15 |
16 |
17 | def save_video(video: Union[np.ndarray, torch.Tensor], fname, fps=None):
18 | import torchvision.io
19 | from einops import rearrange
20 |
21 | video = any_to_torch_tensor(video)
22 | assert video.ndim == 4, "must be 4D tensor"
23 | assert (
24 | video.size(1) == 3 or video.size(3) == 3
25 | ), "shape should be either T3HW or THW3"
26 |
27 | if video.size(1) == 3:
28 | video = rearrange(video, "T C H W -> T H W C")
29 | torchvision.io.write_video(fname, video, fps=fps)
30 |
31 |
32 | def ffmpeg_save_video(
33 | video: Union[np.ndarray, torch.Tensor], fname: str, fps: Optional[int] = None,
34 | ):
35 | import ffmpeg
36 | from einops import rearrange
37 |
38 | video = any_to_numpy(video)
39 | assert video.ndim == 4, f"must be 4D array, {video.shape}"
40 | assert (
41 | video.shape[1] == 3 or video.shape[3] == 3
42 | ), "shape should be either T3HW or THW3"
43 | if video.shape[1] == 3:
44 | video = rearrange(video, "T C H W -> T H W C")
45 |
46 | out = ffmpeg.input(
47 | "pipe:",
48 | format="rawvideo",
49 | pix_fmt="rgb24",
50 | s="{}x{}".format(video.shape[2], video.shape[1], r=fps or 30),
51 | ).output(
52 | fname,
53 | vcodec="libx264",
54 | crf=28,
55 | preset="fast",
56 | pix_fmt="yuv420p",
57 | loglevel="quiet",
58 | y="-y", # Allow overwriting the output file
59 | )
60 | process = out.run_async(pipe_stdin=True)
61 | # for frame in video:
62 | # process.stdin.write(frame.tobytes())
63 | # process.stdin.close()
64 | # process.wait()
65 | try:
66 | for frame in video:
67 | process.stdin.write(frame.tobytes())
68 | except BrokenPipeError:
69 | print("error")
70 | pass
71 |
72 | process.stdin.close()
73 | process.wait()
74 |
75 |
76 | def compress_video(in_mp4_path: str, out_mp4_path: str, delete_input: bool = True):
77 | commands_list = [
78 | "ffmpeg",
79 | "-v",
80 | "quiet",
81 | "-y",
82 | "-i",
83 | in_mp4_path,
84 | "-vcodec",
85 | "libx264",
86 | "-crf",
87 | "28",
88 | out_mp4_path,
89 | ]
90 | assert subprocess.run(commands_list).returncode == 0, commands_list
91 | if delete_input:
92 | f_remove(in_mp4_path)
93 |
94 |
95 | class VideoTensorWriter:
96 | def __init__(self, folder=".", fps=40):
97 | self._folder = folder
98 | self._fps = fps
99 | self._frames = []
100 |
101 | @property
102 | def frames(self) -> List[np.ndarray]:
103 | return self._frames
104 |
105 | def add_frame(self, frame: Union[np.ndarray, torch.Tensor]):
106 | assert len(frame.shape) == 3
107 | self._frames.append(frame)
108 |
109 | def clear(self):
110 | self._frames = []
111 |
112 | def save(
113 | self,
114 | step: Union[int, str],
115 | save: bool = True,
116 | suffix: Optional[str] = None,
117 | fps: Optional[int] = None,
118 | compress: bool = True,
119 | ) -> str:
120 | """
121 | Requires:
122 | pip install av
123 | """
124 | fps = fps or self._fps
125 | fname = str(step) if suffix is None else f"{step}-{suffix}"
126 | in_fname = f"{fname}_raw.mp4" if compress else f"{fname}.mp4"
127 | in_path = f_join(self._folder, in_fname)
128 | out_path = f_join(self._folder, f"{fname}.mp4")
129 | if save:
130 | f_mkdir(self._folder)
131 | save_video(any_stack(self._frames, dim=0), in_path, fps=fps)
132 | if compress:
133 | compress_video(in_path, out_path, delete_input=True)
134 | self.clear()
135 | # clear in record env wrapper if not `save`
136 | return out_path
137 |
--------------------------------------------------------------------------------
/allenact_plugins/utils/wandb_utils.py:
--------------------------------------------------------------------------------
1 | import copy
2 | from typing import Union
3 |
4 | import gym.spaces
5 | import numpy as np
6 |
7 | from .array_tensor_utils import any_to_primitive
8 |
9 | # from allenact_plugins.stretch_manipulathor_plugin.dataset_utils import TaskData
10 |
11 |
12 | __all__ = [
13 | "thor_points_to_wandb_points",
14 | "sphere_to_corner_points",
15 | "center_size_to_corner_points",
16 | "space_to_corner_points",
17 | ]
18 |
19 |
20 | def thor_points_to_wandb_points(
21 | points: Union[list, np.ndarray], return_list: bool = True
22 | ):
23 | """(x, y, z, ...) in thor to (z, -x, y, ...)"""
24 | if not isinstance(points, np.ndarray):
25 | points = np.array(points)
26 | assert points.ndim == 2, (points.ndim, points.shape)
27 | xyz_shape = points.shape[1]
28 | transpose_shape = [2, 0, 1] + [3 + i for i in range(xyz_shape - 3)]
29 | flipped_points = points[:, transpose_shape]
30 | flipped_points[:, 0] = -flipped_points[:, 0]
31 | return any_to_primitive(flipped_points) if return_list else flipped_points
32 |
33 |
34 | def sphere_to_corner_points(center: dict, r: float) -> list:
35 | """corner points from sphere of dict of xyz and radius."""
36 | x, y, z = center["x"], center["y"], center["z"]
37 | return [
38 | [x - r, y - r, z - r],
39 | [x - r, y - r, z + r],
40 | [x - r, y + r, z - r],
41 | [x - r, y + r, z + r],
42 | [x + r, y - r, z - r],
43 | [x + r, y - r, z + r],
44 | [x + r, y + r, z - r],
45 | [x + r, y + r, z + r],
46 | ]
47 |
48 |
49 | def center_size_to_corner_points(center: dict, size: dict) -> list:
50 | cx, cy, cz = center["x"], center["y"], center["z"]
51 | hx, hy, hz = size["x"] / 2, size["y"] / 2, size["z"] / 2
52 | return [
53 | [cx - hx, cy - hy, cz - hz],
54 | [cx + hx, cy - hy, cz - hz],
55 | [cx + hx, cy + hy, cz - hz],
56 | [cx - hx, cy + hy, cz - hz],
57 | [cx - hx, cy - hy, cz + hz],
58 | [cx + hx, cy - hy, cz + hz],
59 | [cx + hx, cy + hy, cz + hz],
60 | [cx - hx, cy + hy, cz + hz],
61 | ]
62 |
63 |
64 | def space_to_corner_points(
65 | space: Union[gym.spaces.Box, "TaskData.Space", dict]
66 | ) -> list:
67 | from allenact_plugins.stretch_manipulathor_plugin.dataset_utils import (
68 | TaskData,
69 | ) # circular import issue
70 |
71 | assert isinstance(space, (gym.spaces.Box, TaskData.Space, dict)), type(space)
72 | if isinstance(space, dict):
73 | space = TaskData.Space(copy.deepcopy(space))
74 | l, h = space.low, space.high
75 | lx, ly, lz = l if isinstance(space, gym.spaces.Box) else l.x, l.y, l.z
76 | hx, hy, hz = h if isinstance(space, gym.spaces.Box) else h.x, h.y, h.z
77 | return [
78 | [lx, ly, lz],
79 | [lx, hy, lz],
80 | [lx, ly, hz],
81 | [lx, hy, hz],
82 | [hx, ly, lz],
83 | [hx, hy, lz],
84 | [hx, ly, hz],
85 | [hx, hy, hz],
86 | ]
87 |
--------------------------------------------------------------------------------
/allenact_plugins/wrappers/__init__.py:
--------------------------------------------------------------------------------
1 | from .env_wrappers import *
2 | from .exp_wrappers import *
3 | from .sensor_wrappers import *
4 | from .task_sampler_wrappers import *
5 | from .task_wrappers import *
6 |
--------------------------------------------------------------------------------
/conda/environment-base.yml:
--------------------------------------------------------------------------------
1 | channels:
2 | - defaults
3 | - pytorch
4 | - conda-forge
5 | dependencies:
6 | - python=3.8
7 | - cudatoolkit=11.6
8 | - pytorch:pytorch==1.12.1
9 | - pytorch:torchvision==0.13.1
10 | - ai2thor>=2.5.3
11 | - attrs==22.1.0
12 | - attr==0.3.2
13 | - filelock==3.0.12
14 | - matplotlib==3.3.3
15 | - moviepy==1.0.3
16 | - networkx==2.5
17 | - numpy
18 | - numba
19 | - opencv_python==4.5.1.48
20 | - Pillow==9.2.0
21 | - PyYAML==6.0
22 | - scipy==1.7.3
23 | - setproctitle==1.2.1
24 | - setuptools==63.4.1
25 | - tensorboard==2.10.1
26 | - tensorboardX==2.5.1
27 | - tree==0.2.4
28 | - typing_extensions==4.4.0
29 | - pip:
30 | - dm-tree==0.1.7
31 | - einops==0.5.0
32 | - ftfy
33 | - hydra-core==1.3.0
34 | - mujoco-py>=2.1,<2.2
35 | - numpy-quaternion
36 | - omegaconf==2.2.3
37 | - pyquaternion>=0.9.9
38 | - python-xlib
39 | - regex
40 | - tqdm
41 | - wandb==0.13.9
42 | - "--editable=git+https://github.com/openai/CLIP.git@e184f608c5d5e58165682f7c332c3a8b4c1545f2#egg=clip"
43 | - git+https://github.com/Farama-Foundation/Metaworld.git@master#egg=metaworld
44 |
--------------------------------------------------------------------------------
/conda/environment-dev.yml:
--------------------------------------------------------------------------------
1 | channels:
2 | - defaults
3 | - conda-forge
4 | dependencies:
5 | - black=19.10b0
6 | - docformatter>=1.3.1
7 | - gitpython
8 | - markdown>=3.3
9 | - mkdocs>=1.1.2
10 | - mkdocs-material>=5.5.3
11 | - mkdocs-material-extensions>=1.0
12 | - mypy
13 | - pre-commit
14 | - pytest>=6.1.1
15 | - ruamel.yaml
16 | - pip:
17 | - pydoc-markdown>=3.4.0
18 |
--------------------------------------------------------------------------------
/datasets/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 | !*.sh
4 | !.habitat_datasets_download_info.json
5 | !.habitat_downloader_helper.py
6 | !habitat/configs/debug_habitat_pointnav.yaml
7 |
--------------------------------------------------------------------------------
/datasets/.habitat_datasets_download_info.json:
--------------------------------------------------------------------------------
1 | {
2 | "pointnav-gibson-v1": {
3 | "link": "https://dl.fbaipublicfiles.com/habitat/data/datasets/pointnav/gibson/v1/pointnav_gibson_v1.zip",
4 | "rel_path": "data/datasets/pointnav/gibson/v1/",
5 | "config_url": "configs/datasets/imagenav/gibson.yaml"
6 | },
7 | "pointnav-gibson-v2": {
8 | "link": "https://dl.fbaipublicfiles.com/habitat/data/datasets/pointnav/gibson/v2/pointnav_gibson_v2.zip",
9 | "rel_path": "data/datasets/pointnav/gibson/v2/",
10 | "config_url": "configs/datasets/pointnav/gibson.yaml"
11 | },
12 | "pointnav-mp3d-v1": {
13 | "link": "https://dl.fbaipublicfiles.com/habitat/data/datasets/pointnav/mp3d/v1/pointnav_mp3d_v1.zip",
14 | "rel_path": "data/datasets/pointnav/mp3d/v1/",
15 | "config_url": "configs/datasets/imagenav/mp3d.yaml"
16 | },
17 | "objectnav-mp3d-v1": {
18 | "link": "https://dl.fbaipublicfiles.com/habitat/data/datasets/objectnav/m3d/v1/objectnav_mp3d_v1.zip",
19 | "rel_path": "data/datasets/objectnav/mp3d/v1/",
20 | "config_url": "configs/datasets/objectnav/mp3d.yaml"
21 | },
22 | "eqa-mp3d-v1": {
23 | "link": "https://dl.fbaipublicfiles.com/habitat/data/datasets/eqa/mp3d/v1/eqa_mp3d_v1.zip",
24 | "rel_path": "data/datasets/eqa/mp3d/v1/",
25 | "config_url": "configs/datasets/eqa/mp3d.yaml"
26 | },
27 | "vln-r2r-mp3d-v1": {
28 | "link": "https://dl.fbaipublicfiles.com/habitat/data/datasets/vln/mp3d/r2r/v1/vln_r2r_mp3d_v1.zip",
29 | "rel_path": "data/datasets/vln/mp3d/r2r/v1",
30 | "config_url": "configs/datasets/vln/mp3d_r2r.yaml"
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/datasets/download_habitat_datasets.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Move to the directory containing this file
4 | cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" || exit
5 |
6 | mkdir -p habitat
7 | mkdir -p habitat/scene_datasets
8 | mkdir -p habitat/datasets
9 | mkdir -p habitat/configs
10 |
11 | cd habitat || exit
12 |
13 | output_archive_name=__TO_OVERWRITE__.zip
14 | deletable_dir_name=__TO_DELETE__
15 |
16 | install_test_scenes_and_data() {
17 | if ! wget http://dl.fbaipublicfiles.com/habitat/habitat-test-scenes.zip -O $output_archive_name; then
18 | echo "Could not unzip download test scenes from http://dl.fbaipublicfiles.com/habitat/habitat-test-scenes.zip"
19 | exit 1
20 | fi
21 | if ! unzip $output_archive_name -d $deletable_dir_name; then
22 | echo "Could not unzip $output_archive_name to $deletable_dir_name"
23 | exit 1
24 | fi
25 | rsync -avz $deletable_dir_name/data/datasets . && \
26 | rsync -avz $deletable_dir_name/data/scene_datasets . && \
27 | rm $output_archive_name && \
28 | rm -r $deletable_dir_name
29 | }
30 |
31 | install_scene_data() {
32 | python3 ../.habitat_downloader_helper.py "$1"
33 | }
34 |
35 | if [ "$1" = "test-scenes" ]
36 | then
37 | install_test_scenes_and_data
38 |
39 | else
40 | install_scene_data $1
41 | fi
42 |
43 |
--------------------------------------------------------------------------------
/datasets/download_navigation_datasets.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Move to the directory containing this file
4 | cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" || exit
5 |
6 | install_dataset() {
7 | dataset_name="$1"
8 | download_suffix="$2"
9 | if ! mkdir "$dataset_name" ; then
10 | echo "Could not create directory " $(pwd)/$dataset_name "Does it already exist? If so, delete it."
11 | exit 1
12 | fi
13 | url_archive_name=$dataset_name$download_suffix.tar.gz
14 | output_archive_name=__TO_OVERWRITE__.tar.gz
15 | wget https://prior-datasets.s3.us-east-2.amazonaws.com/embodied-ai/navigation/$url_archive_name -O $output_archive_name
16 | tar -xf "$output_archive_name" -C "$dataset_name" --strip-components=1 && rm $output_archive_name
17 | echo "saved folder: "$dataset_name""
18 | }
19 |
20 |
21 | # Download, Unzip, and Remove zip
22 | if [ "$1" = "robothor-pointnav" ]
23 | then
24 | echo "Downloading RoboTHOR PointNav Dataset ..."
25 | install_dataset "$1" "-v0"
26 | cd ..
27 | echo "Generating RoboTHOR PointNav Debug Dataset ..."
28 | PYTHONPATH=. python ./allenact_plugins/robothor_plugin/scripts/make_pointnav_debug_dataset.py
29 |
30 | elif [ "$1" = "robothor-objectnav" ]
31 | then
32 | echo "Downloading RoboTHOR ObjectNav Dataset ..."
33 | install_dataset "$1" "-challenge-2021"
34 | cd ..
35 | echo "Generating RoboTHOR ObjectNav Debug Dataset ..."
36 | PYTHONPATH=. python ./allenact_plugins/robothor_plugin/scripts/make_objectnav_debug_dataset.py
37 |
38 | elif [ "$1" = "ithor-pointnav" ]
39 | then
40 | echo "Downloading iTHOR PointNav Dataset ..."
41 | install_dataset "$1" "-v0"
42 | cd ..
43 | echo "Generating iTHOR PointNav Debug Dataset ..."
44 | PYTHONPATH=. python ./allenact_plugins/ithor_plugin/scripts/make_pointnav_debug_dataset.py
45 |
46 | elif [ "$1" = "ithor-objectnav" ]
47 | then
48 | echo "Downloading iTHOR ObjectNav Dataset ..."
49 | install_dataset "$1" "-v0"
50 | cd ..
51 | echo "Generating iTHOR ObjectNav Debug Dataset ..."
52 | PYTHONPATH=. python ./allenact_plugins/ithor_plugin/scripts/make_objectnav_debug_dataset.py
53 |
54 | elif [ "$1" = "all-thor" ]
55 | then
56 | bash download_navigation_datasets.sh "robothor-pointnav"
57 | bash download_navigation_datasets.sh "robothor-objectnav"
58 | bash download_navigation_datasets.sh "ithor-pointnav"
59 | bash download_navigation_datasets.sh "ithor-objectnav"
60 |
61 | else
62 | echo "\nFailed: Usage download_navigation_datasets.sh robothor-pointnav | robothor-objectnav | ithor-pointnav | ithor-objectnav | all-thor"
63 | exit 1
64 | fi
65 |
--------------------------------------------------------------------------------
/dev_requirements.txt:
--------------------------------------------------------------------------------
1 | black==19.10b0
2 | ruamel.yaml
3 | gitpython
4 | markdown==3.3
5 | mypy
6 | pytest
7 | docformatter==1.3.1
8 | docstr-coverage==1.2.0
9 | mkdocs==1.1.2
10 | mkdocs-material==5.5.3
11 | pre-commit
12 | pydoc-markdown==3.4.0
13 | compress-pickle==1.2.0
14 |
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | """Entry point to training/validating/testing for a user given experiment
3 | name."""
4 | import allenact.main
5 |
6 | if __name__ == "__main__":
7 | allenact.main.main()
8 |
--------------------------------------------------------------------------------
/projects/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/__init__.py
--------------------------------------------------------------------------------
/projects/objectnav/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/objectnav/__init__.py
--------------------------------------------------------------------------------
/projects/objectnav/experiments/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/objectnav/experiments/__init__.py
--------------------------------------------------------------------------------
/projects/objectnav/experiments/clip/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/objectnav/experiments/clip/__init__.py
--------------------------------------------------------------------------------
/projects/objectnav/experiments/clip/cfg/clip_resnet50_gru.yaml:
--------------------------------------------------------------------------------
1 | # Config file
2 |
3 | tag: "ObjectNav-RoboTHOR-RGB-ClipResNet50GRU-DDPPO"
4 |
5 | general:
6 | num_processes: 60 # 12 * 5
7 | val_processes: 1
8 | test_processes: 15
9 | worker_per_device: 1
10 | headless: false
11 | train_gpus: null
12 | validation_gpus: null
13 | testing_gpus: [0,1,2,3]
14 | train_dataset_dir: "datasets/robothor-objectnav/train"
15 | validation_dataset_dir: "datasets/robothor-objectnav/val"
16 | test_dataset_dir: "datasets/robothor-objectnav/val"
17 | validation_tasks: 1
18 | testing_tasks: null # all
19 | visualize: false
20 | visualize_test: false
21 | viz_mode: debug # "rgb"
22 | viz_class:
23 | - video_viz
24 | # - base_trajectory
25 | # - thor_trajectory
26 | viz_fps: 10
27 | callback_kwargs:
28 | sync: true
29 | wandb_project:
30 | wandb_entity:
31 |
32 | sampler_kwargs:
33 | task_args:
34 | done_always_terminate: true
35 | randomize_materials: false
36 | randomize_lightning: false
37 | # rewrite in each python experiment config
38 | reset_free: false
39 | measurement_lead_reset: true
40 | measure_method: std
41 | num_steps_for_reset: 10000
42 |
43 |
44 | valid_sampler_kwargs:
45 | task_args:
46 | done_always_terminate: true
47 | randomize_materials: false
48 | randomize_lightning: false
49 | reset_free: false
50 |
51 |
52 | model_kwargs:
53 | rgb_resnet_preprocessor_uuid: "rgb_clip_resnet"
54 | depth_resnet_preprocessor_uuid: null
55 | hidden_size: 512
56 | goal_dims: 32
57 | num_rnn_layers: 1
58 | rnn_type: "GRU"
59 | add_prev_actions: false
60 | action_embed_size: 6
61 |
62 |
63 | training_pipeline:
64 | lr: 3e-4
65 | end_lr: 1e-10
66 | lr_scheduler: "linear"
67 | loss_name: "ppo_loss"
68 | loss_steps: 300000000 # or 100 M
69 | num_steps: 128
70 | training_setting_kwargs:
71 | num_mini_batch: 1
72 | update_repeats: 4
73 | max_grad_norm: 0.5
74 | num_steps: ${training_pipeline.num_steps}
75 | gamma: 0.99
76 | use_gae: true
77 | gae_lambda: 0.95
78 | advance_scene_rollout_period: null
79 | save_interval: 5000000
80 | metric_accumulate_interval: 10000
81 | loss_kwargs:
82 | clip_param: 0.1
83 | value_loss_coef: 0.5
84 | entropy_coef: 0.01
85 | use_clipped_value_loss: true
86 | normalize_advantage: true
87 |
--------------------------------------------------------------------------------
/projects/objectnav/experiments/clip/mixins.py:
--------------------------------------------------------------------------------
1 | from typing import Sequence, Union
2 |
3 | import attr
4 | import numpy as np
5 |
6 | from allenact.base_abstractions.preprocessor import Preprocessor
7 | from allenact.base_abstractions.sensor import Sensor
8 | from allenact.embodiedai.sensors.vision_sensors import RGBSensor, DepthSensor
9 | from allenact.utils.experiment_utils import Builder
10 | from allenact_plugins.clip_plugin.clip_preprocessors import ClipResNetPreprocessor
11 |
12 |
13 | @attr.s(kw_only=True)
14 | class ClipResNetPreprocessorMixin:
15 | sensors: Sequence[Sensor] = attr.ib()
16 | rgb_output_uuid: str = attr.ib()
17 | depth_output_uuid: str = attr.ib(default=None)
18 | clip_model_type: str = attr.ib()
19 | pool: bool = attr.ib(default=False)
20 |
21 | def preprocessors(self) -> Sequence[Union[Preprocessor, Builder[Preprocessor]]]:
22 | preprocessors = []
23 |
24 | rgb_sensor = next((s for s in self.sensors if isinstance(s, RGBSensor)), None)
25 | assert (
26 | np.linalg.norm(
27 | np.array(rgb_sensor._norm_means)
28 | - np.array(ClipResNetPreprocessor.CLIP_RGB_MEANS)
29 | )
30 | < 1e-5
31 | )
32 | assert (
33 | np.linalg.norm(
34 | np.array(rgb_sensor._norm_sds)
35 | - np.array(ClipResNetPreprocessor.CLIP_RGB_STDS)
36 | )
37 | < 1e-5
38 | )
39 |
40 | if rgb_sensor is not None:
41 | preprocessors.append(
42 | ClipResNetPreprocessor(
43 | rgb_input_uuid=rgb_sensor.uuid,
44 | clip_model_type=self.clip_model_type,
45 | pool=self.pool,
46 | output_uuid=self.rgb_output_uuid,
47 | input_img_height_width=(rgb_sensor.height, rgb_sensor.width),
48 | )
49 | )
50 |
51 | depth_sensor = next(
52 | (s for s in self.sensors if isinstance(s, DepthSensor)), None
53 | )
54 | if depth_sensor is not None:
55 | assert self.depth_output_uuid is not None
56 | preprocessors.append(
57 | ClipResNetPreprocessor(
58 | rgb_input_uuid=depth_sensor.uuid,
59 | clip_model_type=self.clip_model_type,
60 | pool=self.pool,
61 | output_uuid=self.depth_output_uuid,
62 | input_img_height_width=(depth_sensor.height, depth_sensor.width),
63 | )
64 | )
65 |
66 | return preprocessors
67 |
--------------------------------------------------------------------------------
/projects/objectnav/experiments/clip/objnav_not_terminate_if_incorrect_done.py:
--------------------------------------------------------------------------------
1 | from projects.objectnav.experiments.clip.objectnav_robothor_rgb_clipresnet50gru_ddppo import (
2 | ObjectNavRoboThorClipRGBPPOExperimentConfig,
3 | get_config,
4 | )
5 |
6 |
7 | CFG = get_config(debug=False, reset_free=False, done_always_terminate=False)
8 |
9 |
10 | class ObjNavEpisodic(ObjectNavRoboThorClipRGBPPOExperimentConfig):
11 | cfg = CFG
12 |
13 | def __init__(self):
14 | # TODO mv to constants
15 | reward_config = {
16 | "step_penalty": -0.01,
17 | "goal_success_reward": 10.0,
18 | "failed_stop_reward": -0.05, # TODO
19 | "reached_max_steps_reward": 0.0,
20 | "shaping_weight": 1.0,
21 | }
22 | super().__init__(reward_config=reward_config)
23 |
24 | MAX_STEPS = 300 # 500
25 |
26 | @classmethod
27 | def tag(cls) -> str:
28 | return (
29 | "rf10-objnav-fixed_phase_length_unless_success-fail_step-0.05-maxstep=300"
30 | )
31 |
--------------------------------------------------------------------------------
/projects/objectnav/experiments/rmrl/1e4.py:
--------------------------------------------------------------------------------
1 | from projects.objectnav.experiments.clip.objectnav_robothor_rgb_clipresnet50gru_ddppo import (
2 | ObjectNavRoboThorClipRGBPPOExperimentConfig,
3 | get_config,
4 | )
5 |
6 |
7 | CFG = get_config(
8 | debug=False,
9 | done_always_terminate=False,
10 | reset_free=True,
11 | measurement_lead_reset=False,
12 | num_steps_for_reset=int(1e4),
13 | )
14 |
15 |
16 | class ObjNavEpisodic(ObjectNavRoboThorClipRGBPPOExperimentConfig):
17 | cfg = CFG
18 |
19 | def __init__(self):
20 | # TODO mv to constants
21 | reward_config = {
22 | "step_penalty": -0.01,
23 | "goal_success_reward": 10.0,
24 | "failed_stop_reward": -0.05, # TODO
25 | "reached_max_steps_reward": 0.0,
26 | "shaping_weight": 1.0,
27 | }
28 | super().__init__(reward_config=reward_config)
29 |
30 | MAX_STEPS = 300 # 500
31 |
32 | @classmethod
33 | def tag(cls) -> str:
34 | return "rf11-objnav-1e4"
35 |
--------------------------------------------------------------------------------
/projects/objectnav/experiments/rmrl/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/objectnav/experiments/rmrl/__init__.py
--------------------------------------------------------------------------------
/projects/objectnav/experiments/rmrl/inf.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 | from projects.objectnav.experiments.clip.objectnav_robothor_rgb_clipresnet50gru_ddppo import (
4 | ObjectNavRoboThorClipRGBPPOExperimentConfig,
5 | get_config,
6 | )
7 |
8 | CFG = get_config(
9 | debug=False,
10 | done_always_terminate=False,
11 | reset_free=True,
12 | measurement_lead_reset=False,
13 | num_steps_for_reset=np.inf,
14 | )
15 |
16 |
17 | class ObjNavEpisodic(ObjectNavRoboThorClipRGBPPOExperimentConfig):
18 | cfg = CFG
19 |
20 | def __init__(self):
21 | # TODO mv to constants
22 | reward_config = {
23 | "step_penalty": -0.01,
24 | "goal_success_reward": 10.0,
25 | "failed_stop_reward": -0.05, # TODO
26 | "reached_max_steps_reward": 0.0,
27 | "shaping_weight": 1.0,
28 | }
29 | super().__init__(reward_config=reward_config)
30 |
31 | MAX_STEPS = 300 # 500
32 |
33 | @classmethod
34 | def tag(cls) -> str:
35 | return "rf9-objnav-truly_RF"
36 |
--------------------------------------------------------------------------------
/projects/objectnav/experiments/rmrl/std.py:
--------------------------------------------------------------------------------
1 | from projects.objectnav.experiments.clip.objectnav_robothor_rgb_clipresnet50gru_ddppo import (
2 | ObjectNavRoboThorClipRGBPPOExperimentConfig,
3 | get_config,
4 | )
5 |
6 |
7 | CFG = get_config(
8 | debug=False,
9 | done_always_terminate=False,
10 | reset_free=True,
11 | measurement_lead_reset=True,
12 | measure_method="std",
13 | )
14 |
15 |
16 | class ObjNavStdMeasureRMRL(ObjectNavRoboThorClipRGBPPOExperimentConfig):
17 | cfg = CFG
18 |
19 | def __init__(self):
20 | reward_config = {
21 | "step_penalty": -0.01,
22 | "goal_success_reward": 10.0,
23 | "failed_stop_reward": -0.05,
24 | "reached_max_steps_reward": 0.0,
25 | "shaping_weight": 1.0,
26 | }
27 | super().__init__(reward_config=reward_config)
28 |
29 | MAX_STEPS = 300
30 |
31 | @classmethod
32 | def tag(cls) -> str:
33 | return "objnav-std-0.1"
34 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/sawyer_peg/__init__.py
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/sawyer_peg/experiments/__init__.py
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/cfg/low_dim.yaml:
--------------------------------------------------------------------------------
1 | # Config file
2 |
3 | tag: "RFRL - low dim obs"
4 |
5 | general:
6 | num_processes: 32
7 | worker_per_device: 1
8 | train_gpus: [0,1]
9 | eval_env: "SawyerPeg-v1"
10 | validation_gpus: null
11 | val_processes: 0 # only ckpt
12 | validation_tasks: 1
13 | testing_gpus: [0,1,2,3]
14 | testing_tasks: 50 # task * processes = 200
15 | test_processes: 4
16 | visualize: false
17 | visualize_test: false
18 | viz_mode: "rgb_array"
19 | viz_resolution:
20 | - 320
21 | - 240
22 | viz_fps: 40
23 | callback_kwargs:
24 | sync: true
25 | wandb_project:
26 | wandb_entity:
27 |
28 | sampler_kwargs:
29 | record_during_training: false
30 | num_record_processes: 3
31 | record_kwargs:
32 | mode: debug
33 | save: false
34 | save_path:
35 | record_rule:
36 | - 62500
37 | - 62500
38 | - 6
39 | fps: 30
40 | resolution:
41 | - 640
42 | - 480
43 |
44 | model_kwargs:
45 | num_stacked_frames: 4
46 | mlp_hidden_dims: [512, 256]
47 | shared_state_encoder: true
48 | separate_state_encoder: false
49 | critic_condition_action: false
50 | obs_feature_dim: 512
51 |
52 | training_pipeline:
53 | lr: 3e-4
54 | end_lr: 2e-4
55 | lr_scheduler: linear
56 | loss_name: "ppo_loss"
57 | loss_steps: 3e6
58 | num_steps: 300
59 | training_setting_kwargs:
60 | num_mini_batch: 4
61 | update_repeats: 10
62 | max_grad_norm: 0.5
63 | num_steps: ${training_pipeline.num_steps}
64 | gamma: 0.99
65 | use_gae: true
66 | gae_lambda: 0.95
67 | advance_scene_rollout_period: null
68 | save_interval: 1e5
69 | metric_accumulate_interval: 1
70 | loss_kwargs:
71 | clip_param: 0.2
72 | value_loss_coef: 0.3
73 | entropy_coef: 0.01
74 | use_clipped_value_loss: True
75 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/cfg/visual.yaml:
--------------------------------------------------------------------------------
1 | # Config file
2 |
3 | tag: "RFRL - visual"
4 |
5 | general:
6 | num_processes: 8
7 | worker_per_device: 1
8 | train_gpus: [0, 1]
9 | validation_gpus: null
10 | val_processes: 0 # only ckpt
11 | validation_tasks: 1
12 | testing_gpus: [0,1,2,3]
13 | test_processes: 4
14 | testing_tasks: 50 # task * processes = 200
15 | visualize: false
16 | visualize_test: false
17 | viz_mode: "obs"
18 | viz_fps: 40
19 | callback_kwargs:
20 | sync: true
21 | wandb_project:
22 | wandb_entity:
23 |
24 | sampler_kwargs:
25 | record_during_training: false
26 | num_record_processes: 1
27 | record_kwargs:
28 | mode: debug
29 | save: false
30 | record_rule:
31 | - 31250
32 | - 31250
33 | - 6
34 | fps: 30
35 | resolution:
36 | - 640
37 | - 480
38 |
39 | model_kwargs:
40 | num_stacked_frames: 1
41 | mlp_hidden_dims: [512, 256]
42 | low_dim_feature_dim: 512
43 | shared_state_encoder: true
44 | separate_state_encoder: false
45 | critic_condition_action: false
46 | use_action_embed: true
47 | action_embed_dim: 32 # 32 * 4 = 128
48 | squash_output: true
49 | orthogonal_init: false
50 | rgb_uuid: rgb
51 | state_uuid: state
52 | visual_encoder: "cnn"
53 | single_visual_encoder: true
54 | channel_first: true
55 | visual_output_size: 512
56 | visual_encoder_kwargs:
57 | flatten: true
58 | output_relu: true
59 | output_layer_norm: false
60 | layer_channels: [32, 64, 32]
61 | kernel_sizes: [8, 4, 3]
62 | layers_stride: [4, 2, 1]
63 | paddings: [0, 0, 0]
64 | dilations: [1, 1, 1]
65 | augmentation: random_shift
66 | augmentation_kwargs:
67 | pad: 4
68 | shift_together_if_cat: true
69 | same_shift_if_cat: null
70 |
71 |
72 | training_pipeline:
73 | lr: 5e-4
74 | end_lr: 3.5e-4
75 | lr_scheduler: "linear"
76 | loss_name: "ppo_loss"
77 | loss_steps: 3e6
78 | num_steps: 1024
79 | training_setting_kwargs:
80 | num_mini_batch: 1
81 | update_repeats: 20
82 | max_grad_norm: 0.5
83 | num_steps: ${training_pipeline.num_steps}
84 | gamma: 0.99
85 | use_gae: true
86 | gae_lambda: 0.95
87 | advance_scene_rollout_period: null
88 | save_interval: 100000 # 100k checkpointing
89 | metric_accumulate_interval: 1
90 | loss_kwargs:
91 | clip_param: 0.2
92 | value_loss_coef: 0.3
93 | entropy_coef: 0.01
94 | use_clipped_value_loss: true
95 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/cfg/visual_4_proc.yaml:
--------------------------------------------------------------------------------
1 | # Config file
2 |
3 | tag: "RFRL - visual"
4 |
5 | general:
6 | num_processes: 4
7 | worker_per_device: 1
8 | train_gpus: [2]
9 | val_processes: 0 # only ckpt
10 | validation_tasks: 1
11 | testing_gpus: [0,1,2,3]
12 | test_processes: 4
13 | testing_tasks: 50 # task * processes = 200
14 | visualize: false
15 | visualize_test: false
16 | viz_mode: "obs"
17 | viz_fps: 40
18 | callback_kwargs:
19 | sync: true
20 | wandb_project:
21 | wandb_entity:
22 |
23 | sampler_kwargs:
24 | record_during_training: false
25 | num_record_processes: 1
26 | record_kwargs:
27 | mode: debug
28 | save: false
29 | record_rule:
30 | - 31250
31 | - 31250
32 | - 6
33 | fps: 30
34 | resolution:
35 | - 640
36 | - 480
37 |
38 | model_kwargs:
39 | num_stacked_frames: 1
40 | mlp_hidden_dims: [512, 256]
41 | low_dim_feature_dim: 512
42 | shared_state_encoder: true
43 | separate_state_encoder: false
44 | critic_condition_action: false
45 | use_action_embed: true
46 | action_embed_dim: 32 # 32 * 4 = 128
47 | squash_output: true
48 | orthogonal_init: false
49 | rgb_uuid: rgb
50 | state_uuid: state
51 | visual_encoder: "cnn"
52 | single_visual_encoder: true
53 | channel_first: true
54 | visual_output_size: 512
55 | visual_encoder_kwargs:
56 | flatten: true
57 | output_relu: true
58 | output_layer_norm: false
59 | layer_channels: [32, 64, 32]
60 | kernel_sizes: [8, 4, 3]
61 | layers_stride: [4, 2, 1]
62 | paddings: [0, 0, 0]
63 | dilations: [1, 1, 1]
64 | augmentation: random_shift
65 | augmentation_kwargs:
66 | pad: 4
67 | shift_together_if_cat: true
68 | same_shift_if_cat: null
69 |
70 |
71 | training_pipeline:
72 | lr: 5e-4
73 | end_lr: 3.5e-4
74 | lr_scheduler: "linear"
75 | loss_name: "ppo_loss"
76 | loss_steps: 3e6
77 | num_steps: 1024
78 | training_setting_kwargs:
79 | num_mini_batch: 1
80 | update_repeats: 20
81 | max_grad_norm: 0.5
82 | num_steps: ${training_pipeline.num_steps}
83 | gamma: 0.99
84 | use_gae: true
85 | gae_lambda: 0.95
86 | advance_scene_rollout_period: null
87 | save_interval: 5e5 # TODO 1e5?
88 | metric_accumulate_interval: 1
89 | loss_kwargs:
90 | clip_param: 0.2
91 | value_loss_coef: 0.3
92 | entropy_coef: 0.01
93 | use_clipped_value_loss: true
94 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/measure_variations/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/sawyer_peg/experiments/measure_variations/__init__.py
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/measure_variations/visual_dtw.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
2 | from allenact_plugins.wrappers import DictObsSensor
3 | from ..visual_base import SawyerPegRFRandomAlmostReversibleVisual, get_config
4 |
5 |
6 | class SawyerPegRFRandomAlmostReversibleVisualDTW(
7 | SawyerPegRFRandomAlmostReversibleVisual
8 | ):
9 | processes = 8
10 | cfg = get_config(processes, debug=False)
11 | ENV = parse_sawyer_peg_env("visual_dtw_measure")
12 | input_uuid = "sawyer_peg_obs"
13 | SENSORS = [
14 | DictObsSensor(
15 | uuid=input_uuid,
16 | num_stacked_frames=cfg.model_kwargs["num_stacked_frames"],
17 | env_name=ENV,
18 | ),
19 | ]
20 | MEASUREMENT = "dtw"
21 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/measure_variations/visual_entropy.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
2 | from allenact_plugins.wrappers import DictObsSensor
3 | from ..visual_base import SawyerPegRFRandomAlmostReversibleVisual, get_config
4 |
5 |
6 | class SawyerPegRFRandomAlmostReversibleVisualentropy(
7 | SawyerPegRFRandomAlmostReversibleVisual
8 | ):
9 | processes = 8
10 | cfg = get_config(processes, debug=False)
11 | ENV = parse_sawyer_peg_env("visual_entropy_measure")
12 | input_uuid = "sawyer_peg_obs"
13 | SENSORS = [
14 | DictObsSensor(
15 | uuid=input_uuid,
16 | num_stacked_frames=cfg.model_kwargs["num_stacked_frames"],
17 | env_name=ENV,
18 | ),
19 | ]
20 | MEASUREMENT = "entropy"
21 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/measure_variations/visual_euclidean.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
2 | from allenact_plugins.wrappers import DictObsSensor
3 | from ..visual_base import SawyerPegRFRandomAlmostReversibleVisual, get_config
4 |
5 |
6 | class SawyerPegRFRandomAlmostReversibleVisualEuclidean(
7 | SawyerPegRFRandomAlmostReversibleVisual
8 | ):
9 | processes = 8
10 | cfg = get_config(processes, debug=False)
11 | ENV = parse_sawyer_peg_env("visual_euclidean_measure")
12 | input_uuid = "sawyer_peg_obs"
13 | SENSORS = [
14 | DictObsSensor(
15 | uuid=input_uuid,
16 | num_stacked_frames=cfg.model_kwargs["num_stacked_frames"],
17 | env_name=ENV,
18 | ),
19 | ]
20 | MEASUREMENT = "euclidean"
21 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/measure_variations/visual_std.py:
--------------------------------------------------------------------------------
1 | from ..visual_base import SawyerPegRFRandomAlmostReversibleVisual
2 |
3 |
4 | class SawyerPegRFRandomAlmostReversibleVisualBaseline(
5 | SawyerPegRFRandomAlmostReversibleVisual
6 | ):
7 | ...
8 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/method/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/sawyer_peg/experiments/method/__init__.py
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/method/visual.py:
--------------------------------------------------------------------------------
1 | from ..visual_base import SawyerPegRFRandomAlmostReversibleVisual
2 |
3 |
4 | class SawyerPegRFRandomAlmostReversibleVisualBaseline(
5 | SawyerPegRFRandomAlmostReversibleVisual
6 | ):
7 | ...
8 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/method/visual_adv.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.models.actor_critic_visual import DiscreteActorCriticVisual
2 | from allenact_plugins.sawyer_peg_plugin import (
3 | SawyerPegMultiDiscretizeEnv,
4 | MultiDiscretizeSawyerPegTaskSampler,
5 | TwoPhasesSawyerPegMultiDiscreteTaskSampler,
6 | )
7 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
8 | from allenact_plugins.wrappers import ExperimentConfigBase, DictObsSensor
9 | from projects.sawyer_peg.experiments.visual_base import get_config
10 |
11 |
12 | CFG = get_config(8, debug=False)
13 | with CFG.unlocked():
14 | CFG.train_gpus = [0, 1]
15 |
16 |
17 | class SawyerPegRFVisualTwoPhases(ExperimentConfigBase):
18 |
19 | cfg = CFG
20 |
21 | ENV = parse_sawyer_peg_env(
22 | [
23 | "visual_obs_kwargs",
24 | "two_phases_kwargs",
25 | "fixed_resets_kwargs",
26 | "fixed_pos_hole_kwargs",
27 | ]
28 | )
29 | EVAL_ENV = parse_sawyer_peg_env("visual_in_domain_eval")
30 | TEST_ENV = parse_sawyer_peg_env("visual_eval")
31 | input_uuid = "sawyer_peg_obs"
32 | SENSORS = [
33 | DictObsSensor(
34 | uuid=input_uuid,
35 | num_stacked_frames=cfg.model_kwargs["num_stacked_frames"],
36 | env_name=ENV,
37 | ),
38 | ]
39 | MODEL = DiscreteActorCriticVisual
40 | ENV_WRAPPER = SawyerPegMultiDiscretizeEnv
41 | TASK_SAMPLER = TwoPhasesSawyerPegMultiDiscreteTaskSampler # two phase task sampler
42 | EVAL_TASK_SAMPLER = MultiDiscretizeSawyerPegTaskSampler
43 |
44 | @classmethod
45 | def tag(cls) -> str:
46 | return "two_phases-1e4-visual"
47 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/method/visual_random_1e4.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.models.actor_critic_visual import DiscreteActorCriticVisual
2 | from allenact_plugins.sawyer_peg_plugin import (
3 | SawyerPegMultiDiscretizeEnv,
4 | MultiDiscretizeSawyerPegTaskSampler,
5 | )
6 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
7 | from allenact_plugins.wrappers import ExperimentConfigBase, DictObsSensor
8 | from projects.sawyer_peg.experiments.visual_base import get_config
9 |
10 |
11 | CFG = get_config(8, debug=False)
12 | with CFG.unlocked():
13 | CFG.train_gpus = [2, 3]
14 |
15 |
16 | class SawyerPegRFVisualTwoPhases(ExperimentConfigBase):
17 |
18 | cfg = CFG
19 |
20 | ENV = parse_sawyer_peg_env(
21 | [
22 | "visual_obs_kwargs",
23 | "random_targets_kwargs",
24 | "fixed_resets_kwargs",
25 | "fixed_pos_hole_kwargs",
26 | ]
27 | )
28 | EVAL_ENV = parse_sawyer_peg_env("visual_in_domain_eval")
29 | TEST_ENV = parse_sawyer_peg_env("visual_in_domain_eval")
30 | input_uuid = "sawyer_peg_obs"
31 | SENSORS = [
32 | DictObsSensor(
33 | uuid=input_uuid,
34 | num_stacked_frames=cfg.model_kwargs["num_stacked_frames"],
35 | env_name=ENV,
36 | ),
37 | ]
38 | MODEL = DiscreteActorCriticVisual
39 | ENV_WRAPPER = SawyerPegMultiDiscretizeEnv
40 | TASK_SAMPLER = MultiDiscretizeSawyerPegTaskSampler
41 | EVAL_TASK_SAMPLER = MultiDiscretizeSawyerPegTaskSampler
42 |
43 | @classmethod
44 | def tag(cls) -> str:
45 | return "random-1e4-visual"
46 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/sawyer_peg/experiments/tests/__init__.py
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/dtw/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/sawyer_peg/experiments/tests/dtw/__init__.py
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/dtw/visual_test_in_domain.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
2 | from projects.sawyer_peg.experiments.visual_base import (
3 | SawyerPegRFRandomAlmostReversibleVisual,
4 | )
5 |
6 |
7 | class SawyerPegRFRandomAlmostReversibleVisualBaseline(
8 | SawyerPegRFRandomAlmostReversibleVisual
9 | ):
10 | TEST_ENV = parse_sawyer_peg_env("visual_in_domain_eval")
11 | MEASUREMENT = "dtw"
12 |
13 | @classmethod
14 | def tag(cls) -> str:
15 | return super().tag() + "_test_in_domain"
16 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/dtw/visual_test_novel_box.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
2 | from projects.sawyer_peg.experiments.visual_base import (
3 | SawyerPegRFRandomAlmostReversibleVisual,
4 | )
5 |
6 |
7 | class SawyerPegRFRandomAlmostReversibleVisualBaseline(
8 | SawyerPegRFRandomAlmostReversibleVisual
9 | ):
10 | TEST_ENV = parse_sawyer_peg_env("visual_eval")
11 | MEASUREMENT = "dtw"
12 |
13 | @classmethod
14 | def tag(cls) -> str:
15 | return super().tag() + "_test_novel_box"
16 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/dtw/visual_test_small_table.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
2 | from projects.sawyer_peg.experiments.visual_base import (
3 | SawyerPegRFRandomAlmostReversibleVisual,
4 | )
5 |
6 |
7 | class SawyerPegRFRandomAlmostReversibleVisualBaseline(
8 | SawyerPegRFRandomAlmostReversibleVisual
9 | ):
10 | TEST_ENV = parse_sawyer_peg_env("visual_small_table")
11 | MEASUREMENT = "dtw"
12 |
13 | @classmethod
14 | def tag(cls) -> str:
15 | return super().tag() + "_test_small_table"
16 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/entropy/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/sawyer_peg/experiments/tests/entropy/__init__.py
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/entropy/visual_test_in_domain.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
2 | from projects.sawyer_peg.experiments.visual_base import (
3 | SawyerPegRFRandomAlmostReversibleVisual,
4 | )
5 |
6 |
7 | class SawyerPegRFRandomAlmostReversibleVisualBaseline(
8 | SawyerPegRFRandomAlmostReversibleVisual
9 | ):
10 | TEST_ENV = parse_sawyer_peg_env("visual_in_domain_eval")
11 | MEASUREMENT = "entropy"
12 |
13 | @classmethod
14 | def tag(cls) -> str:
15 | return super().tag() + "_test_in_domain"
16 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/entropy/visual_test_novel_box.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
2 | from projects.sawyer_peg.experiments.visual_base import (
3 | SawyerPegRFRandomAlmostReversibleVisual,
4 | )
5 |
6 |
7 | class SawyerPegRFRandomAlmostReversibleVisualBaseline(
8 | SawyerPegRFRandomAlmostReversibleVisual
9 | ):
10 | TEST_ENV = parse_sawyer_peg_env("visual_eval")
11 | MEASUREMENT = "entropy"
12 |
13 | @classmethod
14 | def tag(cls) -> str:
15 | return super().tag() + "_test_novel_box"
16 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/entropy/visual_test_small_table.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
2 | from projects.sawyer_peg.experiments.visual_base import (
3 | SawyerPegRFRandomAlmostReversibleVisual,
4 | )
5 |
6 |
7 | class SawyerPegRFRandomAlmostReversibleVisualBaseline(
8 | SawyerPegRFRandomAlmostReversibleVisual
9 | ):
10 | TEST_ENV = parse_sawyer_peg_env("visual_small_table")
11 | MEASUREMENT = "entropy"
12 |
13 | @classmethod
14 | def tag(cls) -> str:
15 | return super().tag() + "_test_small_table"
16 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/euclidean/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/sawyer_peg/experiments/tests/euclidean/__init__.py
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/euclidean/visual_test_in_domain.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
2 | from projects.sawyer_peg.experiments.visual_base import (
3 | SawyerPegRFRandomAlmostReversibleVisual,
4 | )
5 |
6 |
7 | class SawyerPegRFRandomAlmostReversibleVisualBaseline(
8 | SawyerPegRFRandomAlmostReversibleVisual
9 | ):
10 | TEST_ENV = parse_sawyer_peg_env("visual_in_domain_eval")
11 | MEASUREMENT = "euclidean"
12 |
13 | @classmethod
14 | def tag(cls) -> str:
15 | return super().tag() + "_test_in_domain"
16 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/euclidean/visual_test_novel_box.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
2 | from projects.sawyer_peg.experiments.visual_base import (
3 | SawyerPegRFRandomAlmostReversibleVisual,
4 | )
5 |
6 |
7 | class SawyerPegRFRandomAlmostReversibleVisualBaseline(
8 | SawyerPegRFRandomAlmostReversibleVisual
9 | ):
10 | TEST_ENV = parse_sawyer_peg_env("visual_eval")
11 | MEASUREMENT = "euclidean"
12 |
13 | @classmethod
14 | def tag(cls) -> str:
15 | return super().tag() + "_test_novel_box"
16 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/euclidean/visual_test_small_table.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
2 | from projects.sawyer_peg.experiments.visual_base import (
3 | SawyerPegRFRandomAlmostReversibleVisual,
4 | )
5 |
6 |
7 | class SawyerPegRFRandomAlmostReversibleVisualBaseline(
8 | SawyerPegRFRandomAlmostReversibleVisual
9 | ):
10 | TEST_ENV = parse_sawyer_peg_env("visual_small_table")
11 | MEASUREMENT = "euclidean"
12 |
13 | @classmethod
14 | def tag(cls) -> str:
15 | return super().tag() + "_test_small_table"
16 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/others/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/sawyer_peg/experiments/tests/others/__init__.py
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/others/visual_adv_1e4_in_domain.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.models.actor_critic_visual import DiscreteActorCriticVisual
2 | from allenact_plugins.sawyer_peg_plugin import (
3 | SawyerPegMultiDiscretizeEnv,
4 | MultiDiscretizeSawyerPegTaskSampler,
5 | TwoPhasesSawyerPegMultiDiscreteTaskSampler,
6 | )
7 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
8 | from allenact_plugins.wrappers import ExperimentConfigBase, DictObsSensor
9 | from projects.sawyer_peg.experiments.visual_base import get_config
10 |
11 |
12 | CFG = get_config(8, debug=False)
13 |
14 |
15 | class SawyerPegRFVisualTwoPhases(ExperimentConfigBase):
16 |
17 | cfg = CFG
18 |
19 | ENV = parse_sawyer_peg_env(
20 | [
21 | "visual_obs_kwargs",
22 | "two_phases_kwargs",
23 | "fixed_resets_kwargs",
24 | "fixed_pos_hole_kwargs",
25 | ]
26 | )
27 | EVAL_ENV = parse_sawyer_peg_env("visual_in_domain_eval")
28 | TEST_ENV = parse_sawyer_peg_env("visual_in_domain_eval")
29 | input_uuid = "sawyer_peg_obs"
30 | SENSORS = [
31 | DictObsSensor(
32 | uuid=input_uuid,
33 | num_stacked_frames=cfg.model_kwargs["num_stacked_frames"],
34 | env_name=ENV,
35 | ),
36 | ]
37 | MODEL = DiscreteActorCriticVisual
38 | ENV_WRAPPER = SawyerPegMultiDiscretizeEnv
39 | TASK_SAMPLER = TwoPhasesSawyerPegMultiDiscreteTaskSampler # two phase task sampler
40 | EVAL_TASK_SAMPLER = MultiDiscretizeSawyerPegTaskSampler
41 |
42 | @classmethod
43 | def tag(cls) -> str:
44 | return "two_phases-1e4-visual-in_domain_test"
45 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/others/visual_adv_1e4_novel_box.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.models.actor_critic_visual import DiscreteActorCriticVisual
2 | from allenact_plugins.sawyer_peg_plugin import (
3 | SawyerPegMultiDiscretizeEnv,
4 | MultiDiscretizeSawyerPegTaskSampler,
5 | TwoPhasesSawyerPegMultiDiscreteTaskSampler,
6 | )
7 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
8 | from allenact_plugins.wrappers import ExperimentConfigBase, DictObsSensor
9 | from projects.sawyer_peg.experiments.visual_base import get_config
10 |
11 |
12 | CFG = get_config(8, debug=False)
13 |
14 |
15 | class SawyerPegRFVisualTwoPhases(ExperimentConfigBase):
16 |
17 | cfg = CFG
18 |
19 | ENV = parse_sawyer_peg_env(
20 | [
21 | "visual_obs_kwargs",
22 | "two_phases_kwargs",
23 | "fixed_resets_kwargs",
24 | "fixed_pos_hole_kwargs",
25 | ]
26 | )
27 | EVAL_ENV = parse_sawyer_peg_env("visual_eval")
28 | TEST_ENV = parse_sawyer_peg_env("visual_eval")
29 | input_uuid = "sawyer_peg_obs"
30 | SENSORS = [
31 | DictObsSensor(
32 | uuid=input_uuid,
33 | num_stacked_frames=cfg.model_kwargs["num_stacked_frames"],
34 | env_name=ENV,
35 | ),
36 | ]
37 | MODEL = DiscreteActorCriticVisual
38 | ENV_WRAPPER = SawyerPegMultiDiscretizeEnv
39 | TASK_SAMPLER = TwoPhasesSawyerPegMultiDiscreteTaskSampler # two phase task sampler
40 | EVAL_TASK_SAMPLER = MultiDiscretizeSawyerPegTaskSampler
41 |
42 | @classmethod
43 | def tag(cls) -> str:
44 | return "two_phases-1e4-visual-novel_box_test"
45 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/others/visual_random_1e4_in_domain.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.models.actor_critic_visual import DiscreteActorCriticVisual
2 | from allenact_plugins.sawyer_peg_plugin import (
3 | SawyerPegMultiDiscretizeEnv,
4 | MultiDiscretizeSawyerPegTaskSampler,
5 | )
6 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
7 | from allenact_plugins.wrappers import ExperimentConfigBase, DictObsSensor
8 | from projects.sawyer_peg.experiments.visual_base import get_config
9 |
10 |
11 | CFG = get_config(8, debug=False)
12 |
13 |
14 | class SawyerPegRFVisualTwoPhases(ExperimentConfigBase):
15 |
16 | cfg = CFG
17 |
18 | ENV = parse_sawyer_peg_env(
19 | [
20 | "visual_obs_kwargs",
21 | "random_targets_kwargs",
22 | "fixed_resets_kwargs",
23 | "fixed_pos_hole_kwargs",
24 | ]
25 | )
26 | EVAL_ENV = parse_sawyer_peg_env("visual_in_domain_eval")
27 | TEST_ENV = parse_sawyer_peg_env("visual_in_domain_eval")
28 | input_uuid = "sawyer_peg_obs"
29 | SENSORS = [
30 | DictObsSensor(
31 | uuid=input_uuid,
32 | num_stacked_frames=cfg.model_kwargs["num_stacked_frames"],
33 | env_name=ENV,
34 | ),
35 | ]
36 | MODEL = DiscreteActorCriticVisual
37 | ENV_WRAPPER = SawyerPegMultiDiscretizeEnv
38 | TASK_SAMPLER = MultiDiscretizeSawyerPegTaskSampler
39 | EVAL_TASK_SAMPLER = MultiDiscretizeSawyerPegTaskSampler
40 |
41 | @classmethod
42 | def tag(cls) -> str:
43 | return "random-1e4-visual-in_domain_test"
44 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/others/visual_random_1e4_novel_box.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.models.actor_critic_visual import DiscreteActorCriticVisual
2 | from allenact_plugins.sawyer_peg_plugin import (
3 | SawyerPegMultiDiscretizeEnv,
4 | MultiDiscretizeSawyerPegTaskSampler,
5 | )
6 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
7 | from allenact_plugins.wrappers import ExperimentConfigBase, DictObsSensor
8 | from projects.sawyer_peg.experiments.visual_base import get_config
9 |
10 |
11 | CFG = get_config(8, debug=False)
12 |
13 |
14 | class SawyerPegRFVisualTwoPhases(ExperimentConfigBase):
15 |
16 | cfg = CFG
17 |
18 | ENV = parse_sawyer_peg_env(
19 | [
20 | "visual_obs_kwargs",
21 | "random_targets_kwargs",
22 | "fixed_resets_kwargs",
23 | "fixed_pos_hole_kwargs",
24 | ]
25 | )
26 | EVAL_ENV = parse_sawyer_peg_env("visual_eval")
27 | TEST_ENV = parse_sawyer_peg_env("visual_eval")
28 | input_uuid = "sawyer_peg_obs"
29 | SENSORS = [
30 | DictObsSensor(
31 | uuid=input_uuid,
32 | num_stacked_frames=cfg.model_kwargs["num_stacked_frames"],
33 | env_name=ENV,
34 | ),
35 | ]
36 | MODEL = DiscreteActorCriticVisual
37 | ENV_WRAPPER = SawyerPegMultiDiscretizeEnv
38 | TASK_SAMPLER = MultiDiscretizeSawyerPegTaskSampler
39 | EVAL_TASK_SAMPLER = MultiDiscretizeSawyerPegTaskSampler
40 |
41 | @classmethod
42 | def tag(cls) -> str:
43 | return "random-1e4-visual-novel_box"
44 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/std/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/sawyer_peg/experiments/tests/std/__init__.py
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/std/visual_test_in_domain.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
2 | from projects.sawyer_peg.experiments.visual_base import (
3 | SawyerPegRFRandomAlmostReversibleVisual,
4 | )
5 |
6 |
7 | class SawyerPegRFRandomAlmostReversibleVisualBaseline(
8 | SawyerPegRFRandomAlmostReversibleVisual
9 | ):
10 | TEST_ENV = parse_sawyer_peg_env("visual_in_domain_eval")
11 | MEASUREMENT = "std"
12 |
13 | @classmethod
14 | def tag(cls) -> str:
15 | return super().tag() + "_test_in_domain"
16 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/std/visual_test_novel_box.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
2 | from projects.sawyer_peg.experiments.visual_base import (
3 | SawyerPegRFRandomAlmostReversibleVisual,
4 | )
5 |
6 |
7 | class SawyerPegRFRandomAlmostReversibleVisualBaseline(
8 | SawyerPegRFRandomAlmostReversibleVisual
9 | ):
10 | TEST_ENV = parse_sawyer_peg_env("visual_eval")
11 | MEASUREMENT = "std"
12 |
13 | @classmethod
14 | def tag(cls) -> str:
15 | return super().tag() + "_test_novel_box"
16 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/tests/std/visual_test_small_table.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
2 | from projects.sawyer_peg.experiments.visual_base import (
3 | SawyerPegRFRandomAlmostReversibleVisual,
4 | )
5 |
6 |
7 | class SawyerPegRFRandomAlmostReversibleVisualBaseline(
8 | SawyerPegRFRandomAlmostReversibleVisual
9 | ):
10 | TEST_ENV = parse_sawyer_peg_env("visual_small_table")
11 | MEASUREMENT = "std"
12 |
13 | @classmethod
14 | def tag(cls) -> str:
15 | return super().tag() + "_test_small_table"
16 |
--------------------------------------------------------------------------------
/projects/sawyer_peg/experiments/visual_base.py:
--------------------------------------------------------------------------------
1 | import yaml
2 |
3 | from allenact_plugins.models.actor_critic_visual import DiscreteActorCriticVisual
4 | from allenact_plugins.sawyer_peg_plugin import (
5 | SawyerPegMultiDiscretizeEnv,
6 | MultiDiscretizeSawyerPegTaskSampler,
7 | )
8 | from allenact_plugins.sawyer_peg_plugin.registered_envs import parse_sawyer_peg_env
9 | from allenact_plugins.utils import Config
10 | from allenact_plugins.utils.env_utils import get_file
11 | from allenact_plugins.wrappers import ExperimentConfigBase, DictObsSensor
12 |
13 | __all__ = ["get_config", "SawyerPegRFRandomAlmostReversibleVisual"]
14 |
15 |
16 | def get_config(proc: int = 8, debug: bool = False):
17 | if proc == 8:
18 | cfg_name = "visual.yaml"
19 | elif proc == 4:
20 | cfg_name = "visual_4_proc.yaml"
21 | else:
22 | raise NotImplementedError(proc)
23 | cfg_path = yaml.safe_load(get_file(__file__, "cfg", cfg_name))
24 | cfg = Config(cfg_path)
25 | if debug:
26 | cfg.debug()
27 | return cfg
28 |
29 |
30 | class SawyerPegRFRandomAlmostReversibleVisual(ExperimentConfigBase):
31 |
32 | processes = 8
33 | cfg = get_config(processes, debug=False)
34 | ENV = parse_sawyer_peg_env("visual_train")
35 | EVAL_ENV = parse_sawyer_peg_env("visual_in_domain_eval")
36 | TEST_ENV = parse_sawyer_peg_env("visual_eval")
37 | input_uuid = "sawyer_peg_obs"
38 | SENSORS = [
39 | DictObsSensor(
40 | uuid=input_uuid,
41 | num_stacked_frames=cfg.model_kwargs["num_stacked_frames"],
42 | env_name=ENV,
43 | ),
44 | ]
45 | MODEL = DiscreteActorCriticVisual
46 | ENV_WRAPPER = SawyerPegMultiDiscretizeEnv
47 | TASK_SAMPLER = MultiDiscretizeSawyerPegTaskSampler
48 |
49 | MEASUREMENT = "std"
50 |
51 | @classmethod
52 | def tag(cls) -> str:
53 | return (
54 | f"{cls.MEASUREMENT}_measure-random_target-visual-{cls.processes}_processes"
55 | )
56 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/strech_manipulation/__init__.py
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/strech_manipulation/experiments/__init__.py
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/budget_measure_ablation/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/strech_manipulation/experiments/budget_measure_ablation/__init__.py
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/budget_measure_ablation/cfg/rgb.yaml:
--------------------------------------------------------------------------------
1 | # Config file
2 |
3 | tag: "Stretch Robot Pick and Place"
4 |
5 | general:
6 | num_processes: 16
7 | val_processes: 0 # only ckpt
8 | test_processes: 25
9 | worker_per_device: 1
10 | headless: false
11 | train_gpus: [0,1]
12 | validation_gpus: null
13 | testing_gpus: [0,1,2,3]
14 | train_dataset_dir: null
15 | validation_dataset_dir: null
16 | test_dataset_dir: null
17 | validation_tasks: 1 # 0
18 | testing_tasks: 8 # 25 * 8 = 200
19 | visualize: false
20 | visualize_test: false
21 | viz_mode: debug # "rgb"
22 | viz_class:
23 | - video_viz
24 | viz_fps: 10
25 | # viz_resolution: [512, 512]
26 | callback_kwargs:
27 | sync: true
28 | output_dir: stretch
29 | wandb_project:
30 | wandb_entity:
31 | callback_sensors:
32 | # thor_training_video_callback:
33 | # save_path: "training_videos"
34 | # thor_point_cloud_callback:
35 | # num_steps_recording: 50000
36 |
37 | sampler_kwargs:
38 | record_during_training: false
39 | num_record_processes: 3
40 | record_kwargs: # shared with training video callback
41 | record_rule: [-1, 62500, 6]
42 | mode: debug
43 | save: false
44 | fps: 10
45 | debug_extra_views: third-view
46 | # RF specific settings
47 | random_targets: true
48 | obj_goal_rate: 0.3
49 | two_phase: false
50 | irr_measure: true
51 | irr_measure_method: std
52 | num_steps_for_resets: 10000
53 | multi_objects: false
54 | fixed_container: true
55 | fixed_container_pos_rot: null
56 | # env settings
57 | spec_env_kwargs:
58 | randomize_materials: false
59 | randomize_lighting: false
60 | # directly teleport in task sampler instead
61 | init_teleport_kwargs: null
62 | object_open_speed: 0.05
63 | # task settings
64 | task_args:
65 | use_polar_coord_goal: true
66 | use_pickup_phase: true
67 | no_distractor: true
68 | add_debug_metrics: false
69 | reward_configs:
70 | step_penalty: -0.01
71 | failed_action_penalty: -0.03
72 | first_picked_up_reward: 1.0
73 | arm_dist_multiplier: 1.0
74 | obj_dist_multiplier: 1.0
75 | goal_success_reward: 10.0
76 |
77 |
78 | valid_sampler_kwargs:
79 | spec_env_kwargs:
80 | # directly teleport in task sampler instead
81 | init_teleport_kwargs: null
82 | object_open_speed: 0.05
83 | controllable_randomization: true
84 | # quality: "Very High"
85 | task_args:
86 | use_polar_coord_goal: true
87 | use_pickup_phase: true
88 | no_distractor: true
89 | add_topdown_camera: false
90 | add_debug_metrics: false
91 | reward_configs:
92 | step_penalty: -0.01
93 | failed_action_penalty: -0.03
94 | first_picked_up_reward: 1.0
95 | arm_dist_multiplier: 1.0
96 | obj_dist_multiplier: 1.0
97 | goal_success_reward: 10.0
98 |
99 | model_kwargs:
100 | num_stacked_frames: null
101 | mlp_hidden_dims: null
102 | low_dim_feature_dim: 512 # 512
103 | goal_embed_dims: 512 # 512 for prompt 32 for goal embedding
104 | shared_state_encoder: true
105 |
106 |
107 | training_pipeline:
108 | lr: 3e-4 # 5e-4
109 | end_lr: 2e-4 # 3.5e-4
110 | lr_scheduler: "linear"
111 | loss_name: "ppo_loss"
112 | loss_steps: 5000000 # 5M
113 | num_steps: 200
114 | training_setting_kwargs:
115 | num_mini_batch: 4
116 | update_repeats: 10
117 | max_grad_norm: 0.5
118 | num_steps: ${training_pipeline.num_steps}
119 | gamma: 0.99
120 | use_gae: true
121 | gae_lambda: 0.95
122 | advance_scene_rollout_period: null
123 | save_interval: 125000 # 125k
124 | metric_accumulate_interval: 1
125 | loss_kwargs:
126 | clip_param: 0.1 # 0.2
127 | value_loss_coef: 0.5 # 0.3
128 | entropy_coef: 0.01
129 | use_clipped_value_loss: true
130 | normalize_advantage: true
131 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/budget_measure_ablation/dtw_random.py:
--------------------------------------------------------------------------------
1 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
2 | RFStretchPickPlaceExperimentConfigBase,
3 | get_cfg,
4 | )
5 |
6 | CFG = get_cfg(
7 | debug=False,
8 | countertop_scale=None,
9 | keep_extra_furniture=False,
10 | randomize_materials_lighting=False,
11 | texture_randomization_keys=None,
12 | irr_measure_method="dtw",
13 | cfg_name="rgb.yaml",
14 | )
15 |
16 |
17 | class SingleComboConfig(RFStretchPickPlaceExperimentConfigBase):
18 |
19 | cfg = CFG
20 |
21 | TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
22 | EVAL_TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
23 |
24 | @classmethod
25 | def tag(cls) -> str:
26 | return f"Red_Apple-Stripe_Plate-random-dtw"
27 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/budget_measure_ablation/dtw_random_four_combo.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
2 | TrainingFourCombos,
3 | )
4 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
5 | RFStretchPickPlaceExperimentConfigBase,
6 | get_cfg,
7 | )
8 |
9 | CFG = get_cfg(
10 | debug=False,
11 | countertop_scale=None,
12 | keep_extra_furniture=False,
13 | randomize_materials_lighting=False,
14 | texture_randomization_keys=None,
15 | irr_measure_method="dtw",
16 | cfg_name="rgb.yaml",
17 | )
18 |
19 |
20 | class DTWFourComboConfig(RFStretchPickPlaceExperimentConfigBase):
21 |
22 | cfg = CFG
23 |
24 | TARGET_TYPES = TrainingFourCombos
25 | EVAL_TARGET_TYPES = TrainingFourCombos
26 |
27 | @classmethod
28 | def tag(cls) -> str:
29 | return f"FourCombo-random-dtw"
30 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/budget_measure_ablation/dtw_random_sixteen_combo.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
2 | TrainingSixteenCombos,
3 | )
4 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
5 | RFStretchPickPlaceExperimentConfigBase,
6 | get_cfg,
7 | )
8 |
9 | CFG = get_cfg(
10 | debug=False,
11 | countertop_scale=None,
12 | keep_extra_furniture=False,
13 | randomize_materials_lighting=False,
14 | texture_randomization_keys=None,
15 | irr_measure_method="dtw",
16 | cfg_name="rgb.yaml",
17 | )
18 |
19 |
20 | class DTWSixteenComboConfig(RFStretchPickPlaceExperimentConfigBase):
21 |
22 | cfg = CFG
23 |
24 | TARGET_TYPES = TrainingSixteenCombos
25 | EVAL_TARGET_TYPES = TrainingSixteenCombos
26 |
27 | @classmethod
28 | def tag(cls) -> str:
29 | return f"SixteenCombo-random-dtw"
30 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/budget_measure_ablation/entropy_random.py:
--------------------------------------------------------------------------------
1 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
2 | RFStretchPickPlaceExperimentConfigBase,
3 | get_cfg,
4 | )
5 |
6 | CFG = get_cfg(
7 | debug=False,
8 | countertop_scale=None,
9 | keep_extra_furniture=False,
10 | randomize_materials_lighting=False,
11 | texture_randomization_keys=None,
12 | irr_measure_method="entropy",
13 | cfg_name="rgb.yaml",
14 | )
15 |
16 |
17 | class SingleComboConfig(RFStretchPickPlaceExperimentConfigBase):
18 |
19 | cfg = CFG
20 |
21 | TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
22 | EVAL_TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
23 |
24 | @classmethod
25 | def tag(cls) -> str:
26 | return f"Red_Apple-Stripe_Plate-random-entropy"
27 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/budget_measure_ablation/entropy_random_four_combo.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
2 | TrainingFourCombos,
3 | )
4 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
5 | RFStretchPickPlaceExperimentConfigBase,
6 | get_cfg,
7 | )
8 |
9 | CFG = get_cfg(
10 | debug=False,
11 | countertop_scale=None,
12 | keep_extra_furniture=False,
13 | randomize_materials_lighting=False,
14 | texture_randomization_keys=None,
15 | irr_measure_method="entropy",
16 | cfg_name="rgb.yaml",
17 | )
18 |
19 |
20 | class SingleComboConfig(RFStretchPickPlaceExperimentConfigBase):
21 |
22 | cfg = CFG
23 |
24 | TARGET_TYPES = TrainingFourCombos
25 | EVAL_TARGET_TYPES = TrainingFourCombos
26 |
27 | @classmethod
28 | def tag(cls) -> str:
29 | return f"Red_Apple-Stripe_Plate-random-entropy"
30 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/budget_measure_ablation/entropy_random_sixteen.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
2 | TrainingSixteenCombos,
3 | )
4 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
5 | RFStretchPickPlaceExperimentConfigBase,
6 | get_cfg,
7 | )
8 |
9 | CFG = get_cfg(
10 | debug=False,
11 | countertop_scale=None,
12 | keep_extra_furniture=False,
13 | randomize_materials_lighting=False,
14 | texture_randomization_keys=None,
15 | irr_measure_method="entropy",
16 | cfg_name="rgb.yaml",
17 | )
18 |
19 |
20 | class SingleComboConfig(RFStretchPickPlaceExperimentConfigBase):
21 |
22 | cfg = CFG
23 |
24 | TARGET_TYPES = TrainingSixteenCombos
25 | EVAL_TARGET_TYPES = TrainingSixteenCombos
26 |
27 | @classmethod
28 | def tag(cls) -> str:
29 | return f"Red_Apple-Stripe_Plate-random-entropy"
30 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/budget_measure_ablation/euclidean_random.py:
--------------------------------------------------------------------------------
1 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
2 | RFStretchPickPlaceExperimentConfigBase,
3 | get_cfg,
4 | )
5 |
6 |
7 | CFG = get_cfg(
8 | debug=False,
9 | countertop_scale=None,
10 | keep_extra_furniture=False,
11 | randomize_materials_lighting=False,
12 | texture_randomization_keys=None,
13 | irr_measure_method="euclidean",
14 | cfg_name="rgb.yaml",
15 | )
16 |
17 | EUCLIDEAN_RUNNING_SERVER = "rf4"
18 |
19 |
20 | class EuclideanSingleComboConfig(RFStretchPickPlaceExperimentConfigBase):
21 |
22 | cfg = CFG
23 |
24 | TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
25 | EVAL_TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
26 |
27 | @classmethod
28 | def tag(cls) -> str:
29 | return f"Red_Apple-Stripe_Plate-random-euclidean"
30 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/budget_measure_ablation/euclidean_random_four_combos.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
2 | TrainingFourCombos,
3 | )
4 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
5 | RFStretchPickPlaceExperimentConfigBase,
6 | get_cfg,
7 | )
8 |
9 |
10 | CFG = get_cfg(
11 | debug=False,
12 | countertop_scale=None,
13 | keep_extra_furniture=False,
14 | randomize_materials_lighting=False,
15 | texture_randomization_keys=None,
16 | irr_measure_method="euclidean",
17 | cfg_name="rgb.yaml",
18 | )
19 |
20 |
21 | class EuclideanFourComboConfig(RFStretchPickPlaceExperimentConfigBase):
22 |
23 | cfg = CFG
24 |
25 | TARGET_TYPES = TrainingFourCombos
26 | EVAL_TARGET_TYPES = TrainingFourCombos
27 |
28 | @classmethod
29 | def tag(cls) -> str:
30 | return f"four_combos-random-euclidean"
31 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/budget_measure_ablation/euclidean_random_sixteen_combos.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
2 | TrainingSixteenCombos,
3 | )
4 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
5 | RFStretchPickPlaceExperimentConfigBase,
6 | get_cfg,
7 | )
8 |
9 |
10 | CFG = get_cfg(
11 | debug=False,
12 | countertop_scale=None,
13 | keep_extra_furniture=False,
14 | randomize_materials_lighting=False,
15 | texture_randomization_keys=None,
16 | irr_measure_method="euclidean",
17 | cfg_name="rgb.yaml",
18 | )
19 |
20 |
21 | class EuclideanSixteenComboConfig(RFStretchPickPlaceExperimentConfigBase):
22 |
23 | cfg = CFG
24 |
25 | TARGET_TYPES = TrainingSixteenCombos
26 | EVAL_TARGET_TYPES = TrainingSixteenCombos
27 |
28 | @classmethod
29 | def tag(cls) -> str:
30 | return f"sixteen_combos-random-euclidean"
31 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/budget_measure_ablation/random_irr_four_combos.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
2 | TrainingFourCombos,
3 | )
4 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
5 | RFStretchPickPlaceExperimentConfigBase,
6 | get_cfg,
7 | )
8 |
9 |
10 | class FourComboConfig(RFStretchPickPlaceExperimentConfigBase):
11 |
12 | cfg = get_cfg(
13 | debug=False,
14 | countertop_scale=None,
15 | keep_extra_furniture=False,
16 | randomize_materials_lighting=False,
17 | texture_randomization_keys=None,
18 | )
19 |
20 | TARGET_TYPES = TrainingFourCombos
21 | EVAL_TARGET_TYPES = TrainingFourCombos
22 |
23 | @classmethod
24 | def tag(cls) -> str:
25 | return f"four_combos-random-std"
26 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/budget_measure_ablation/random_irr_single_combo.py:
--------------------------------------------------------------------------------
1 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
2 | RFStretchPickPlaceExperimentConfigBase,
3 | get_cfg,
4 | )
5 |
6 |
7 | class SingleComboConfig(RFStretchPickPlaceExperimentConfigBase):
8 |
9 | cfg = get_cfg(
10 | debug=False,
11 | countertop_scale=None,
12 | keep_extra_furniture=False,
13 | randomize_materials_lighting=False,
14 | texture_randomization_keys=None,
15 | irr_measure_method="std",
16 | cfg_name="rgb.yaml",
17 | )
18 |
19 | TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
20 | EVAL_TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
21 |
22 | @classmethod
23 | def tag(cls) -> str:
24 | return f"Red_Apple-Stripe_Plate-random-std"
25 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/budget_measure_ablation/random_irr_sixteen_combos.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
2 | TrainingSixteenCombos,
3 | )
4 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
5 | RFStretchPickPlaceExperimentConfigBase,
6 | get_cfg,
7 | )
8 |
9 |
10 | class FourComboConfig(RFStretchPickPlaceExperimentConfigBase):
11 |
12 | cfg = get_cfg(
13 | debug=False,
14 | countertop_scale=None,
15 | keep_extra_furniture=False,
16 | randomize_materials_lighting=False,
17 | texture_randomization_keys=None,
18 | )
19 | # with cfg.unlocked():
20 | # cfg.sampler_kwargs["num_record_processes"] = None # all
21 |
22 | TARGET_TYPES = TrainingSixteenCombos
23 | EVAL_TARGET_TYPES = TrainingSixteenCombos
24 |
25 | @classmethod
26 | def tag(cls) -> str:
27 | return f"sixteen_combos-random-std"
28 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/episodic_variations/1e3.py:
--------------------------------------------------------------------------------
1 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
2 | RFStretchPickPlaceExperimentConfigBase,
3 | get_cfg,
4 | )
5 |
6 | CFG = get_cfg(debug=False, countertop_scale=None, keep_extra_furniture=False)
7 | with CFG.unlocked():
8 | CFG.sampler_kwargs["irr_measure"] = False
9 | CFG.sampler_kwargs["num_steps_for_resets"] = 1e3
10 |
11 |
12 | class SingleComboConfig(RFStretchPickPlaceExperimentConfigBase):
13 |
14 | cfg = CFG
15 |
16 | TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
17 | EVAL_TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
18 |
19 | @classmethod
20 | def tag(cls) -> str:
21 | return f"Red_Apple-Stripe_Plate-1e3-random"
22 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/episodic_variations/1e3_four_combos.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
2 | TrainingFourCombos,
3 | )
4 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
5 | RFStretchPickPlaceExperimentConfigBase,
6 | get_cfg,
7 | )
8 |
9 | CFG = get_cfg(debug=False, countertop_scale=None, keep_extra_furniture=False)
10 | with CFG.unlocked():
11 | CFG.sampler_kwargs["irr_measure"] = False
12 | CFG.sampler_kwargs["num_steps_for_resets"] = 1e3
13 |
14 |
15 | class SingleComboConfig(RFStretchPickPlaceExperimentConfigBase):
16 |
17 | cfg = CFG
18 |
19 | TARGET_TYPES = TrainingFourCombos
20 | EVAL_TARGET_TYPES = TrainingFourCombos
21 |
22 | @classmethod
23 | def tag(cls) -> str:
24 | return f"FourCombos-1e3-random"
25 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/episodic_variations/1e3_sixteen_combos.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
2 | TrainingSixteenCombos,
3 | )
4 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
5 | RFStretchPickPlaceExperimentConfigBase,
6 | get_cfg,
7 | )
8 |
9 | CFG = get_cfg(debug=False, countertop_scale=None, keep_extra_furniture=False)
10 | with CFG.unlocked():
11 | CFG.sampler_kwargs["irr_measure"] = False
12 | CFG.sampler_kwargs["num_steps_for_resets"] = 1e3
13 |
14 |
15 | class SingleComboConfig(RFStretchPickPlaceExperimentConfigBase):
16 |
17 | cfg = CFG
18 |
19 | TARGET_TYPES = TrainingSixteenCombos
20 | EVAL_TARGET_TYPES = TrainingSixteenCombos
21 |
22 | @classmethod
23 | def tag(cls) -> str:
24 | return f"SixteenCombos-1e3-random"
25 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/episodic_variations/1e4.py:
--------------------------------------------------------------------------------
1 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
2 | RFStretchPickPlaceExperimentConfigBase,
3 | get_cfg,
4 | )
5 |
6 | CFG = get_cfg(debug=False, countertop_scale=None, keep_extra_furniture=False)
7 | with CFG.unlocked():
8 | CFG.sampler_kwargs["irr_measure"] = False
9 | CFG.sampler_kwargs["num_steps_for_resets"] = 1e4
10 |
11 |
12 | class SingleComboConfig(RFStretchPickPlaceExperimentConfigBase):
13 |
14 | cfg = CFG
15 |
16 | TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
17 | EVAL_TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
18 |
19 | @classmethod
20 | def tag(cls) -> str:
21 | return f"Red_Apple-Stripe_Plate-1e4-random"
22 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/episodic_variations/1e4_four_combos.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
2 | TrainingFourCombos,
3 | )
4 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
5 | RFStretchPickPlaceExperimentConfigBase,
6 | get_cfg,
7 | )
8 |
9 | CFG = get_cfg(debug=False, countertop_scale=None, keep_extra_furniture=False)
10 | with CFG.unlocked():
11 | CFG.sampler_kwargs["irr_measure"] = False
12 | CFG.sampler_kwargs["num_steps_for_resets"] = 1e4
13 |
14 |
15 | class FourComboConfigTwoPhasesRandom(RFStretchPickPlaceExperimentConfigBase):
16 |
17 | cfg = CFG
18 |
19 | TARGET_TYPES = TrainingFourCombos
20 | EVAL_TARGET_TYPES = TrainingFourCombos
21 |
22 | @classmethod
23 | def tag(cls) -> str:
24 | return f"FourCombos-1e4-random"
25 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/episodic_variations/1e4_sixteen_combos.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
2 | TrainingSixteenCombos,
3 | )
4 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
5 | RFStretchPickPlaceExperimentConfigBase,
6 | get_cfg,
7 | )
8 |
9 | CFG = get_cfg(debug=False, countertop_scale=None, keep_extra_furniture=False)
10 | with CFG.unlocked():
11 | CFG.sampler_kwargs["irr_measure"] = False
12 | CFG.sampler_kwargs["num_steps_for_resets"] = 1e4
13 |
14 |
15 | class SixteenComboConfigTwoPhasesRandom(RFStretchPickPlaceExperimentConfigBase):
16 |
17 | cfg = CFG
18 |
19 | TARGET_TYPES = TrainingSixteenCombos
20 | EVAL_TARGET_TYPES = TrainingSixteenCombos
21 |
22 | @classmethod
23 | def tag(cls) -> str:
24 | return f"SixteenCombos-1e4-random"
25 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/episodic_variations/250k.py:
--------------------------------------------------------------------------------
1 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
2 | RFStretchPickPlaceExperimentConfigBase,
3 | get_cfg,
4 | )
5 |
6 | CFG = get_cfg(debug=False, countertop_scale=None, keep_extra_furniture=False)
7 | with CFG.unlocked():
8 | CFG.sampler_kwargs["irr_measure"] = False
9 | CFG.sampler_kwargs["num_steps_for_resets"] = 2.5e4
10 | CFG.sampler_kwargs["reset_if_obj_dropped"] = True
11 |
12 | CFG.validation_tasks = 1
13 | CFG.loss_steps = 60000000
14 | CFG.training_setting_kwargs["save_interval"] = 10000000 # 10M
15 |
16 |
17 | class SingleComboConfig(RFStretchPickPlaceExperimentConfigBase):
18 |
19 | cfg = CFG
20 |
21 | TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
22 | EVAL_TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
23 |
24 | @classmethod
25 | def tag(cls) -> str:
26 | return (
27 | f"{cls.TARGET_TYPES[0][0]}-{cls.TARGET_TYPES[0][1]}-250k-reset_if_dropped"
28 | )
29 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/episodic_variations/5e3.py:
--------------------------------------------------------------------------------
1 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
2 | RFStretchPickPlaceExperimentConfigBase,
3 | get_cfg,
4 | )
5 |
6 | CFG = get_cfg(debug=False, countertop_scale=None, keep_extra_furniture=False)
7 | with CFG.unlocked():
8 | CFG.sampler_kwargs["irr_measure"] = False
9 | CFG.sampler_kwargs["num_steps_for_resets"] = 5e3
10 |
11 |
12 | class SingleComboConfig(RFStretchPickPlaceExperimentConfigBase):
13 |
14 | cfg = CFG
15 |
16 | TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
17 | EVAL_TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
18 |
19 | @classmethod
20 | def tag(cls) -> str:
21 | return f"Red_Apple-Stripe_Plate-5e3-random"
22 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/episodic_variations/5e3_four_combos.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
2 | TrainingFourCombos,
3 | )
4 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
5 | RFStretchPickPlaceExperimentConfigBase,
6 | get_cfg,
7 | )
8 |
9 | CFG = get_cfg(debug=False, countertop_scale=None, keep_extra_furniture=False)
10 | with CFG.unlocked():
11 | CFG.sampler_kwargs["irr_measure"] = False
12 | CFG.sampler_kwargs["num_steps_for_resets"] = 5e3
13 |
14 |
15 | class FourComboConfigTwoPhasesRandom(RFStretchPickPlaceExperimentConfigBase):
16 |
17 | cfg = CFG
18 |
19 | TARGET_TYPES = TrainingFourCombos
20 | EVAL_TARGET_TYPES = TrainingFourCombos
21 |
22 | @classmethod
23 | def tag(cls) -> str:
24 | return f"FourCombos-5e3-random"
25 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/episodic_variations/5e3_sixteen_combos.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
2 | TrainingSixteenCombos,
3 | )
4 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
5 | RFStretchPickPlaceExperimentConfigBase,
6 | get_cfg,
7 | )
8 |
9 | CFG = get_cfg(debug=False, countertop_scale=None, keep_extra_furniture=False)
10 | with CFG.unlocked():
11 | CFG.sampler_kwargs["irr_measure"] = False
12 | CFG.sampler_kwargs["num_steps_for_resets"] = 5e3
13 |
14 |
15 | class SixteenComboConfigTwoPhasesRandom(RFStretchPickPlaceExperimentConfigBase):
16 |
17 | cfg = CFG
18 |
19 | TARGET_TYPES = TrainingSixteenCombos
20 | EVAL_TARGET_TYPES = TrainingSixteenCombos
21 |
22 | @classmethod
23 | def tag(cls) -> str:
24 | return f"SixteenCombos-5e3-random"
25 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/episodic_variations/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/strech_manipulation/experiments/episodic_variations/__init__.py
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/tests/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/strech_manipulation/experiments/tests/__init__.py
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/tests/budegt_and_measurement/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/strech_manipulation/experiments/tests/budegt_and_measurement/__init__.py
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/tests/budegt_and_measurement/measure_random_novel_objects.py:
--------------------------------------------------------------------------------
1 | from projects.strech_manipulation.experiments.tests.budegt_and_measurement.measure_random_in_domain import (
2 | get_measure_test_cfg,
3 | N_COMBO,
4 | StretchMeasureTestConfig,
5 | MEASURE,
6 | )
7 |
8 |
9 | class SingleComboConfig(StretchMeasureTestConfig):
10 |
11 | cfg = get_measure_test_cfg(
12 | n_combo=N_COMBO,
13 | irr_measure_method=MEASURE,
14 | novel_objects=True,
15 | extra_tag="novel_objects_test",
16 | debug=False,
17 | countertop_scale=None,
18 | keep_extra_furniture=False,
19 | randomize_materials_lighting=False,
20 | texture_randomization_keys=None,
21 | cfg_name="rgb.yaml",
22 | )
23 |
24 | EVAL_TARGET_TYPES = cfg.EVAL_TARGET_TYPES
25 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/tests/budegt_and_measurement/measure_random_novel_pos.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
2 | TestingCombos,
3 | TrainingFourCombos,
4 | TrainingSixteenCombos,
5 | )
6 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
7 | RFStretchPickPlaceExperimentConfigBase,
8 | get_cfg,
9 | )
10 |
11 |
12 | # FILL BUDGET AND MEASURE HERE
13 | N_COMBO = 1
14 | MEASURE = "std"
15 |
16 |
17 | def get_measure_test_cfg(
18 | *,
19 | n_combo: int = 1,
20 | irr_measure_method: str,
21 | novel_objects: bool,
22 | extra_tag: str,
23 | **kwargs,
24 | ):
25 | cfg = get_cfg(irr_measure_method=irr_measure_method, **kwargs)
26 | combo_map = {
27 | 1: [("Red_Apple", "Stripe_Plate")],
28 | 4: TrainingFourCombos,
29 | 16: TrainingSixteenCombos,
30 | }
31 | with cfg.unlocked():
32 | if not novel_objects:
33 | cfg.EVAL_TARGET_TYPES = combo_map[n_combo]
34 | else:
35 | cfg.EVAL_TARGET_TYPES = TestingCombos
36 |
37 | cfg.tag = f"{n_combo}Combo-random-{irr_measure_method}-{extra_tag}"
38 |
39 | return cfg
40 |
41 |
42 | class StretchMeasureTestConfig(RFStretchPickPlaceExperimentConfigBase):
43 |
44 | cfg = get_measure_test_cfg(
45 | n_combo=N_COMBO,
46 | irr_measure_method=MEASURE,
47 | novel_objects=False,
48 | extra_tag="pos_ood_test",
49 | debug=False,
50 | countertop_scale=None,
51 | randomize_materials_lighting=False,
52 | texture_randomization_keys=None,
53 | cfg_name="rgb.yaml",
54 | )
55 |
56 | EVAL_TARGET_TYPES = cfg.EVAL_TARGET_TYPES # type: ignore
57 |
58 | @classmethod
59 | def tag(cls) -> str:
60 | return f"{cls.cfg.tag}"
61 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/tests/budegt_and_measurement/measure_random_novel_scene.py:
--------------------------------------------------------------------------------
1 | from projects.strech_manipulation.experiments.tests.budegt_and_measurement.measure_random_in_domain import (
2 | get_measure_test_cfg,
3 | N_COMBO,
4 | StretchMeasureTestConfig,
5 | MEASURE,
6 | )
7 |
8 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
9 | STRETCH_MANIPULATHOR_FURNISHED_COMMIT_ID,
10 | )
11 |
12 |
13 | class SingleComboConfig(StretchMeasureTestConfig):
14 |
15 | cfg = get_measure_test_cfg(
16 | n_combo=N_COMBO,
17 | irr_measure_method=MEASURE,
18 | novel_objects=True,
19 | extra_tag="novel_scene_test",
20 | debug=False,
21 | countertop_scale=None,
22 | randomize_materials_lighting=True,
23 | texture_randomization_keys=None,
24 | cfg_name="rgb.yaml",
25 | )
26 |
27 | EVAL_TARGET_TYPES = cfg.EVAL_TARGET_TYPES
28 |
29 | THOR_TEST_COMMIT_ID = STRETCH_MANIPULATHOR_FURNISHED_COMMIT_ID
30 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/tests/budegt_and_measurement/measure_random_novel_texture_lightning.py:
--------------------------------------------------------------------------------
1 | from projects.strech_manipulation.experiments.tests.budegt_and_measurement.measure_random_in_domain import (
2 | StretchMeasureTestConfig,
3 | get_measure_test_cfg,
4 | N_COMBO,
5 | MEASURE,
6 | )
7 |
8 |
9 | class SingleComboConfig(StretchMeasureTestConfig):
10 |
11 | cfg = get_measure_test_cfg(
12 | n_combo=N_COMBO,
13 | irr_measure_method=MEASURE,
14 | novel_objects=False,
15 | extra_tag="novel_texture_lightning_test",
16 | debug=False,
17 | countertop_scale=None,
18 | randomize_materials_lighting=True,
19 | texture_randomization_keys=None,
20 | cfg_name="rgb.yaml",
21 | )
22 | EVAL_TARGET_TYPES = cfg.EVAL_TARGET_TYPES
23 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/tests/episodic/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/projects/strech_manipulation/experiments/tests/episodic/__init__.py
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/tests/episodic/random_5e3_single_combo_novel_objects.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import TestingCombos
2 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
3 | RFStretchPickPlaceExperimentConfigBase,
4 | get_cfg,
5 | )
6 |
7 | CFG = get_cfg(
8 | debug=False,
9 | countertop_scale=None,
10 | keep_extra_furniture=False,
11 | randomize_materials_lighting=False,
12 | texture_randomization_keys=None,
13 | irr_measure_method="euclidean",
14 | cfg_name="rgb.yaml",
15 | )
16 |
17 |
18 | class SingleComboConfig(RFStretchPickPlaceExperimentConfigBase):
19 |
20 | cfg = CFG
21 |
22 | TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
23 | EVAL_TARGET_TYPES = TestingCombos
24 | MAX_STEPS = 300
25 |
26 | @classmethod
27 | def tag(cls) -> str:
28 | return f"Red_Apple-Stripe_Plate-random-5e3-novel_objects_test"
29 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/tests/episodic/random_5e3_single_combo_novel_pos.py:
--------------------------------------------------------------------------------
1 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
2 | RFStretchPickPlaceExperimentConfigBase,
3 | get_cfg,
4 | )
5 |
6 | CFG = get_cfg(
7 | debug=False,
8 | countertop_scale=None,
9 | keep_extra_furniture=False,
10 | randomize_materials_lighting=False,
11 | texture_randomization_keys=None,
12 | irr_measure_method="euclidean",
13 | cfg_name="rgb.yaml",
14 | )
15 |
16 |
17 | class SingleComboConfig(RFStretchPickPlaceExperimentConfigBase):
18 |
19 | cfg = CFG
20 |
21 | TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
22 | EVAL_TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
23 | MAX_STEPS = 300
24 |
25 | @classmethod
26 | def tag(cls) -> str:
27 | return f"Red_Apple-Stripe_Plate-random-5e3-pos_ood_test"
28 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/tests/episodic/random_5e3_single_combo_novel_scene.py:
--------------------------------------------------------------------------------
1 | from allenact_plugins.stretch_manipulathor_plugin.stretch_constants import (
2 | TestingCombos,
3 | STRETCH_MANIPULATHOR_FURNISHED_COMMIT_ID,
4 | )
5 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
6 | RFStretchPickPlaceExperimentConfigBase,
7 | get_cfg,
8 | )
9 |
10 | CFG = get_cfg(
11 | debug=False,
12 | countertop_scale=None,
13 | keep_extra_furniture=False,
14 | randomize_materials_lighting=True,
15 | texture_randomization_keys=None,
16 | irr_measure_method="euclidean",
17 | cfg_name="rgb.yaml",
18 | )
19 |
20 |
21 | class SingleComboConfig(RFStretchPickPlaceExperimentConfigBase):
22 |
23 | cfg = CFG
24 |
25 | TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
26 | EVAL_TARGET_TYPES = TestingCombos
27 | THOR_TEST_COMMIT_ID = STRETCH_MANIPULATHOR_FURNISHED_COMMIT_ID
28 | MAX_STEPS = 300
29 |
30 | @classmethod
31 | def tag(cls) -> str:
32 | return f"Red_Apple-Stripe_Plate-random-5e3-novel_scene_test"
33 |
--------------------------------------------------------------------------------
/projects/strech_manipulation/experiments/tests/episodic/random_5e3_single_combo_novel_texture_lightning.py:
--------------------------------------------------------------------------------
1 | from projects.strech_manipulation.experiments.budget_measure_ablation.base import (
2 | RFStretchPickPlaceExperimentConfigBase,
3 | get_cfg,
4 | )
5 |
6 | CFG = get_cfg(
7 | debug=False,
8 | countertop_scale=None,
9 | keep_extra_furniture=False,
10 | randomize_materials_lighting=True,
11 | texture_randomization_keys=None,
12 | irr_measure_method="euclidean",
13 | cfg_name="rgb.yaml",
14 | )
15 |
16 |
17 | class SingleComboConfig(RFStretchPickPlaceExperimentConfigBase):
18 |
19 | cfg = CFG
20 |
21 | TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
22 | EVAL_TARGET_TYPES = [("Red_Apple", "Stripe_Plate")]
23 | MAX_STEPS = 300
24 |
25 | @classmethod
26 | def tag(cls) -> str:
27 | return f"Red_Apple-Stripe_Plate-random-5e3-randomize_texture_lightning_test"
28 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | ai2thor>=2.5.3
2 | attrs==22.1.0
3 | attr==0.3.2
4 | dm-tree==0.1.7
5 | einops==0.5.0
6 | filelock==3.0.12
7 | ftfy
8 | hydra-core==1.3.0
9 | matplotlib==3.3.3
10 | moviepy==1.0.3
11 | mujoco-py>=2.1,<2.2
12 | networkx==2.5
13 | numpy
14 | numpy-quaternion
15 | omegaconf==2.2.3
16 | opencv_python==4.5.1.48
17 | pillow==9.2.0
18 | pyquaternion>=0.9.9
19 | python-xlib
20 | regex
21 | scipy==1.7.3
22 | setproctitle==1.2.1
23 | setuptools==63.4.1
24 | tensorboard==2.10.1
25 | tensorboardX==2.5.1
26 | tqdm
27 | tree==0.2.4
28 | typing_extensions==4.4
29 | wandb==0.13.9
30 | clip @ git+https://github.com/openai/CLIP.git@e184f608c5d5e58165682f7c332c3a8b4c1545f2
31 | metaworld @ git+https://github.com/Farama-Foundation/Metaworld.git@master#egg=metaworld
32 |
--------------------------------------------------------------------------------
/scripts/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zcczhang/rmrl/f065a42e24f9f560c4c0ef48dead0338ae6e1bc6/scripts/__init__.py
--------------------------------------------------------------------------------
/scripts/startx.py:
--------------------------------------------------------------------------------
1 | import atexit
2 | import os
3 | import platform
4 | import re
5 | import shlex
6 | import subprocess
7 | import tempfile
8 |
9 |
10 | # Turning off automatic black formatting for this script as it breaks quotes.
11 |
12 | # fmt: off
13 |
14 | def pci_records():
15 | records = []
16 | command = shlex.split("lspci -vmm")
17 | output = subprocess.check_output(command).decode()
18 |
19 | for devices in output.strip().split("\n\n"):
20 | record = {}
21 | records.append(record)
22 | for row in devices.split("\n"):
23 | key, value = row.split("\t")
24 | record[key.split(":")[0]] = value
25 |
26 | return records
27 |
28 | def generate_xorg_conf(devices):
29 | xorg_conf = []
30 |
31 | device_section = """
32 | Section "Device"
33 | Identifier "Device{device_id}"
34 | Driver "nvidia"
35 | VendorName "NVIDIA Corporation"
36 | BusID "{bus_id}"
37 | EndSection
38 | """
39 | server_layout_section = """
40 | Section "ServerLayout"
41 | Identifier "Layout0"
42 | {screen_records}
43 | EndSection
44 | """
45 | screen_section = """
46 | Section "Screen"
47 | Identifier "Screen{screen_id}"
48 | Device "Device{device_id}"
49 | DefaultDepth 24
50 | Option "AllowEmptyInitialConfiguration" "True"
51 | SubSection "Display"
52 | Depth 24
53 | Virtual 1024 768
54 | EndSubSection
55 | EndSection
56 | """
57 | screen_records = []
58 | for i, bus_id in enumerate(devices):
59 | xorg_conf.append(device_section.format(device_id=i, bus_id=bus_id))
60 | xorg_conf.append(screen_section.format(device_id=i, screen_id=i))
61 | screen_records.append('Screen {screen_id} "Screen{screen_id}" 0 0'.format(screen_id=i))
62 |
63 | xorg_conf.append(server_layout_section.format(screen_records="\n ".join(screen_records)))
64 |
65 | output = "\n".join(xorg_conf)
66 | return output
67 |
68 | def startx(display=0):
69 | if platform.system() != "Linux":
70 | raise Exception("Can only run startx on linux")
71 |
72 | devices = []
73 | for r in pci_records():
74 | if r.get("Vendor", "") == "NVIDIA Corporation" \
75 | and r["Class"] in ["VGA compatible controller", "3D controller"]:
76 | bus_id = "PCI:" + ":".join(map(lambda x: str(int(x, 16)), re.split(r"[:\.]", r["Slot"])))
77 | devices.append(bus_id)
78 |
79 | if not devices:
80 | raise Exception("no nvidia cards found")
81 |
82 | try:
83 | fd, path = tempfile.mkstemp()
84 | with open(path, "w") as f:
85 | f.write(generate_xorg_conf(devices))
86 | command = shlex.split("Xorg -noreset +extension GLX +extension RANDR +extension RENDER -config %s :%s" % (path, display))
87 | proc = subprocess.Popen(command)
88 | atexit.register(lambda: proc.poll() is None and proc.kill())
89 | proc.wait()
90 | finally:
91 | os.close(fd)
92 | os.unlink(path)
93 |
94 | # fmt: on
95 |
96 |
97 | if __name__ == "__main__":
98 | startx()
99 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | import os
2 | import pathlib
3 |
4 | import pkg_resources
5 | from setuptools import setup, find_packages
6 |
7 | PKG_NAME = "rmrl"
8 | VERSION = "0.0.1"
9 | EXTRAS = {}
10 |
11 |
12 | def _read_file(fname):
13 | # this_dir = os.path.abspath(os.path.dirname(__file__))
14 | # with open(os.path.join(this_dir, fname)) as f:
15 | with pathlib.Path(fname).open() as fp:
16 | return fp.read()
17 |
18 |
19 | def _read_install_requires():
20 | with pathlib.Path("requirements.txt").open() as fp:
21 | main = [
22 | str(requirement) for requirement in pkg_resources.parse_requirements(fp)
23 | ]
24 | plugins = []
25 | for plugin in os.listdir("allenact_plugins"):
26 | req_path = os.path.join("allenact_plugins", plugin, "extra_requirements.txt")
27 | if os.path.exists(req_path):
28 | with pathlib.Path(req_path).open() as fp:
29 | plugins += [
30 | str(requirement)
31 | for requirement in pkg_resources.parse_requirements(fp)
32 | ]
33 | return main + plugins
34 |
35 |
36 | def _fill_extras(extras):
37 | if extras:
38 | extras["all"] = list(set([item for group in extras.values() for item in group]))
39 | return extras
40 |
41 |
42 | setup(
43 | name=PKG_NAME,
44 | version=VERSION,
45 | author=f"{PKG_NAME} Developers",
46 | # url='http://github.com/',
47 | description="research project",
48 | long_description=_read_file("README.md"),
49 | long_description_content_type="text/markdown",
50 | keywords=["Deep Learning", "Reinforcement Learning"],
51 | license="MIT",
52 | packages=find_packages(include=f"{PKG_NAME}.*"),
53 | include_package_data=True,
54 | zip_safe=False,
55 | entry_points={
56 | "console_scripts": [
57 | # 'cmd_tool=mylib.subpkg.module:main',
58 | ]
59 | },
60 | install_requires=_read_install_requires(),
61 | extras_require=_fill_extras(EXTRAS),
62 | python_requires=">=3.7",
63 | classifiers=[
64 | "Development Status :: 3 - Alpha",
65 | "Topic :: Scientific/Engineering :: Artificial Intelligence",
66 | "Environment :: Console",
67 | "Programming Language :: Python :: 3",
68 | ],
69 | )
70 |
--------------------------------------------------------------------------------