当前位置: 首页 > news >正文

AI2THOR 2.1.0使用教程

一、安装和入门

1.1 AI2-THOR使用要求

  • 操作系统: Mac OS X 10.9+, Ubuntu 14.04+
  • 显卡:DX9(着色器型号 3.0)或 DX11,功能级别为 9.3。
  • CPU:支持 SSE2 指令集。
  • Python 2.7 或 Python 3.5+
  • Linux 用户:启用了 GLX 模块的 X 服务器

1.2 使用 pip 安装

  您可以使用 pip 安装 AI2-THOR。创建 Python 2.7/3.5/3.6 虚拟环境,

conda create -n ai2thor_env python=3.6

  然后进入虚拟环境

conda activate ai2thor_env

  然后安装ai2thor

pip install ai2thor

  在运行以下代码之前,请确保正在运行带有 OpenGL 的 X 服务器,并且已为您的显卡安装了 OpenGL 扩展。

import ai2thor.controller
controller = ai2thor.controller.Controller()
controller.start()

  第一次使用控制器时,包含 3D 场景的游戏环境将被下载到 $HOME/.ai2thor。二进制文件的大小约为 500MB。

二、概念

  • Agent: 胶囊形状的实体,可在场景中导航并与物体互动。

  • Scene: AI2-THOR 中的场景代表一个虚拟房间,代理可以在其中导航并与之互动。有 4 个场景类别,每个类别有 30 个独特的场景: 厨房、起居室、卧室、浴室。

  • Action: 让代理在场景中执行的离散命令(例如,向前移动、向右旋转、拾取对象)

  • Sim Object: 可以与代理互动的对象。根据 “对象类型”(Object Type)所定义的 “承受能力”(affordanced),"对象 "具有一系列交互功能。

  • Object Visibility: 当一个对象满足三个条件时,它就被认为是可见的: 它必须位于摄像机的视口内,必须与 Agent 的中心距离在一个阈值范围内(默认值:1.5 米),并且从摄像机发射的光线必须在不首先击中其他障碍物的情况下击中该对象。请注意,图像中渲染的物体并不总是对 Agent 可见。例如,1.5 米阈值之外的物体可以在图像中看到,但对 Agent 来说将被报告为不可见。

  • Object Interactability: 如果一个物体被标记为可见,并且没有任何其他物体遮挡,那么这个物体就是可交互的。大多数对象只要也是可见的,就是可交互的,但有些对象是透明的,这可能会导致对象被报告为透过它们是可见的。例如,玻璃淋浴门后面有一个海绵物体。玻璃门将被标记为 "可见 "和 “可交互”,但海绵仅为 “可见”。如果试图与海绵进行交互,就会出现错误,因为无法通过玻璃门接触到海绵,只能看到海绵。

  • Receptacle: 一种可以容纳另一个物体的物体。例如 桌面、杯子、沙发、床、桌子、碗等。有些容器无法在场景中移动,它们大多是无法移动的大型物体(台面、水槽等)。有些收纳盒还可以打开和关闭(微波炉、橱柜、抽屉等),而有些收纳盒还可以被代理拿起来移动(盘子、碗、盒子等)。

三、示例

  我们提供了一些示例来展示如何使用 AI2-THOR。

3.1 简单示例

  一个简单的示例,将代理向前移动一步并返回相应的图像和元数据。

