Ejemplo n.º 1
0
def make_orb_config():
    baseline_config = get_config("configs/tasks/pointnav_rgbd.yaml")
    config = habitat.get_config("configs/tasks/pointnav_rgbd.yaml")

    config.defrost()
    baseline_config.defrost()

    config.TASK_CONFIG = baseline_config.TASK_CONFIG
    config.ORBSLAM2 = baseline_config.ORBSLAM2
    config.ORBSLAM2.SLAM_VOCAB_PATH = "data/ORBvoc.txt"
    config.ORBSLAM2.SLAM_SETTINGS_PATH = "configs/orbslam2/mp3d3_small1k.yaml"
    config.ORBSLAM2.DIST_TO_STOP = 0.2
    config.ORBSLAM2.MAP_CELL_SIZE = 0.10
    config.SIMULATOR.AGENT_0.SENSORS = [
        "RGB_SENSOR",
        "DEPTH_SENSOR",
    ]
    config.SIMULATOR.RGB_SENSOR.WIDTH = 256
    config.SIMULATOR.RGB_SENSOR.HEIGHT = 256
    config.SIMULATOR.DEPTH_SENSOR.WIDTH = 256
    config.SIMULATOR.DEPTH_SENSOR.HEIGHT = 256
    config.ORBSLAM2.CAMERA_HEIGHT = config.SIMULATOR.DEPTH_SENSOR.POSITION[1]
    config.ORBSLAM2.H_OBSTACLE_MIN = 0.3 * config.ORBSLAM2.CAMERA_HEIGHT
    config.ORBSLAM2.H_OBSTACLE_MAX = 1.0 * config.ORBSLAM2.CAMERA_HEIGHT
    config.ORBSLAM2.MIN_PTS_IN_OBSTACLE = config.SIMULATOR.DEPTH_SENSOR.WIDTH / 2.0

    config.freeze()
    baseline_config.freeze()

    return config
Ejemplo n.º 2
0
def main():
    HabitatSimActions.extend_action_space("STRAFE_LEFT")
    HabitatSimActions.extend_action_space("STRAFE_RIGHT")

    config = habitat.get_config(config_paths="configs/tasks/pointnav.yaml")
    config.defrost()

    config.TASK.POSSIBLE_ACTIONS = config.TASK.POSSIBLE_ACTIONS + [
        "STRAFE_LEFT",
        "STRAFE_RIGHT",
    ]
    config.TASK.ACTIONS.STRAFE_LEFT = habitat.config.Config()
    config.TASK.ACTIONS.STRAFE_LEFT.TYPE = "StrafeLeft"
    config.TASK.ACTIONS.STRAFE_RIGHT = habitat.config.Config()
    config.TASK.ACTIONS.STRAFE_RIGHT.TYPE = "StrafeRight"
    config.SIMULATOR.ACTION_SPACE_CONFIG = "NoNoiseStrafe"
    config.freeze()

    with habitat.Env(config=config) as env:
        env.reset()
        env.step("STRAFE_LEFT")
        env.step("STRAFE_RIGHT")

    config.defrost()
    config.SIMULATOR.ACTION_SPACE_CONFIG = "NoiseStrafe"
    config.freeze()

    with habitat.Env(config=config) as env:
        env.reset()
        env.step("STRAFE_LEFT")
        env.step("STRAFE_RIGHT")
def _generate_fn(scene):
    cfg = habitat.get_config()
    cfg.defrost()
    cfg.SIMULATOR.SCENE = scene
    cfg.SIMULATOR.AGENT_0.SENSORS = []
    cfg.freeze()

    sim = habitat.sims.make_sim("Sim-v0", config=cfg.SIMULATOR)

    dset = habitat.datasets.make_dataset("PointNav-v1")
    dset.episodes = list(
        generate_pointnav_episode(
            sim, NUM_EPISODES_PER_SCENE, is_gen_shortest_path=False
        )
    )
    for ep in dset.episodes:
        ep.scene_id = ep.scene_id[len("./data/scene_datasets/") :]

    scene_key = scene.split("/")[-1].split(".")[0]
    out_file = (
        f"./data/datasets/pointnav/gibson/v2/train_large/content/"
        f"{scene_key}.json.gz"
    )
    os.makedirs(osp.dirname(out_file), exist_ok=True)
    with gzip.open(out_file, "wt") as f:
        f.write(dset.to_json())
Ejemplo n.º 4
0
def shortest_path_example(mode):
    config = habitat.get_config(config_paths="configs/tasks/pointnav.yaml")
    config.TASK.MEASUREMENTS.append("TOP_DOWN_MAP")
    config.TASK.SENSORS.append("HEADING_SENSOR")
    env = SimpleRLEnv(config=config)
    goal_radius = env.episodes[0].goals[0].radius
    if goal_radius is None:
        goal_radius = config.SIMULATOR.FORWARD_STEP_SIZE
    follower = ShortestPathFollower(env.habitat_env.sim, goal_radius, False)
    follower.mode = mode

    print("Environment creation successful")
    for episode in range(3):
        env.reset()
        dirname = os.path.join(
            IMAGE_DIR, "shortest_path_example", mode, "%02d" % episode
        )
        if os.path.exists(dirname):
            shutil.rmtree(dirname)
        os.makedirs(dirname)
        print("Agent stepping around inside environment.")
        images = []
        while not env.habitat_env.episode_over:
            best_action = follower.get_next_action(
                env.habitat_env.current_episode.goals[0].position
            )
            observations, reward, done, info = env.step(best_action.value)
            im = observations["rgb"]
            top_down_map = draw_top_down_map(
                info, observations["heading"], im.shape[0]
            )
            output_im = np.concatenate((im, top_down_map), axis=1)
            images.append(output_im)
        images_to_video(images, dirname, "trajectory")
        print("Episode finished")
