本博客旨在提供开始使用AI2-THOR的基本入门示例。
1. MoveAhead
一个简单的示例,将智能体向前移动一步并返回相应的图像和元数据。
from ai2thor.controller import Controller
# Kitchens: FloorPlan1 - FloorPlan30
# Living rooms: FloorPlan201 - FloorPlan230
# Bedrooms: FloorPlan301 - FloorPlan330
# Bathrooms: FloorPLan401 - FloorPlan430
controller = Controller(scene='FloorPlan28', gridSize=0.25)
event = controller.step(action='MoveAhead')
# Numpy Array - shape (width, height, channels), channels are in RGB order
event.frame
# Numpy Array in BGR order suitable for use with OpenCV
event.cv2image
# current metadata dictionary that includes the state of the scene
event.metadata
# shuts down the controller
controller.stop()
2. Context Managers
初始化controller的另一种方法是使用上下文管理器。这里,前面的MoveAhead示例可以写成:
from ai2thor.controller import Controller
with Controller(scene='FloorPlan28', gridSize=0.25) as c:
event = c.step(action='MoveAhead')
event.frame
event.cv2image
event.metadata
如果with命令内部存在错误或with命令内部的所有内容都已执行,则controller将立即停止。
3. Object interaction
我们的目标是拿起杯子,然后打开微波炉,然后将杯子放入微波炉中。 要拾取物体,智能体必须首先导航到存在可拾取/可见物体的区域。 通常,应通过一系列MoveAhead,RotateLeft,RotateRight命令完成此操作。 在这里,我们将直接移动到存在杯子的已知位置。
from ai2thor.controller import Controller
controller = Controller(scene='FloorPlan28', gridSize=0.25)
# change starting loca