Azure ML - 在环境中安装 GitHub 包

问题描述 投票:0回答:1

我是 Azure ML 的新手,正在创建自己的 Python 环境。

我正在尝试使用 Azure ML 运行我的 detectorron2(实例分段)代码。为此,我需要从 GitHub 安装他们的 detectorron2 包。我的代码基于 Facebook 研究团队提供的 Google Colab 示例。在这里,在笔记本中,我们只需做:

!git clone 'https://github.com/facebookresearch/detectron2'
dist = distutils.core.run_setup("./detectron2/setup.py")
!python -m pip install {' '.join([f"'{x}'" for x in dist.install_requires])}
sys.path.insert(0, os.path.abspath('./detectron2'))

!python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'

然后

import detectron2

现在,我想在 AzureML 中运行我的 detector2 代码。为此,我遵循了这个教程。我只是将 .ipynb detectorron2 文件转换为 .py,创建了工作区、资源,使用了 Azure 的 PyTorch 策划环境之一,然后简单地提交了作业。在日志中,我了解到诸如

!pip
!git
之类的行会返回语法错误。相反,我了解到应该创建一个包含所需包的环境(?)。

现在我发现这很困难。我没有使用他们策划的环境之一,而是创建了一个新环境。在每个环境的上下文窗格中,用户可以编辑 Docker 文件和要求。我尝试了几件事。在需求中,我列出了所有必需的包。包括

detectron2
git+https://github.com/facebookresearch/detectron2.git
。我尝试使用 detectorron2 提供的 one 来编辑 Docker 文件。我尝试了基于 detectron2 安装说明的变体(例如 Docker 文件中的
RUN pip install git+https://github.com/facebookresearch/detectron2.git
)。

但是,每当我提交并运行代码时,我都会在 Azure 日志中收到

ModuleNotFoundError: No module named 'detectron2.utils'; 'detectron2' is not a package
错误。

在 Azure ML 中安装 GitHub 包(例如 detectorron2)的正确方法是什么?我做错了什么?

python docker environment azure-machine-learning-service git-clone
1个回答
0
投票

尝试创建自定义环境(您也可以使用 CLI 或 SDK),如以下链接所示(通过 GUI) - https://learn.microsoft.com/en-us/azure/machine-learning/how-to- azure-container-for-pytorch-environment?view=azureml-api-2

我在 dockerfile 中添加了以下内容(除了使用策划的环境

FROM
声明)

pip install azureml-mlflow
pip install torch
python -m pip install "git+https://github.com/facebookresearch/detectron2.git"

创建环境需要一些时间 - 您应该看到构建状态为“成功”。 一旦环境构建并准备就绪 - 您应该能够像往常一样在作业/脚本中使用它。 例如

from azureml.core.environment import CondaDependencies
mycustomenv = Environment(name="test-env-detectron")
.
.
.
# use variable mycustomenv as needed 

GUI 的屏幕截图显示了我尝试构建的环境 -

© www.soinside.com 2019 - 2024. All rights reserved.