Ejemplo n.º 5
0
def generate_sampled_train(config_path="datasets/pointnav/gibson.yaml",
                           num_episodes=1000):
    config = habitat.get_config(config_path, config_dir="habitat-api/configs")
    config.defrost()
    config.DATASET.SPLIT = "train"
    config.freeze()
    print("Dataset is loading.")
    dataset = habitat.make_dataset(id_dataset=config.DATASET.TYPE,
                                   config=config.DATASET)
    print(config.DATASET.SPLIT + ": Len episodes: ", len(dataset.episodes))
    dataset.episodes = random.sample(dataset.episodes, num_episodes)
    print("Average geo distance: ", get_avg_geo_dist(dataset))

    json_str = str(dataset.to_json())

    output_dir = "data/datasets/pointnav/gibson/v1/{}_small_2/".format(
        config.DATASET.SPLIT)
    if not os.path.exists(output_dir):
        os.mkdir(output_dir)
    main_dataset_file = "{}/{}_small_2.json.gz".format(output_dir,
                                                       config.DATASET.SPLIT)
    with gzip.GzipFile(main_dataset_file, 'wb') as f:
        f.write(json_str.encode("utf-8"))

    print("Dataset file: {}".format(main_dataset_file))
Ejemplo n.º 6
0
def test_ppo_agents():

    agent_config = ppo_agents.get_default_config()
    agent_config.MODEL_PATH = ""
    agent_config.defrost()
    config_env = habitat.get_config(config_paths=CFG_TEST)
    if not os.path.exists(config_env.SIMULATOR.SCENE):
        pytest.skip("Please download Habitat test data to data folder.")

    benchmark = habitat.Benchmark(config_paths=CFG_TEST)

    for input_type in ["blind", "rgb", "depth", "rgbd"]:
        for resolution in [256, 384]:
            config_env.defrost()
            config_env.SIMULATOR.AGENT_0.SENSORS = []
            if input_type in ["rgb", "rgbd"]:
                config_env.SIMULATOR.AGENT_0.SENSORS += ["RGB_SENSOR"]
                agent_config.RESOLUTION = resolution
                config_env.SIMULATOR.RGB_SENSOR.WIDTH = resolution
                config_env.SIMULATOR.RGB_SENSOR.HEIGHT = resolution
            if input_type in ["depth", "rgbd"]:
                config_env.SIMULATOR.AGENT_0.SENSORS += ["DEPTH_SENSOR"]
                agent_config.RESOLUTION = resolution
                config_env.SIMULATOR.DEPTH_SENSOR.WIDTH = resolution
                config_env.SIMULATOR.DEPTH_SENSOR.HEIGHT = resolution

            config_env.freeze()

            del benchmark._env
            benchmark._env = habitat.Env(config=config_env)
            agent_config.INPUT_TYPE = input_type

            agent = ppo_agents.PPOAgent(agent_config)
            habitat.logger.info(benchmark.evaluate(agent, num_episodes=10))
Ejemplo n.º 7
0
def example_get_topdown_map():
    config = habitat.get_config(config_file="tasks/pointnav.yaml")
    dataset = habitat.make_dataset(
        id_dataset=config.DATASET.TYPE, config=config.DATASET
    )
    env = habitat.Env(config=config, dataset=dataset)
    env.reset()
    top_down_map = maps.get_topdown_map(env.sim, map_resolution=(5000, 5000))
    recolor_map = np.array(
        [[255, 255, 255], [128, 128, 128], [0, 0, 0]], dtype=np.uint8
    )
    range_x = np.where(np.any(top_down_map, axis=1))[0]
    range_y = np.where(np.any(top_down_map, axis=0))[0]
    padding = int(np.ceil(top_down_map.shape[0] / 125))
    range_x = (
        max(range_x[0] - padding, 0),
        min(range_x[-1] + padding + 1, top_down_map.shape[0]),
    )
    range_y = (
        max(range_y[0] - padding, 0),
        min(range_y[-1] + padding + 1, top_down_map.shape[1]),
    )
    top_down_map = top_down_map[
        range_x[0] : range_x[1], range_y[0] : range_y[1]
    ]
    top_down_map = recolor_map[top_down_map]
    imageio.imsave(os.path.join(IMAGE_DIR, "top_down_map.png"), top_down_map)