import ai2thor.controller
controller = ai2thor.controller.Controller()
controller.start()# Kitchens: FloorPlan1 - FloorPlan30
# Living rooms: FloorPlan201 - FloorPlan230
# Bedrooms: FloorPlan301 - FloorPlan330
# Bathrooms: FloorPLan401 - FloorPlan430controller.reset('FloorPlan28')
controller.step(dict(action='Initialize', gridSize=0.25))event = controller.step(dict(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

3.2 调用复杂操作的示例

  拿起杯子, 打开微波炉, 把杯子放在微波炉里

  要拾取对象,代理必须首先导航到有可拾取/可见对象的区域。通常,它应该通过一系列 MoveAhead、RotateLeft、RotateRight 命令来完成。在这里,我们直接传送到一个已知的位置,那里有一个杯子。

import ai2thor.controller
controller = ai2thor.controller.Controller()
controller.start()controller.reset('FloorPlan28')
controller.step(dict(action='Initialize', gridSize=0.25))controller.step(dict(action='Teleport', x=-2.5, y=0.900998235, z=-3.0))
controller.step(dict(action='LookDown'))
event = controller.step(dict(action='Rotate', rotation=180))
# In FloorPlan28, the agent should now be looking at a mug
for o in event.metadata['objects']:if o['visible'] and o['pickupable'] and o['objectType'] == 'Mug':event = controller.step(dict(action='PickupObject', objectId=o['objectId']), raise_for_failure=True)mug_object_id = o['objectId']break# the agent now has the Mug in its inventory
# to put it into the Microwave, we need to open the microwave firstevent = controller.step(dict(action='LookUp'))
event = controller.step(dict(action='RotateLeft'))event = controller.step(dict(action='MoveLeft'))
event = controller.step(dict(action='MoveLeft'))
event = controller.step(dict(action='MoveLeft'))
event = controller.step(dict(action='MoveLeft'))event = controller.step(dict(action='MoveAhead'))
event = controller.step(dict(action='MoveAhead'))
event = controller.step(dict(action='MoveAhead'))
event = controller.step(dict(action='MoveAhead'))
event = controller.step(dict(action='MoveAhead'))
event = controller.step(dict(action='MoveAhead'))for o in event.metadata['objects']:if o['visible'] and o['openable'] and o['objectType'] == 'Microwave':event = controller.step(dict(action='OpenObject', objectId=o['objectId']), raise_for_failure=True)receptacle_object_id = o['objectId']breakevent = controller.step(dict(action='PutObject',receptacleObjectId=receptacle_object_id,objectId=mug_object_id), raise_for_failure=True)# close the microwave
event = controller.step(dict(action='CloseObject',objectId=receptacle_object_id), raise_for_failure=True)

3.3 多智能体示例

  此示例说明如何在多代理设置中运行 AI2-THOR。

import ai2thor.controller
controller = ai2thor.controller.Controller()
controller.start()# agentCount specifies the number of agents in a scene
multi_agent_event = controller.step(dict(action='Initialize', gridSize=0.25, agentCount=2))# print out agentIds
for e in mult_agent_event.events:print(e.metadata['agentId'])# move the second agent ahead, agents are 0-indexed
multi_agent_event = controller.step(dict(action='MoveAhead', agentId=1)) 

3.4 多线程示例

  此示例演示如何以多线程方式运行代理的多个实例。

mport threading
import time
import ai2thor.controllerthread_count = 8def run():controller = ai2thor.controller.Controller()controller.start()# 100 is an arbritary numberfor _ in range(100):t_start = time.time()controller.reset('FloorPlan1')controller.step({'action' : 'Initialize', 'gridSize' : 0.25})print('init time', time.time() - t_start)t_start_total = time.time()for _ in range(10):controller.step({'action' : 'MoveAhead'})controller.step({'action' : 'RotateRight'})total_time = time.time() - t_start_totalprint('total time', total_time, 20 / total_time, 'fps')threads = [threading.Thread(target=run) for _ in range(thread_count)]
for t in threads:t.daemon = Truet.start()time.sleep(1)for t in threads:# calling join() in a loop/timeout to allow for Python 2.7# to be interrupted with SIGINTwhile t.isAlive():t.join(1)print('done')

3.5 一个示例结果

在这里插入图片描述

参考文献

[1] https://allenai.github.io/ai2thor-v2.1.0-documentation/installation#

[2] https://ai2thor.allenai.org/

http://www.lryc.cn/news/367656.html

相关文章:

  • 在Nginx中配置php程序环境。
  • !力扣70. 爬楼梯
  • Spring boot+vue前后端分离
  • Python基础总结之列表转字符串
  • 二分【1】二分查找框架 查找指定元素
  • Python 中如何使用 lambda 函数
  • 关于焊点检测(SJ-BIST)模块实现
  • 关于修改Python中pip默认安装路径的终极方法
  • android集成百度文心一言实现对话功能,实战项目讲解,人人都能拥有一款ai应用
  • 事件总线vueEvent
  • 设计模式之观察者模式ObserverPattern(十一)
  • JavaScript 编程语言【 数据类型】日期和时间
  • RabbitMQ简单使用方法,以异步处理日志为例:
  • 二分+模拟,CF1461D - Divide and Summarize
  • C#操作MySQL从入门到精通(16)——使用子查询
  • 【vue实战项目】通用管理系统:图表功能
  • 第99天:权限提升-数据库提权口令获取MYSQLMSSQLOracleMSF
  • Java 环境配置 -- Java 语言的安装、配置、编译与运行
  • 升级最新版openssh-9.7p1及openssl-1.1.1h详细步骤及常见问题总结
  • 学习使用 Frida 过程中出现的问题
  • Java实现简单词法、语法分析器
  • Python实现半双工的实时通信SSE(Server-Sent Events)
  • python中的解包操作(*和**)
  • Lua 时间工具类
  • Qt——Qt网络编程之TCP通信客户端的实现(使用QTcpSocket实现一个TCP客户端例程)
  • Qt信号槽与函数直接调用性能对比
  • Python中的异常处理:try-except-finally详解与自定义异常类
  • vscode软件上安装 Fitten Code插件及使用
  • 人工智能小作业
  • 程序员搞副业一些会用到的工具