Hub 文档
在 Hugging Face Hub 上使用 ML-Agents
加入 Hugging Face 社区
并获得增强的文档体验
开始使用
在 Hugging Face 使用 ML-Agents
ml-agents
是一个开源工具包,它使使用 Unity 制作的游戏和模拟能够作为训练智能代理的环境。
探索 Hub 中的 ML-Agents
您可以通过在模型页面左侧进行筛选来查找 ml-agents
模型。
Hub 上的所有模型都附带了有用的功能
- 一个自动生成的模型卡片,包含描述、训练配置等信息。
- 有助于发现的元数据标签。
- Tensorboard 摘要文件用于可视化训练指标。
- 一个指向 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
: 下载模型的路径。
可视化代理游戏
您可以直接在浏览器中轻松观看任何模型进行游戏
- 转到您的模型仓库。
- 在
Watch Your Agent Play
部分,单击链接。 - 在演示中,在步骤 1 中,选择您的模型仓库,即模型 ID。
- 在步骤 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 仓库的名称。格式为<您的 huggingface 用户名>/<仓库名称>
。--commit-message
.