Ejemplo n.º 8
0
def shortest_path_example(mode):
    config = habitat.get_config(config_file="tasks/pointnav.yaml")
    env = habitat.Env(config=config)
    goal_radius = env.episodes[0].goals[0].radius
    if goal_radius is None:
        goal_radius = config.SIMULATOR.FORWARD_STEP_SIZE
    follower = ShortestPathFollower(env.sim, goal_radius, False)
    follower.mode = mode

    print("Environment creation successful")
    for episode in range(3):
        observations = env.reset()
        dirname = os.path.join(IMAGE_DIR, "shortest_path_example", mode,
                               "%02d" % episode)
        if os.path.exists(dirname):
            shutil.rmtree(dirname)
        os.makedirs(dirname)
        print("Agent stepping around inside environment.")
        count_steps = 0
        while not env.episode_over:
            best_action = follower.get_next_action(
                env.current_episode.goals[0].position)
            observations = env.step(SIM_NAME_TO_ACTION[best_action.value])
            count_steps += 1
            im = observations["rgb"]
            imageio.imsave(os.path.join(dirname, "%03d.jpg" % count_steps), im)
        print("Episode finished after {} steps.".format(count_steps))
    def __init__(self, env_config_file):
        threading.Thread.__init__(self)
        self.env = habitat.Env(config=habitat.get_config(env_config_file))
        # always assume height equals width
        self._sensor_resolution = {
            "RGB": self.env._sim.config["RGB_SENSOR"]["HEIGHT"],
            "DEPTH": self.env._sim.config["DEPTH_SENSOR"]["HEIGHT"],
            "BC_SENSOR": self.env._sim.config["BC_SENSOR"]["HEIGHT"],
        }
        self.env._sim._sim.agents[
            0].move_filter_fn = self.env._sim._sim._step_filter
        self.observations = self.env.reset()

        self.env._sim._sim.agents[0].state.velocity = np.float32([0, 0, 0])
        self.env._sim._sim.agents[0].state.angular_velocity = np.float32(
            [0, 0, 0])

        self._pub_rgb = rospy.Publisher("~rgb",
                                        numpy_msg(Floats),
                                        queue_size=1)
        self._pub_depth = rospy.Publisher("~depth",
                                          numpy_msg(Floats),
                                          queue_size=1)

        # additional RGB sensor I configured
        self._pub_bc_sensor = rospy.Publisher("~bc_sensor",
                                              numpy_msg(Floats),
                                              queue_size=1)

        self._pub_depth_and_pointgoal = rospy.Publisher("depth_and_pointgoal",
                                                        numpy_msg(Floats),
                                                        queue_size=1)
        print("created habitat_plant succsefully")
Ejemplo n.º 10
0
def test_task_actions():
    config = habitat.get_config(config_paths=CFG_TEST)
    config.defrost()
    config.TASK.POSSIBLE_ACTIONS = config.TASK.POSSIBLE_ACTIONS + ["TELEPORT"]
    config.freeze()

    env = habitat.Env(config=config)
    env.reset()
    env.step(
        action={
            "action": "TELEPORT",
            "action_args": {
                "position": TELEPORT_POSITION,
                "rotation": TELEPORT_ROTATION,
            },
        }
    )
    agent_state = env.sim.get_agent_state()
    assert np.allclose(
        np.array(TELEPORT_POSITION, dtype=np.float32), agent_state.position
    ), "mismatch in position after teleport"
    assert np.allclose(
        np.array(TELEPORT_ROTATION, dtype=np.float32),
        np.array([*agent_state.rotation.imag, agent_state.rotation.real]),
    ), "mismatch in rotation after teleport"
    env.step("TURN_RIGHT")
    env.close()
Ejemplo n.º 11
0
def get_topdown_map(config_paths, map_name):

    config = habitat.get_config(config_paths=config_paths)
    dataset = habitat.make_dataset(id_dataset=config.DATASET.TYPE,
                                   config=config.DATASET)
    env = habitat.Env(config=config, dataset=dataset)
    env.reset()

    square_map_resolution = 5000
    top_down_map = maps.get_topdown_map(env.sim,
                                        map_resolution=(square_map_resolution,
                                                        square_map_resolution))

    # Image containing 0 if occupied, 1 if unoccupied, and 2 if border (if
    # the flag is set)
    top_down_map[np.where(top_down_map == 0)] = 125
    top_down_map[np.where(top_down_map == 1)] = 255
    top_down_map[np.where(top_down_map == 2)] = 0

    imageio.imsave(os.path.join(MAP_DIR, map_name + ".pgm"), top_down_map)

    complete_name = os.path.join(MAP_DIR, map_name + ".yaml")
    f = open(complete_name, "w+")

    f.write("image: " + map_name + ".pgm\n")
    f.write("resolution: " +
            str((COORDINATE_MAX - COORDINATE_MIN) / square_map_resolution) +
            "\n")
    f.write("origin: [" + str(-1) + "," + str(-1) + ", 0.000000]\n")
    f.write("negate: 0\noccupied_thresh: 0.65\nfree_thresh: 0.196")
    f.close()
