ModuleNotFoundError:Azure ML管道中没有名为“ keras”的模块

时间:2019-10-03 06:00:38

标签: azure-machine-learning-service

我正在尝试按照以下步骤-documented here

使用dogs vs cats数据集获得一个简单的Azure ML管道

我的笔记本包含以下内容-

import azureml.core
from azureml.core import Workspace, Datastore
from azureml.core import Environment
from azureml.core.environment import CondaDependencies
from azureml.pipeline.steps import PythonScriptStep

ws = Workspace.from_config()

myenv = Environment(name="myenv")
conda_dep = CondaDependencies()
conda_dep.add_conda_package("keras")
conda_dep.add_conda_package("PIL")
myenv.python.conda_dependencies=conda_dep
myenv.register(workspace=ws)

设置数据引用和计算后,这就是我创建管道的方式-

trainStep = PythonScriptStep(
    script_name="dogs_vs_cats.py",
    arguments=["--input", blob_input_data, "--output", output_data1],
    inputs=[blob_input_data],
    outputs=[output_data1],
    compute_target=compute_target,
    source_directory="../dogs-vs-cats"
)

Steps = [trainStep]

from azureml.pipeline.core import Pipeline
pipeline1 = Pipeline(workspace=ws, steps=[Steps])

from azureml.core import Experiment

pipeline_run1 = Experiment(ws, 'dogs_vs_cats_exp').submit(pipeline1)
pipeline_run1.wait_for_completion()

一旦执行了此步骤,实验就会失败,一堆信息后我会收到以下错误-

Traceback (most recent call last):
  File "dogs_vs_cats.py", line 30, in <module>
    import keras
ModuleNotFoundError: No module named 'keras'

终端显示我的conda环境设置为azureml_py36,而Keras似乎列在conda list的输出中。

我是否正确设置了环境?什么是误报

1 个答案:

答案 0 :(得分:0)

从您指定环境的方式来看,很难看出它是否是正确的RunConfiguration对象。如果是这样,应该将其添加到PythonScriptStep中。

trainStep = PythonScriptStep(
    script_name="dogs_vs_cats.py",
    arguments=["--input", blob_input_data, "--output", output_data1],
    inputs=[blob_input_data],
    outputs=[output_data1],
    compute_target=compute_target,
    source_directory="../dogs-vs-cats",
    runconfig=myenv
)

现在,您正在定义环境,但是似乎没有在任何地方使用它。如果您的问题仍然存在,请尝试像在此笔记本中的“指定运行脚本的环境”步骤中一样定义您的RunConfiguration:

https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/machine-learning-pipelines/pipeline-batch-scoring/pipeline-batch-scoring.ipynb