diff --git a/configs/tasks/objectnav_mp3d.yaml b/configs/tasks/objectnav_mp3d.yaml index 8811ba838a4d7fc8af95418b250041f0f6700332..2f5dd4b0af61fef9794dd9eb087871abbcf97b50 100644 --- a/configs/tasks/objectnav_mp3d.yaml +++ b/configs/tasks/objectnav_mp3d.yaml @@ -1,5 +1,8 @@ ENVIRONMENT: MAX_EPISODE_STEPS: 500 + ITERATOR_OPTIONS: + CYCLE: True + NUM_EPISODE_SAMPLE: 4 SIMULATOR: TURN_ANGLE: 30 TILT_ANGLE: 30 @@ -20,6 +23,9 @@ SIMULATOR: HEIGHT: 480 HFOV: 79 POSITION: [0, 0.88, 0] + NOISE_MODEL: "GaussianNoiseModel" + NOISE_MODEL_KWARGS: + intensity_constant: 0.1 DEPTH_SENSOR: WIDTH: 640 HEIGHT: 480 @@ -27,6 +33,7 @@ SIMULATOR: MIN_DEPTH: 0.5 MAX_DEPTH: 5.0 POSITION: [0, 0.88, 0] + NOISE_MODEL: "RedwoodDepthNoiseModel" TASK: TYPE: ObjectNav-v1 POSSIBLE_ACTIONS: ["STOP", "MOVE_FORWARD", "TURN_LEFT", "TURN_RIGHT", "LOOK_UP", "LOOK_DOWN"] @@ -45,7 +52,7 @@ TASK: DATASET: TYPE: ObjectNav-v1 - SPLIT: val - CONTENT_SCENES: [] + SPLIT: train + CONTENT_SCENES: ["GdvgFV5R1Z5", "GdvgFV5R1Z5", "GdvgFV5R1Z5", "GdvgFV5R1Z5"] # ["YmJkqBEsHnH", "YmJkqBEsHnH", "YmJkqBEsHnH", "YmJkqBEsHnH"] # ["*"] # DATA_PATH: "data/datasets/objectnav/mp3d/v0/{split}/{split}.json.gz" SCENES_DIR: "data/scene_datasets/" diff --git a/examples/shortest_path_follower_example.py b/examples/shortest_path_follower_example.py index 7b2262aed1e60c2d56d588e562c7f349d3277619..2d0e397195f8832eeb09763734de71b69a48a14d 100644 --- a/examples/shortest_path_follower_example.py +++ b/examples/shortest_path_follower_example.py @@ -62,7 +62,9 @@ def draw_top_down_map(info, heading, output_size): def shortest_path_example(mode): - config = habitat.get_config(config_paths="configs/tasks/pointnav.yaml") + config = habitat.get_config( + config_paths="configs/tasks/objectnav_mp3d.yaml" + ) config.defrost() config.TASK.MEASUREMENTS.append("TOP_DOWN_MAP") config.TASK.SENSORS.append("HEADING_SENSOR") @@ -97,8 +99,13 @@ def shortest_path_example(mode): top_down_map = draw_top_down_map( info, observations["heading"][0], im.shape[0] ) + from habitat.utils.visualizations.utils import ( + observations_to_image, + ) + output_im = np.concatenate((im, top_down_map), axis=1) - images.append(output_im) + + images.append(observations_to_image(observations, info)) images_to_video(images, dirname, "trajectory") print("Episode finished") diff --git a/habitat/config/default.py b/habitat/config/default.py index 1182a03e82fdc6c618d820f50a04fd326ffeb8fe..1031ef26b7f6d145ed64ce050167b658875abb33 100644 --- a/habitat/config/default.py +++ b/habitat/config/default.py @@ -212,6 +212,8 @@ SIMULATOR_SENSOR.HEIGHT = 480 SIMULATOR_SENSOR.WIDTH = 640 SIMULATOR_SENSOR.HFOV = 90 # horizontal field of view in degrees SIMULATOR_SENSOR.POSITION = [0, 1.25, 0] +SIMULATOR_SENSOR.ORIENTATION = [0.0, 0.0, 0.0] +SIMULATOR_SENSOR.NOISE_MODEL = "None" # ----------------------------------------------------------------------------- # RGB SENSOR # ----------------------------------------------------------------------------- @@ -242,7 +244,7 @@ _C.SIMULATOR.AGENT_0.ANGULAR_ACCELERATION = 4 * 3.14 _C.SIMULATOR.AGENT_0.LINEAR_FRICTION = 0.5 _C.SIMULATOR.AGENT_0.ANGULAR_FRICTION = 1.0 _C.SIMULATOR.AGENT_0.COEFFICIENT_OF_RESTITUTION = 0.0 -_C.SIMULATOR.AGENT_0.SENSORS = ["RGB_SENSOR"] +_C.SIMULATOR.AGENT_0.SENSORS = ["RGB_SENSOR", "DEPTH_SENSOR"] _C.SIMULATOR.AGENT_0.IS_SET_START_STATE = False _C.SIMULATOR.AGENT_0.START_POSITION = [0, 0, 0] _C.SIMULATOR.AGENT_0.START_ROTATION = [0, 0, 0, 1] diff --git a/habitat/core/dataset.py b/habitat/core/dataset.py index 00e70f5ad843d4bb208edf98cc10964406587ad0..3b74acdf51c26aa1d0c160bc788a188e91ab66f8 100644 --- a/habitat/core/dataset.py +++ b/habitat/core/dataset.py @@ -309,6 +309,13 @@ class EpisodeIterator(Iterator): # sample episodes if num_episode_sample >= 0: + np.random.seed(100) + print(f"np.random.state {np.random.get_state()[0]}") + episodes = [ + episode + for episode in episodes + if episode.episode_id in ["7", "77", "774", "10"] + ] episodes = np.random.choice( episodes, num_episode_sample, replace=False ) diff --git a/habitat/core/env.py b/habitat/core/env.py index 273a9775e8d5c08bd23c8d85fa6bd852acb7bc92..f79ef247aab3a3c706aaf88632c7ccf9150d8dd7 100644 --- a/habitat/core/env.py +++ b/habitat/core/env.py @@ -4,6 +4,7 @@ # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. +import random import time from typing import Any, Dict, Iterator, List, Optional, Tuple, Type, Union @@ -91,6 +92,9 @@ class Env: self._config.defrost() self._config.SIMULATOR.SCENE = self._dataset.episodes[0].scene_id self._config.freeze() + print( + f"scenes{self._dataset.scene_ids}len(self._dataset.episodes) = {len(self._dataset.episodes)}" + ) self._sim = make_sim( id_sim=self._config.SIMULATOR.TYPE, config=self._config.SIMULATOR @@ -198,6 +202,7 @@ class Env: assert len(self.episodes) > 0, "Episodes list is empty" self._current_episode = next(self._episode_iterator) + # print(f"self._current_episode: {self._current_episode.episode_id} {self._current_episode.scene_id}") self.reconfigure(self._config) observations = self.task.reset(episode=self.current_episode) @@ -254,6 +259,8 @@ class Env: return observations def seed(self, seed: int) -> None: + np.random.seed(seed) + random.seed(seed) self._sim.seed(seed) self._task.seed(seed) diff --git a/habitat/datasets/object_nav/object_nav_dataset.py b/habitat/datasets/object_nav/object_nav_dataset.py index a595b26bdadf254969868feda27eefc4bd7fc8bb..c0437346a9ba044064993b8d942d26fc099fc0d2 100644 --- a/habitat/datasets/object_nav/object_nav_dataset.py +++ b/habitat/datasets/object_nav/object_nav_dataset.py @@ -36,7 +36,11 @@ class ObjectNavDatasetV1(PointNavDatasetV1): def from_json( self, json_str: str, scenes_dir: Optional[str] = None ) -> None: + from habitat.core.logging import logger + + logger.info(f"deserializing") deserialized = json.loads(json_str) + logger.info("unpacking") if CONTENT_SCENES_PATH_FIELD in deserialized: self.content_scenes_path = deserialized[CONTENT_SCENES_PATH_FIELD] @@ -98,3 +102,4 @@ class ObjectNavDatasetV1(PointNavDatasetV1): for i, ep in enumerate(self.episodes): ep.episode_id = str(i) + logger.info("unpacked.") diff --git a/habitat/sims/habitat_simulator/habitat_simulator.py b/habitat/sims/habitat_simulator/habitat_simulator.py index 244258270d53e989ff319d75cef759c8bbf4edda..2c2eab0df86d166504cc705935bf832c4f1c5bf7 100644 --- a/habitat/sims/habitat_simulator/habitat_simulator.py +++ b/habitat/sims/habitat_simulator/habitat_simulator.py @@ -186,12 +186,18 @@ class HabitatSim(Simulator): sensor_specifications = [] for sensor in _sensor_suite.sensors.values(): sim_sensor_cfg = habitat_sim.SensorSpec() + overwrite_config( + config_from=sensor.config, config_to=sim_sensor_cfg + ) sim_sensor_cfg.uuid = sensor.uuid sim_sensor_cfg.resolution = list( sensor.observation_space.shape[:2] ) sim_sensor_cfg.parameters["hfov"] = str(sensor.config.HFOV) - sim_sensor_cfg.position = sensor.config.POSITION + # sim_sensor_cfg.position = sensor.config.POSITION + # sim_sensor_cfg.orientation = np.array(sensor.config.ORIENTATION, dtype=np.float32) + # sim_sensor_cfg.noise_model = sensor.config.NOISE_MODEL + # TODO(maksymets): Add configure method to Sensor API to avoid # accessing child attributes through parent interface sim_sensor_cfg.sensor_type = sensor.sim_sensor_type # type: ignore diff --git a/habitat/tasks/nav/nav.py b/habitat/tasks/nav/nav.py index 49d835d2dad256d82518e6a04d04f5f5a64b2e49..62159d8dda3babda5502b4df6bbc47e61099d447 100644 --- a/habitat/tasks/nav/nav.py +++ b/habitat/tasks/nav/nav.py @@ -817,6 +817,9 @@ class DistanceToGoal(Measure): for goal in episode.goals for view_point in goal.view_points ] + # logger.info( + # f"episode: {episode.episode_id}, {episode.goals[0].object_category} self._episode_view_points { len(self._episode_view_points)}." + # ) self.update_metric(*args, episode=episode, **kwargs) def _euclidean_distance(self, position_a, position_b): diff --git a/habitat_baselines/common/env_utils.py b/habitat_baselines/common/env_utils.py index 1c87463e6edb1dcc8ea72ca2e9edaab92a655b15..0e8d350e690183a29e2cc8dc8ada4a5576f320c9 100644 --- a/habitat_baselines/common/env_utils.py +++ b/habitat_baselines/common/env_utils.py @@ -54,8 +54,11 @@ def construct_envs( configs = [] env_classes = [env_class for _ in range(num_processes)] dataset = make_dataset(config.TASK_CONFIG.DATASET.TYPE) - scenes = dataset.get_scenes_to_load(config.TASK_CONFIG.DATASET) + scenes = config.TASK_CONFIG.DATASET.CONTENT_SCENES + if "*" in config.TASK_CONFIG.DATASET.CONTENT_SCENES: + scenes = dataset.get_scenes_to_load(config.TASK_CONFIG.DATASET) + print(f"len(scenes): {len(scenes)}") if len(scenes) > 0: random.shuffle(scenes) diff --git a/habitat_baselines/common/utils.py b/habitat_baselines/common/utils.py index d9b976765786f934f36494a9db9ff58ee8ca3cc2..8ddb184f6128811ad9885f12756c2ce039c42ecf 100644 --- a/habitat_baselines/common/utils.py +++ b/habitat_baselines/common/utils.py @@ -165,5 +165,9 @@ def generate_video( images_to_video(images, video_dir, video_name) if "tensorboard" in video_option: tb_writer.add_video_from_np_images( - f"episode{episode_id}", checkpoint_idx, images, fps=fps + # f"episode{episode_id}", + video_name, + checkpoint_idx, + images, + fps=fps, ) diff --git a/habitat_baselines/config/objectnav/ddppo_objectnav.yaml b/habitat_baselines/config/objectnav/ddppo_objectnav.yaml index 1e759ad89264bc52b4eda4560d80c49903decac1..1881ceb16cc463b329cd6abba278e616fc520079 100644 --- a/habitat_baselines/config/objectnav/ddppo_objectnav.yaml +++ b/habitat_baselines/config/objectnav/ddppo_objectnav.yaml @@ -4,23 +4,26 @@ ENV_NAME: "NavRLEnv" SIMULATOR_GPU_ID: 0 TORCH_GPU_ID: 1 VIDEO_OPTION: ["disk", "tensorboard"] -TENSORBOARD_DIR: "/checkpoint/maksymets/logs/habitat_baselines/ddppo/obj_nav_mp3d" +TENSORBOARD_DIR: "/checkpoint/maksymets/logs/habitat_baselines/ddppo/obj_nav_mp3d_4_ep_slack-1e3" VIDEO_DIR: "data/video_dir" -TEST_EPISODE_COUNT: 2184 -EVAL_CKPT_PATH_DIR: "data/new_checkpoints" -NUM_PROCESSES: 2 +TEST_EPISODE_COUNT: 1 +EVAL_CKPT_PATH_DIR: "data/new_checkpoints/obj_nav_mp3d_4_ep_slack-1e3" +NUM_PROCESSES: 4 SENSORS: ["DEPTH_SENSOR", "RGB_SENSOR"] -CHECKPOINT_FOLDER: "data/new_checkpoints" -NUM_UPDATES: 10000 +CHECKPOINT_FOLDER: "data/new_checkpoints/obj_nav_mp3d_4_ep_slack-1e3" +NUM_UPDATES: 270000 LOG_INTERVAL: 10 CHECKPOINT_INTERVAL: 50 +EVAL: + SPLIT: "train" RL: SUCCESS_REWARD: 2.5 + SLACK_REWARD: -1e-3 PPO: # ppo params clip_param: 0.2 - ppo_epoch: 2 + ppo_epoch: 4 num_mini_batch: 2 value_loss_coef: 0.5 entropy_coef: 0.01 diff --git a/habitat_baselines/config/pointnav/ddppo_pointnav.yaml b/habitat_baselines/config/pointnav/ddppo_pointnav.yaml index b6f56c62d5d4d2db259d57643d810df6768adb26..6558e350e925f35dac920737c659e2d30cb16122 100644 --- a/habitat_baselines/config/pointnav/ddppo_pointnav.yaml +++ b/habitat_baselines/config/pointnav/ddppo_pointnav.yaml @@ -8,7 +8,7 @@ TENSORBOARD_DIR: "tb" VIDEO_DIR: "video_dir" TEST_EPISODE_COUNT: 994 EVAL_CKPT_PATH_DIR: "data/new_checkpoints" -NUM_PROCESSES: 4 +NUM_PROCESSES: 2 SENSORS: ["DEPTH_SENSOR"] CHECKPOINT_FOLDER: "data/new_checkpoints" NUM_UPDATES: 10000 diff --git a/habitat_baselines/rl/ddppo/single_node_obj_nav.sh b/habitat_baselines/rl/ddppo/single_node_obj_nav.sh new file mode 100644 index 0000000000000000000000000000000000000000..df389cd3dd91f05bd54bfea96bce529129c11b2e --- /dev/null +++ b/habitat_baselines/rl/ddppo/single_node_obj_nav.sh @@ -0,0 +1,12 @@ +#/bin/bash + +export GLOG_minloglevel=2 +export MAGNUM_LOG=quiet + +set -x +python -u -m torch.distributed.launch \ + --use_env \ + --nproc_per_node 1 \ + habitat_baselines/run.py \ + --exp-config habitat_baselines/config/objectnav/ddppo_objectnav.yaml \ + --run-type train diff --git a/tb/events.out.tfevents.1580768898.devfair0194.69437.0 b/tb/events.out.tfevents.1580768898.devfair0194.69437.0 new file mode 100644 index 0000000000000000000000000000000000000000..b954c8a63fb6be701f80cb65d12fcb361d9cf340 Binary files /dev/null and b/tb/events.out.tfevents.1580768898.devfair0194.69437.0 differ diff --git a/tb/events.out.tfevents.1580943506.devfair0194.30021.0 b/tb/events.out.tfevents.1580943506.devfair0194.30021.0 new file mode 100644 index 0000000000000000000000000000000000000000..98ae3d4bfd6d18f265bf43c7bd9431c1713aad10 Binary files /dev/null and b/tb/events.out.tfevents.1580943506.devfair0194.30021.0 differ diff --git a/tb/events.out.tfevents.1580946428.devfair0194.34988.0 b/tb/events.out.tfevents.1580946428.devfair0194.34988.0 new file mode 100644 index 0000000000000000000000000000000000000000..796eb3e24f753fb9861cd5924de125b2845aa9d3 Binary files /dev/null and b/tb/events.out.tfevents.1580946428.devfair0194.34988.0 differ diff --git a/tb/losses/policy/events.out.tfevents.1580768902.devfair0194.69437.2 b/tb/losses/policy/events.out.tfevents.1580768902.devfair0194.69437.2 new file mode 100644 index 0000000000000000000000000000000000000000..769bf65661095cb8c6215c35c1a76face53e8dd6 Binary files /dev/null and b/tb/losses/policy/events.out.tfevents.1580768902.devfair0194.69437.2 differ diff --git a/tb/losses/policy/events.out.tfevents.1580946531.devfair0194.34988.2 b/tb/losses/policy/events.out.tfevents.1580946531.devfair0194.34988.2 new file mode 100644 index 0000000000000000000000000000000000000000..372a4b19d3613bac5f5ea87f1173ea0f9846b246 Binary files /dev/null and b/tb/losses/policy/events.out.tfevents.1580946531.devfair0194.34988.2 differ diff --git a/tb/losses/value/events.out.tfevents.1580768902.devfair0194.69437.1 b/tb/losses/value/events.out.tfevents.1580768902.devfair0194.69437.1 new file mode 100644 index 0000000000000000000000000000000000000000..b5416a2f96807e103601adb623ce68e42d77ebef Binary files /dev/null and b/tb/losses/value/events.out.tfevents.1580768902.devfair0194.69437.1 differ diff --git a/tb/losses/value/events.out.tfevents.1580946531.devfair0194.34988.1 b/tb/losses/value/events.out.tfevents.1580946531.devfair0194.34988.1 new file mode 100644 index 0000000000000000000000000000000000000000..43dd6f5345f9e0b8f8e85e9617d13d17c7d424a4 Binary files /dev/null and b/tb/losses/value/events.out.tfevents.1580946531.devfair0194.34988.1 differ