Ejemplo n.º 12
0
def main():
    # Get the default config node
    config = habitat.get_config(config_paths="configs/tasks/pointnav.yaml")
    config.defrost()

    # Add things to the config to for the measure
    config.task.episode_info_example = habitat.config()
    # The type field is used to look-up the measure in the registry.
    # By default, the things are registered with the class name
    config.TASK.EPISODE_INFO_EXAMPLE.TYPE = "EpisodeInfoExample"
    config.TASK.EPISODE_INFO_EXAMPLE.VALUE = 5
    # Add the measure to the list of measures in use
    config.TASK.MEASUREMENTS.append("EPISODE_INFO_EXAMPLE")

    # Now define the config for the sensor
    config.TASK.AGENT_POSITION_SENSOR = habitat.Config()
    # Use the custom name
    config.TASK.AGENT_POSITION_SENSOR.TYPE = "my_supercool_sensor"
    config.TASK.AGENT_POSITION_SENSOR.ANSWER_TO_LIFE = 42
    # Add the sensor to the list of sensors in use
    config.TASK.SENSORS.append("AGENT_POSITION_SENSOR")
    config.freeze()

    with habitat.Env(config=config) as env:
        print(env.reset()["agent_position"])
        print(env.get_metrics()["episode_info"])
        print(env.step("MOVE_FORWARD")["agent_position"])
        print(env.get_metrics()["episode_info"])
Ejemplo n.º 13
0
def main():
    habitat.SimulatorActions.extend_action_space("NOISY_LEFT")
    habitat.SimulatorActions.extend_action_space("NOISY_RIGHT")
    habitat.SimulatorActions.extend_action_space("NOISY_FORWARD")

    config = habitat.get_config(
        config_paths="../habitat-api/configs/tasks/pointnav.yaml")
    config.defrost()
    config.SIMULATOR.ACTION_SPACE_CONFIG = "NoNoisyMove"
    config.DATASET.DATA_PATH = "../habitat-api/" + config.DATASET.DATA_PATH
    config.SIMULATOR.SCENE = '../habitat-api/' + config.SIMULATOR.SCENE
    config.freeze()

    env = habitat.Env(config=config)
    env.reset()
    env.step(habitat.SimulatorActions.NOISY_LEFT)
    env.step(habitat.SimulatorActions.NOISY_RIGHT)
    env.step(habitat.SimulatorActions.NOISY_FORWARD)
    env.close()

    config.defrost()
    config.SIMULATOR.ACTION_SPACE_CONFIG = "NoisyMove"
    config.freeze()

    env = habitat.Env(config=config)
    env.reset()
    env.step(habitat.SimulatorActions.NOISY_LEFT)
    env.step(habitat.SimulatorActions.NOISY_RIGHT)
    env.step(habitat.SimulatorActions.NOISY_FORWARD)
    env.close()
Ejemplo n.º 14
0
    def __init__(self, env_config_file):
        threading.Thread.__init__(self)
        self.env = habitat.Env(config=habitat.get_config(env_config_file))
        # always assume height equals width
        self._sensor_resolution = {
            "RGB": self.env._sim.config["RGB_SENSOR"]["HEIGHT"],
            "DEPTH": self.env._sim.config["DEPTH_SENSOR"]["HEIGHT"],
            "BC_SENSOR": self.env._sim.config["BC_SENSOR"]["HEIGHT"],
        }
        self.env._sim._sim.agents[
            0].move_filter_fn = self.env._sim._sim._step_filter
        self.observations = self.env.reset()

        # add a sphere
        # load some object templates from configuration files
        sphere_template_id = self.env._sim._sim.load_object_configs(
            str("/home/eric/habitat-sim-may-2020/habitat-sim/data/test_assets/objects/sphere"
                ))[0]
        id_sphere = self.env._sim._sim.add_object(sphere_template_id)
        self.env._sim._sim.set_translation(np.array([-2.63, 0.114367, 19.3]),
                                           id_sphere)

        # load and initialize the lobot_merged asset
        locobot_template_id = self.env._sim._sim.load_object_configs(
            "/home/eric/habitat-sim-may-2020/habitat-sim/data/objects/locobot_merged"
        )[0]
        # print("locobot_template_id is " + str(locobot_template_id))
        # add robot object to the scene with the agent/camera SceneNode attached
        self.id_agent_obj = self.env._sim._sim.add_object(
            locobot_template_id, self.env._sim._sim.agents[0].scene_node)
        # print("id of agent object is " + str(self.id_agent_obj))
        # set the agent's body to dynamic
        self.env._sim._sim.set_object_motion_type(
            hsim.physics.MotionType.DYNAMIC, self.id_agent_obj)

        self.env._sim._sim.agents[0].state.velocity = np.float32([0, 0, 0])
        self.env._sim._sim.agents[0].state.angular_velocity = np.float32(
            [0, 0, 0])
        self.vel_control = self.env._sim._sim.get_object_velocity_control(
            self.id_agent_obj)
        self.env._sim._sim.set_translation(
            np.array([-1.7927, 0.114367, 19.1552]), self.id_agent_obj)

        self._pub_rgb = rospy.Publisher("~rgb",
                                        numpy_msg(Floats),
                                        queue_size=1)
        self._pub_depth = rospy.Publisher("~depth",
                                          numpy_msg(Floats),
                                          queue_size=1)

        # additional RGB sensor I configured
        self._pub_bc_sensor = rospy.Publisher("~bc_sensor",
                                              numpy_msg(Floats),
                                              queue_size=1)

        self._pub_depth_and_pointgoal = rospy.Publisher("depth_and_pointgoal",
                                                        numpy_msg(Floats),
                                                        queue_size=1)
        print("created habitat_plant succsefully")
