问题描述
我正在尝试将Faster R-CNN模型放入ACI上的容器实例.为此,我需要我的Docker映像拥有python版本3.5.*.我在conda yaml文件中指定了该代码,但是每次我旋转一个实例并在其中运行 docker run -it ***/bin/bash
时,我都会看到它只有Python 3.6.7.
I am trying to get my Faster R-CNN model into an Container Instance on ACI. For that I need my docker image to posses python version 3.5.*. I specify that in my conda yaml file, but every time I spin an instance up and docker run -it *** /bin/bash
into it I see that it only has Python 3.6.7.
https://user-images.githubusercontent.com/21140767/50680590-82b20b80-1008-11e9-9bfe-4a0e71084ce0.png
如何使我的Docker映像具有Python版本3.5.*?我已经尝试过conda安装Python版本3.5.2,但是没有成功,因为最终它没有3.5.2,而只有3.6.7.(dfimage可让您查看用于创建映像的dockerfile, https://hub.docker.com/r/chenzj/dfimage/).
How can I get my Docker image to have Python version 3.5.*? I already tried conda installing Python version 3.5.2, but that didn't work as eventually it didn't posses 3.5.2, but only 3.6.7. (dfimage lets you see the dockerfile from which the image was created, https://hub.docker.com/r/chenzj/dfimage/).
https://user-images.githubusercontent.com/21140767/50680673-d6245980-1008-11e9-9d48-71a7c150d925.png
我的Yaml:
name: project_environment
dependencies:
- python=3.5.2
- pip:
- matplotlib
- opencv-python==3.4.3.18
- azureml-core==1.0.6
- numpy
- cntk
- cython
channels:
- anaconda
笔记本单元格:从azureml.core.conda_dependencies导入CondaDependencies
Notebook cell: from azureml.core.conda_dependencies import CondaDependencies
svmandss = CondaDependencies.create(python_version="3.5.2", pip_packages=[
"matplotlib",
"opencv-python==3.4.3.18",
"azureml-core",
"numpy",
"cntk",
"cython"], )
svmandss.add_channel('anaconda')
with open("fasterrcnn.yml","w") as f:
f.write(svmandss.serialize_to_string())
另一个具有ContainerImage规范的笔记本单元格.
Another notebook cell with ContainerImage specifications.
image_config = ContainerImage.image_configuration(execution_script="score_fasterrcnn.py",runtime="python",conda_file="./fasterrcnn.yml",dependencies=listdir("utils"),docker_file="./Dockerfile")
service = Webservice.deploy_from_model(workspace=ws,
name='faster-rcnn',
deployment_config=aciconfig,
models=[Model(workspace=ws, name='Faster-RCNN')],
image_config=image_config)
service.wait_for_deployment(show_output=True)
注意
为获得更好的可读性,请参阅我的GitHub问题:( https://github.com/Azure/MachineLearningNotebooks/issues/163 ).
推荐答案
由于这是Google搜索"azureml python版本"时的最佳回答之一.我在这里发布答案.关于这个问题,文档还不是很清楚,但是可以使用以下内容:
Since this is one of the top Google answers when searching for "azureml python version" I'm posting the answer here. The documentation is not very clear when it comes to this, but the following will work:
from azureml.core import Workspace
from azureml.core.runconfig import RunConfiguration
from azureml.core.conda_dependencies import CondaDependencies
ws = Workspace.from_config()
# This is the important part
conda_dep = CondaDependencies(conda_dependencies_file_path="pipeline/environment.yml")
aml_run_config = RunConfiguration(conda_dependencies=conda_dep)
# Define compute target - must be preconfigured in th workspace
compute_target = ws.compute_targets['my-azureml-target']
aml_run_config.target = compute_target
from azureml.pipeline.steps import PythonScriptStep
script_source_dir = "./pipeline"
step_1_script = "test.py"
step_1 = PythonScriptStep(
script_name=step_1_script,
source_directory=script_source_dir,
compute_target=compute_target,
runconfig=aml_run_config,
allow_reuse=True
)
from azureml.pipeline.core import Pipeline
# Build the pipeline
pipeline1 = Pipeline(workspace=ws, steps=[step_1])
from azureml.core import Experiment
# Submit the pipeline to be run
pipeline_run1 = Experiment(ws, 'Test-pipeline').submit(pipeline1)
pipeline_run1.wait_for_completion(show_output=True)
这采用以下目录结构:
- root/
- create_pipeline.py
- 管道/
- test.py
- environment.yml
其中create_pipeline.py是上面的文件,test.py是您要运行的脚本,environment.yml是conda环境文件-包括python版本.
where create_pipeline.py is the file above, test.py is the script you would like to run and environment.yml is the conda environment file - including the python version.
这篇关于如何使用CondaDependencies更改Azure Machine Learning sdk ContainerImage中的Python版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!