在 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 仓库名称。格式为<your huggingface username>/<the repo name>。--commit-message:提交消息。