Ejemplo n.º 15
0
def get_config(training: bool = False,
               top_down_map: bool = False,
               max_steps: Optional[Union[int, float]] = None,
               task: str = 'pointnav',
               train_dataset: str = 'habitat_test',
               train_split: str = 'train',
               eval_dataset: str = 'habitat_test',
               eval_split: str = 'val',
               gpu_id: int = 0,
               image_key: str = 'rgb',
               goal_key: str = 'pointgoal_with_gps_compass',
               depth_key: Optional[str] = None,
               reward_function: RewardFunction = gin.REQUIRED,
               eval_episodes_per_scene: int = 3) -> Dict[str, Any]:
    mode = 'train' if training else 'eval'
    dataset = train_dataset if training else eval_dataset
    split = train_split if training else eval_split
    opts = ['SIMULATOR.HABITAT_SIM_V0.GPU_DEVICE_ID', gpu_id]
    if max_steps:
        opts += ['ENVIRONMENT.MAX_EPISODE_STEPS', int(max_steps)]
    opts += ['DATASET.SPLIT', split]
    if not training:
        opts += ['ENVIRONMENT.ITERATOR_OPTIONS.SHUFFLE', False]
        opts += [
            'ENVIRONMENT.ITERATOR_OPTIONS.MAX_SCENE_REPEAT_EPISODES',
            eval_episodes_per_scene
        ]
    if not task.endswith('.yaml'):
        task = f'{get_config_dir()}/habitat/tasks/{task}.yaml'
    if not dataset.endswith('.yaml'):
        dataset = f'{get_config_dir()}/habitat/datasets/{dataset}.yaml'
    task_file = Path(wandb.run.dir) / 'task.yaml'
    dataset_file = Path(wandb.run.dir) / f'{mode}_dataset.yaml'
    copyfile(task, task_file)
    copyfile(dataset, dataset_file)
    wandb.save(str(task_file))
    wandb.save(str(dataset_file))
    if not HabitatSimActions.has_action('TURN_ANGLE'):
        HabitatSimActions.extend_action_space('TURN_ANGLE')
    config = habitat.get_config([task, dataset], opts)
    config.defrost()
    config.TASK.SUCCESS = habitat.Config()
    config.TASK.SUCCESS.TYPE = 'Success'
    config.TASK.SUCCESS.SUCCESS_DISTANCE = config.TASK.SUCCESS_DISTANCE
    config.TASK.MEASUREMENTS.append('SUCCESS')
    config.TASK.ACTIONS.TURN_ANGLE = habitat.Config()
    config.TASK.ACTIONS.TURN_ANGLE.TYPE = 'TurnAngleAction'
    config.TASK.POSSIBLE_ACTIONS = ['STOP', 'MOVE_FORWARD', 'TURN_ANGLE']
    if top_down_map and 'TOP_DOWN_MAP' not in config.TASK.MEASUREMENTS:
        # Top-down map is expensive to compute, so we only enable it when needed.
        config.TASK.MEASUREMENTS.append('TOP_DOWN_MAP')
    config.freeze()
    return {
        'config': config,
        'image_key': image_key,
        'goal_key': goal_key,
        'depth_key': depth_key,
        'reward_function': reward_function
    }
Ejemplo n.º 16
0
def agent_demo():
    config = habitat.get_config(
        "habitat/habitat-api/configs/tasks/pointnav.yaml")
    config.defrost()
    config.DATASET.DATA_PATH = (
        "habitat/habitat-api/data/datasets/pointnav/gibson/v1/train/train.json.gz"
    )
    config.DATASET.SCENES_DIR = "habitat/habitat-api/data/scene_datasets/"
    config.SIMULATOR.HABITAT_SIM_V0.GPU_DEVICE_ID = 0
    config.SIMULATOR.TURN_ANGLE = 45
    config.freeze()
    env = habitat.Env(config=config)

    print("Environment creation successful")
    observations = env.reset()
    cv2.imshow("RGB", transform_rgb_bgr(observations["rgb"]))

    print("Agent stepping around inside environment.")

    count_steps = 0
    while not env.episode_over:
        keystroke = cv2.waitKey(0)

        if keystroke == ord(FORWARD_KEY):
            action = 1
            print("action: FORWARD")
        elif keystroke == ord(LEFT_KEY):
            action = 2
            print("action: LEFT")
        elif keystroke == ord(RIGHT_KEY):
            action = 3
            print("action: RIGHT")
        elif keystroke == ord(FINISH):
            action = 0
            print("action: FINISH")
        else:
            print("INVALID KEY")
            continue

        observations = env.step(action)
        count_steps += 1

        print("Position:", env.sim.get_agent_state().position)
        print("Quaternions:", env.sim.get_agent_state().rotation)
        quat = Quaternion(env.sim.get_agent_state().rotation.components)
        print(quat.radians)
        cv2.imshow("RGB", transform_rgb_bgr(observations["rgb"]))

    print("Episode finished after {} steps.".format(count_steps))

    if action == habitat.SimulatorActions.STOP and observations["pointgoal"][
            0] < 0.2:
        print("you successfully navigated to destination point")
    else:
        print("your navigation was unsuccessful")
