Hub documentation

在 Hugging Face 上使用 ML-Agents

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

在 Hugging Face 上使用 ML-Agents

ml-agents 是一个开源工具包,它使使用 Unity 制作的游戏和模拟能够作为训练智能代理的环境。

在 Hub 中探索 ML-Agents

您可以在模型页面左侧进行筛选,以查找ml-agents模型。

Hub 上的所有模型都附带了实用功能:

  1. 自动生成的模型卡片,包含描述、训练配置等更多内容。
  2. 有助于提高可发现性的元数据标签。
  3. 用于可视化训练指标的 Tensorboard 摘要文件。
  4. 一个指向 Spaces 网页演示的链接,您可以在浏览器中可视化您的智能体进行游戏。

安装该库

要安装 ml-agents 库,您需要克隆该仓库:

# Clone the repository
git clone https://github.com/Unity-Technologies/ml-agents

# Go inside the repository and install the package
cd ml-agents
pip3 install -e ./ml-agents-envs
pip3 install -e ./ml-agents

使用现有模型

您可以使用 mlagents-load-from-hf 直接从 Hub 下载模型。

mlagents-load-from-hf --repo-id="ThomasSimonini/MLAgents-Pyramids" --local-dir="./downloads"

您需要定义两个参数:

  • --repo-id:要下载的 Hugging Face 仓库的名称。
  • --local-dir:下载模型的路径。

可视化智能体进行游戏

您可以轻松地在浏览器中直接观看任何模型的运行效果:

  1. 前往您的模型仓库。
  2. 在 Watch Your Agent Play 部分,点击该链接。
  3. 在演示中,第 1 步,选择您的模型仓库,即模型 id。
  4. 在步骤 2 中,选择要重放的目标模型。

共享您的模型

您可以使用 mlagents-push-to-hf 轻松上传您的模型:

mlagents-push-to-hf --run-id="First Training" --local-dir="results/First Training" --repo-id="ThomasSimonini/MLAgents-Pyramids" --commit-message="Pyramids"

您需要定义四个参数:

  • --run-id:训练运行 ID 的名称。
  • --local-dir:模型保存的位置。
  • --repo-id:要创建或更新的 Hugging Face 仓库的名称。格式为 <your huggingface username>/<the repo name>。
  • --commit-message.

其他资源

Update on GitHub