Hi my new friend!

habitat-sim和habitat-lab环境搭建

  • Home
  • habitat-sim和habitat-lab环境搭建
Scroll down

说明

承接上文搭建斯坦福大学GibsonEnv环境失败,在本文中重新基于habitat-sim开始搭建环境。

habitat-sim环境搭建

1
2
3
conda create -n habitat python=3.9 cmake=3.14.0
conda activate habitat
conda install habitat-sim withbullet -c conda-forge -c aihabitat

habitat-lab环境搭建

1
2
3
4
git clone --branch stable https://github.com/facebookresearch/habitat-lab.git
cd habitat-lab
pip install -e habitat-lab # install habitat_lab
pip install -e habitat-baselines # install habitat_baselines

在完成环境安装后,可以使用python examples/example.py来测试环境是否安装成功。一定会报错:

1
ValueError: Requested RearrangeDataset config paths 'data/datasets/replica_cad/rearrange/v2/train/rearrange_easy.json.gz' or 'data/replica_cad/' are not downloaded locally. Aborting.

这需要我们下载数据集,下载的是replicaCAD数据集,但是下载方式需要特别注意,需要参考这个地方链接去分开下载数据集,否则数据集不全,需要执行命令:

1
python -m habitat_sim.utils.datasets_download --uids <replica_datasets> --data-path data/

replica_dataset为:

1
2
3
4
5
"replica_cad_dataset",
"hab_fetch",
"ycb",
"rearrange_pick_dataset_v0",
"rearrange_dataset_v2",

但是,在下载的时候还有坑。直接运行命令在下载完解压的时候会出现:

1
Error: unknown shorthand flag: 'f' in -f

这是关于git-lfs的报错,可能与当时的版本有关系,因此完整命令为:

1
python -m habitat_sim.utils.datasets_download --uids <replica_datasets> --data-path data/ --no-prune

安装完成后,可以使用python examples/example.py来测试环境是否安装成功。

相机渲染测试

可运行以下代码,通过WSAD控制相机移动。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import habitat
from habitat.sims.habitat_simulator.actions import HabitatSimActions
import cv2


FORWARD_KEY="w"
LEFT_KEY="a"
RIGHT_KEY="d"
FINISH="f"


def transform_rgb_bgr(image):
return image[:, :, [2, 1, 0]]


def example():
env = habitat.Env(
config=habitat.get_config("benchmark/nav/pointnav/pointnav_habitat_test.yaml")
)

print("Environment creation successful")
observations = env.reset()
print("Destination, distance: {:3f}, theta(radians): {:.2f}".format(
observations["pointgoal_with_gps_compass"][0],
observations["pointgoal_with_gps_compass"][1]))
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 = HabitatSimActions.move_forward
print("action: FORWARD")
elif keystroke == ord(LEFT_KEY):
action = HabitatSimActions.turn_left
print("action: LEFT")
elif keystroke == ord(RIGHT_KEY):
action = HabitatSimActions.turn_right
print("action: RIGHT")
elif keystroke == ord(FINISH):
action = HabitatSimActions.stop
print("action: FINISH")
else:
print("INVALID KEY")
continue

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

print("Destination, distance: {:3f}, theta(radians): {:.2f}".format(
observations["pointgoal_with_gps_compass"][0],
observations["pointgoal_with_gps_compass"][1]))
cv2.imshow("RGB", transform_rgb_bgr(observations["rgb"]))

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

if (
action == HabitatSimActions.stop
and observations["pointgoal_with_gps_compass"][0] < 0.2
):
print("you successfully navigated to destination point")
else:
print("your navigation was unsuccessful")


if __name__ == "__main__":
example()

gibson数据集下载:

我是学生,给我钱

其他文章
目录导航 置顶
  1. 1. 说明
  2. 2. habitat-sim环境搭建
  3. 3. habitat-lab环境搭建
  4. 4. 相机渲染测试
请输入关键词进行搜索