Ejemplo n.º 17
0
def reference_path_example(mode):
    """
    Saves a video of a shortest path follower agent navigating from a start
    position to a goal. Agent follows the ground truth reference path by
    navigating to intermediate viewpoints en route to goal.
    Args:
        mode: 'geodesic_path' or 'greedy'
    """
    config = habitat.get_config(
        config_paths="configs/test/habitat_r2r_vln_test.yaml")
    config.defrost()
    config.TASK.MEASUREMENTS.append("TOP_DOWN_MAP")
    config.TASK.SENSORS.append("HEADING_SENSOR")
    config.freeze()
    with SimpleRLEnv(config=config) as env:
        follower = ShortestPathFollower(env.habitat_env.sim,
                                        goal_radius=0.5,
                                        return_one_hot=False)
        follower.mode = mode
        print("Environment creation successful")

        for episode in range(3):
            env.reset()

            print(env.habitat_env.current_episode)
            episode_id = env.habitat_env.current_episode.episode_id
            print(
                f"Agent stepping around inside environment. Episode id: {episode_id}"
            )

            dirname = os.path.join(IMAGE_DIR, "vln_reference_path_example",
                                   mode, "%02d" % episode)
            if os.path.exists(dirname):
                shutil.rmtree(dirname)
            os.makedirs(dirname)

            images = []
            steps = 0
            reference_path = env.habitat_env.current_episode.reference_path + [
                env.habitat_env.current_episode.goals[0].position
            ]
            for point in reference_path:
                done = False
                while not done:
                    best_action = follower.get_next_action(point)
                    print(best_action)
                    if best_action == None or best_action == 0:
                        break
                    observations, reward, done, info = env.step(best_action)
                    save_map(observations, info, images)
                    steps += 1

            print(f"Navigated to goal in {steps} steps.")
            images_to_video(images, dirname, str(episode_id))
            images = []
Ejemplo n.º 18
0
def example():
    # Note: Use with for the example testing, doesn't need to be like this on the README
    config = habitat.get_config(
        "habitat-lab/configs/tasks/objectnav_mp3d.yaml")
    with habitat.Env(config=config) as env:
        print("Environment creation successful")
        observations = env.reset()  # noqa: F841
        print(observations)
        while not env.episode_over:
            observations = env.step(env.action_space.sample())  # noqa: F841
        print("Episode finished")
Ejemplo n.º 19
0
def test_demo_notebook():
    config = habitat.get_config("configs/tasks/pointnav_mp3d.yaml")
    config.defrost()
    config.DATASET.SPLIT = "val"

    if not PointNavDatasetV1.check_config_paths_exist(config.DATASET):
        pytest.skip(
            "Please download the Matterport3D PointNav val dataset and Matterport3D val scenes"
        )
    else:
        pytest.main(["--nbval-lax", "notebooks/habitat-api-demo.ipynb"])
Ejemplo n.º 20
0
def example():
    env = habitat.Env(config=habitat.get_config("configs/tasks/vln_r2r.yaml"))

    print("Environment creation successful")
    observations = env.reset()

    print("Agent stepping around inside environment.")
    count_steps = 0
    while not env.episode_over:
        observations = env.step(env.action_space.sample())
        count_steps += 1
    print("Episode finished after {} steps.".format(count_steps))
Ejemplo n.º 21
0
def test_demo_notebook():
    config = habitat.get_config("configs/tasks/pointnav_rgbd.yaml")
    config.defrost()
    config.DATASET.SPLIT = "val"

    if not PointNavDatasetV1.check_config_paths_exist(config.DATASET):
        pytest.skip("Please download the habitat test scenes")
    else:
        pytest.main([
            "--nbval-lax",
            "notebooks/relative_camera_views_transform_and_warping_demo.ipynb",
        ])
Ejemplo n.º 22
0
def example_get_topdown_map():
    config = habitat.get_config(config_paths="configs/tasks/pointnav.yaml")
    dataset = habitat.make_dataset(id_dataset=config.DATASET.TYPE,
                                   config=config.DATASET)
    with habitat.Env(config=config, dataset=dataset) as env:
        env.reset()
        top_down_map = maps.get_topdown_map_from_sim(env.sim,
                                                     map_resolution=1024)
        recolor_map = np.array([[255, 255, 255], [128, 128, 128], [0, 0, 0]],
                               dtype=np.uint8)
        top_down_map = recolor_map[top_down_map]
        imageio.imsave(os.path.join(IMAGE_DIR, "top_down_map.png"),
                       top_down_map)
Ejemplo n.º 23
0
def example():
    # Note: Use with for the example testing, doesn't need to be like this on the README

    with habitat.Env(
            config=habitat.get_config("configs/tasks/pointnav.yaml")) as env:
        print("Environment creation successful")
        observations = env.reset()  # noqa: F841

        print("Agent stepping around inside environment.")
        count_steps = 0
        while not env.episode_over:
            observations = env.step(env.action_space.sample())  # noqa: F841
            count_steps += 1
        print("Episode finished after {} steps.".format(count_steps))
Ejemplo n.º 24
0
def example():
	trajectory_directory = 'trajectories/Adrian/'
	config = habitat.get_config(config_file='datasets/pointnav/gibson.yaml')
	config.defrost()
	config.DATASET.SPLIT = 'train_mini'
	config.freeze()
	env = habitat.Env(config=config)
	
	action_list = []
	position_list = []
	
	print("Environment creation successful")
	observations = env.reset()
	position_list.append(env.sim.get_agent_state().position)
	fig = plt.figure(frameon=False)
	ax = plt.Axes(fig, [0., 0., 1., 1.])
	ax.set_axis_off()
	fig.add_axes(ax)
	ax.imshow(observations["rgb"])
	plt.show(block=False)
	fig.savefig(trajectory_directory+'images/'+str(0)+'.png')
	#cv2.imshow("RGB", transform_rgb_bgr(observations["rgb"]))

	print("Agent stepping around inside environment.")
	
	count_steps = 0
	while not env.episode_over:
		input_text = input("Enter the action ... ")
		if input_text == FORWARD_KEY:
			action = 0
		elif input_text == LEFT_KEY:
			action = 1
		elif input_text == RIGHT_KEY:
			action = 2
		elif input_text == FINISH_KEY:
			action = 3
		else:
			print('Invalid action')
			continue
		action_list.append(action)
		observations = env.step(action)
		position_list.append(env.sim.get_agent_state().position)
		count_steps += 1
		ax.imshow(observations["rgb"])
		plt.show(block=False)
		fig.savefig(trajectory_directory+'/images/'+str(count_steps)+'.png')
		#cv2.imshow("RGB", transform_rgb_bgr(observations["rgb"]))
	np.array(action_list).dump(open(trajectory_directory+'actions.npy', 'wb'))
	np.array(position_list).dump(open(trajectory_directory+'positions.npy', 'wb'))
	print("Episode finished after {} steps.".format(count_steps))
    def __init__(self,
                 forward_step,
                 angle_step,
                 is_blind=False,
                 sensors=["RGB_SENSOR"]):
        config = habitat.get_config()

        log_mesg("env: forward_step: {}, angle_step: {}".format(
            forward_step, angle_step))

        config.defrost()
        config.PYROBOT.SENSORS = sensors
        config.PYROBOT.RGB_SENSOR.WIDTH = 256
        config.PYROBOT.RGB_SENSOR.HEIGHT = 256
        config.PYROBOT.DEPTH_SENSOR.WIDTH = 256
        config.PYROBOT.DEPTH_SENSOR.HEIGHT = 256
        config.PYROBOT.DEPTH_SENSOR.MAX_DEPTH = 10
        config.PYROBOT.DEPTH_SENSOR.MIN_DEPTH = 0.3
        config.freeze()

        self._reality = make_sim(id_sim="PyRobot-v0", config=config.PYROBOT)
        self._angle = (angle_step / 180) * np.pi
        self._pointgoal_key = "pointgoal_with_gps_compass"
        self.is_blind = is_blind

        if not is_blind:
            sensors_dict = {
                **self._reality.sensor_suite.observation_spaces.spaces
            }
        else:
            sensors_dict = {}

        sensors_dict[self._pointgoal_key] = spaces.Box(
            low=np.finfo(np.float32).min,
            high=np.finfo(np.float32).max,
            shape=(2, ),
            dtype=np.float32,
        )
        self.observation_space = SpaceDict(sensors_dict)

        self.action_space = spaces.Discrete(4)

        self._actions = {
            "forward": [forward_step, 0, 0],
            "left": [0, 0, self._angle],
            "right": [0, 0, -self._angle],
            "stop": [0, 0, 0],
        }
        self._process = None
        self._last_time = -1
Ejemplo n.º 26
0
def main():
    config = habitat.get_config(config_paths="/home/rene/catkin_ws/src/habitat-api/configs/tasks/pointnav_rgbd.yaml")

    config.defrost()

    # Add things to the config to for the measure
    config.TASK.EPISODE_INFO = habitat.Config()
    # The type field is used to look-up the measure in the registry.
    # By default, the things are registered with the class name
    config.TASK.EPISODE_INFO.TYPE = "EpisodeInfo"
    config.TASK.EPISODE_INFO.VALUE = 5

    # Now define the config for the sensor
    config.TASK.AGENT_POSITION_SENSOR = habitat.Config()
    # Use the custom name
    config.TASK.AGENT_POSITION_SENSOR.TYPE = "my_supercool_sensor"
    # Add the sensor to the list of sensors in use
    config.TASK.SENSORS.append("AGENT_POSITION_SENSOR")


    # Now define the config for the sensor
    config.TASK.SEMANTIC_SEGMENTATION_MASK_SENSOR = habitat.Config()
    # Use the custom name
    config.TASK.SEMANTIC_SEGMENTATION_MASK_SENSOR.TYPE = "semantic_segmentation_mask"
    # Add the sensor to the list of sensors in use
    config.TASK.SENSORS.append("SEMANTIC_SEGMENTATION_MASK_SENSOR")

    config.freeze()

    my_env = sim_env(config)
    # start the thread that publishes sensor readings
    my_env.start()

    rospy.Subscriber("/cmd_vel", Twist, callback, (my_env), queue_size=1)
    # define a list capturing how long it took
    # to update agent orientation for past 3 instances
    # TODO modify dt_list to depend on r1
    dt_list = [0.009, 0.009, 0.009]
    while not rospy.is_shutdown():

        start_time = time.time()
        # cv2.imshow("bc_sensor", my_env.observations['bc_sensor'])
        # cv2.waitKey(100)
        # time.sleep(0.1)
        my_env.update_orientation()

        dt_list.insert(0, time.time() - start_time)
        dt_list.pop()
        my_env.set_dt(sum(dt_list) / len(dt_list))
Ejemplo n.º 27
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--evaluation", type=str, required=True, choices=["local", "remote"])
    args = parser.parse_args()

    config_paths = os.environ["CHALLENGE_CONFIG_FILE"]
    config = habitat.get_config(config_paths)
    agent = RandomAgent(task_config=config)

    if args.evaluation == "local":
        challenge = habitat.Challenge(eval_remote=False)
    else:
        challenge = habitat.Challenge(eval_remote=True)

    challenge.submit(agent)
Ejemplo n.º 28
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--task-config",
                        type=str,
                        default="tasks/pointnav.yaml")
    parser.add_argument("--agent_class", type=str, default="GoalFollower")
    args = parser.parse_args()

    agent = get_agent_cls(args.agent_class)(habitat.get_config(
        args.task_config))
    benchmark = habitat.Benchmark(args.task_config)
    metrics = benchmark.evaluate(agent)

    for k, v in metrics.items():
        habitat.logger.info("{}: {:.3f}".format(k, v))
Ejemplo n.º 29
0
    def __init__(self):
        super().__init__()
        self.TRAIN_SCENES = (
            "habitat/habitat-api/data/datasets/pointnav/gibson/v1/train/train.json.gz"
        )
        self.VALID_SCENES = (
            "habitat/habitat-api/data/datasets/pointnav/gibson/v1/val/val.json.gz"
        )
        self.TEST_SCENES = (
            "habitat/habitat-api/data/datasets/pointnav/gibson/v1/test/test.json.gz"
        )

        self.NUM_PROCESSES = 80
        self.CONFIG = habitat.get_config("configs/gibson.yaml")
        self.CONFIG.defrost()
        self.CONFIG.NUM_PROCESSES = self.NUM_PROCESSES
        self.CONFIG.SIMULATOR_GPU_IDS = [0, 1, 2, 3, 4, 5, 6, 7]
        self.CONFIG.DATASET.SCENES_DIR = "habitat/habitat-api/data/scene_datasets/"
        self.CONFIG.DATASET.POINTNAVV1.CONTENT_SCENES = ["*"]
        self.CONFIG.DATASET.DATA_PATH = self.TRAIN_SCENES
        self.CONFIG.SIMULATOR.AGENT_0.SENSORS = ["RGB_SENSOR"]
        self.CONFIG.SIMULATOR.RGB_SENSOR.WIDTH = self.CAMERA_WIDTH
        self.CONFIG.SIMULATOR.RGB_SENSOR.HEIGHT = self.CAMERA_HEIGHT
        self.CONFIG.SIMULATOR.DEPTH_SENSOR.WIDTH = self.CAMERA_WIDTH
        self.CONFIG.SIMULATOR.DEPTH_SENSOR.HEIGHT = self.CAMERA_HEIGHT
        self.CONFIG.SIMULATOR.TURN_ANGLE = self.ROTATION_DEGREES
        self.CONFIG.SIMULATOR.FORWARD_STEP_SIZE = self.STEP_SIZE
        self.CONFIG.ENVIRONMENT.MAX_EPISODE_STEPS = self.MAX_STEPS

        self.CONFIG.TASK.TYPE = "Nav-v0"
        self.CONFIG.TASK.SUCCESS_DISTANCE = self.DISTANCE_TO_GOAL
        self.CONFIG.TASK.SENSORS = ["POINTGOAL_WITH_GPS_COMPASS_SENSOR"]
        self.CONFIG.TASK.POINTGOAL_WITH_GPS_COMPASS_SENSOR.GOAL_FORMAT = "POLAR"
        self.CONFIG.TASK.POINTGOAL_WITH_GPS_COMPASS_SENSOR.DIMENSIONALITY = 2
        self.CONFIG.TASK.GOAL_SENSOR_UUID = "pointgoal_with_gps_compass"
        self.CONFIG.TASK.MEASUREMENTS = ["DISTANCE_TO_GOAL", "SPL"]
        self.CONFIG.TASK.SPL.TYPE = "SPL"
        self.CONFIG.TASK.SPL.SUCCESS_DISTANCE = self.DISTANCE_TO_GOAL

        self.CONFIG.MODE = "train"

        self.TRAIN_GPUS = [0, 1, 2, 3, 4, 5, 6, 7]
        self.VALIDATION_GPUS = [7]
        self.TESTING_GPUS = [7]

        self.TRAIN_CONFIGS = None
        self.TEST_CONFIGS = None
        self.SENSORS = None
def test_demo_notebook():
    config = habitat.get_config("configs/tasks/pointnav_mp3d.yaml")
    config.defrost()
    config.DATASET.SPLIT = "val"

    if not PointNavDatasetV1.check_config_paths_exist(config.DATASET):
        pytest.skip(
            "Please download the Matterport3D PointNav val dataset and Matterport3D val scenes"
        )
    else:
        pytest.main(["--nbval-lax", "notebooks/habitat-api-demo.ipynb"])

        # NB: Force a gc collect run as it can take a little bit for
        # the cleanup to happen after the notebook and we get
        # a double context crash!
        gc.collect()