Python 来自管道的Azure ML输出

Python 来自管道的Azure ML输出,python,azure,output,pipeline,azure-machine-learning-service,Python,Azure,Output,Pipeline,Azure Machine Learning Service,我正在尝试在Microsoft Azure中构建一个管道,输入中(目前)有一个简单的python脚本。 问题是我找不到我的输出。 在我的笔记本部分,我构建了以下两个代码: 1) 名为“test.ipynb”的脚本 2) 名为“pipeline.ipynb”的管道代码 这给了我以下错误: Pipeline run completed --------------------------------------------------------------------------- FileNot

我正在尝试在Microsoft Azure中构建一个管道,输入中(目前)有一个简单的python脚本。 问题是我找不到我的输出。 在我的笔记本部分,我构建了以下两个代码:

1) 名为“test.ipynb”的脚本

2) 名为“pipeline.ipynb”的管道代码

这给了我以下错误:

Pipeline run completed
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-22-a8a523969bb3> in <module>
    111 
    112 # Upload the model file explicitly into artifacts (for CI/CD)
--> 113 pipeline_run.upload_file(name = model_path, path_or_stream = model_path)
    114 print('Uploaded the model {} to experiment {}'.format(model_fname, pipeline_run.experiment.name))
    115 

/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azureml/core/run.py in wrapped(self, *args, **kwargs)
     47                                      "therefore, the {} cannot upload files, or log file backed metrics.".format(
     48                                          self, self.__class__.__name__))
---> 49         return func(self, *args, **kwargs)
     50     return wrapped
     51 

/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azureml/core/run.py in upload_file(self, name, path_or_stream)
   1749         :rtype: azure.storage.blob.models.ResourceProperties
   1750         """
-> 1751         return self._client.artifacts.upload_artifact(path_or_stream, RUN_ORIGIN, self._container, name)
   1752 
   1753     @_check_for_data_container_id

/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azureml/_restclient/artifacts_client.py in upload_artifact(self, artifact, *args, **kwargs)
    108         if isinstance(artifact, str):
    109             self._logger.debug("Uploading path artifact")
--> 110             return self.upload_artifact_from_path(artifact, *args, **kwargs)
    111         elif isinstance(artifact, IOBase):
    112             self._logger.debug("Uploading io artifact")

/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azureml/_restclient/artifacts_client.py in upload_artifact_from_path(self, path, *args, **kwargs)
    100         path = os.path.normpath(path)
    101         path = os.path.abspath(path)
--> 102         with open(path, "rb") as stream:
    103             return self.upload_artifact_from_stream(stream, *args, **kwargs)
    104 

FileNotFoundError: [Errno 2] No such file or directory: '/mnt/azmnt/code/Users/aniello.spiezia/outputs/output.csv'
管道运行已完成 --------------------------------------------------------------------------- FileNotFoundError回溯(最近一次调用上次) 在里面 111 112#将模型文件显式上载到工件中(对于CI/CD) -->113管道运行。上传文件(名称=模型路径、路径或流=模型路径) 114打印('将模型{}上载到实验{}'。格式(模型名称,管道运行。实验名称)) 115 /anaconda/envs/azureml_py36/lib/python3.6/site-packages/azureml/core/run.py in wrapped(self,*args,**kwargs) 47“因此,{}无法上载文件或记录文件支持的度量。”.format( 48 self,self.\uuuuuuuuuuuuuuuuuuuuuuu class.\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu --->49返回函数(self、*args、**kwargs) 50包好的退货 51 /上传文件(自身、名称、路径或流)中的anaconda/envs/azureml\u py36/lib/python3.6/site-packages/azureml/core/run.py 1749:rtype:azure.storage.blob.models.ResourceProperties 1750 """ ->1751返回self.\u client.artifact.upload.\u artifact(路径或流、运行源、self.\u容器、名称) 1752 1753@\u检查\u数据\u容器\u id /上传工件中的anaconda/envs/azureml\u py36/lib/python3.6/site-packages/azureml//u restclient/artifacts\u client.py(self、artifact、*args、**kwargs) 108如果存在(工件,str): 109 self._logger.debug(“上传路径工件”) -->110返回自我。从路径上传工件(工件,*args,**kwargs) 111 elif isinstance(工件、IOBase): 112 self._logger.debug(“上传io工件”) /anaconda/envs/azureml\u py36/lib/python3.6/site-packages/azureml//u restclient/artifacts\u client.py从路径上传工件(self、path、*args、**kwargs) 100 path=os.path.normpath(路径) 101 path=os.path.abspath(path) -->102以开放(路径“rb”)为流: 103返回自我。从_流上传_工件(流,*args,**kwargs) 104 FileNotFoundError:[Errno 2]没有这样的文件或目录:'/mnt/azmnt/code/Users/aniello.spiezia/outputs/output.csv' 你知道可能是什么问题吗?
我特别感兴趣的是将名为“output.csv”的输出文件保存到某个地方。执行此操作的最佳方式取决于运行完成后您希望如何处理output.csv文件。但是,通常您可以将csv写入./outputs文件夹:

# azureml-core of version 1.0.72 or higher is required
from azureml.core import Workspace, Dataset, Datastore
import pandas as pd
import numpy as np
import datetime
import math

#Upload datasets
subscription_id = 'myid'
resource_group = 'myrg'
workspace_name = 'mywn'
workspace = Workspace(subscription_id, resource_group, workspace_name)
dataset_zre = Dataset.get_by_name(workspace, name='file1')
dataset_SLA = Dataset.get_by_name(workspace, name='file2')
df_zre = dataset_zre.to_pandas_dataframe()
df_SLA = dataset_SLA.to_pandas_dataframe()
result = pd.concat([df_SLA,df_zre], sort=True)

if not os.path.isdir('outputs')
    os.mkdir('outputs')
result.to_csv('outputs/output.csv', index=False)

print("\nFinished!")
#End of the file
运行完成后,AzureML将输出目录的内容上载到运行历史记录中,因此无需
datastore.upload()

之后,当您导航到下面类似my
model.pt的运行文件时,您可以在中看到该文件:

有关./outputs和./logs文件夹的一些信息,请参见此处:


如果您确实希望在运行后创建另一个数据集,请参见此处的帖子:

在上面Daniel的示例中,您需要从运行中下载输出,而不是pipeline.ipynb代码中的数据存储。您不需要调用def_data_store.download(),而是调用pipeline_Run.download()('outputs/output.csv','.')

另一个选项是使用PipelineData输出数据。PipelineData表示管道步骤的命名输出片段,如果要将多个步骤与输入和输出连接在一起,此选项非常有用。使用PipelineData,在声明步骤时需要将PipelineData对象传递到PythonScriptStep中(作为参数=[]和输出=[]的一部分),然后让脚本从命令行参数读取输出路径

本笔记本提供了在管道中使用PipelineData并下载输出的示例:


这篇博客文章详细介绍了如何在脚本中处理这个问题(解析命令行参数、创建输出目录和编写输出文件):

亲爱的Daniel,非常感谢您的回答。我已经按照您的建议更改了test.ipynb文件,然后我回到pipeline.ipynb文件并按下“Run”按钮“。管道已开始运行,但输出中未生成任何文件,并且我的错误与以前完全相同,即
FileNotFoundError:[Errno 2]没有这样的文件或目录:'/mnt/azmnt/code/Users/aniello.spiezia/outputs/output.csv'
在我看来,管道没有运行test.ipynb脚本。这怎么可能?嗨@AnielloSpiezia,你确定你重新部署了管道吗?我似乎不太可能在从脚本中删除完整路径后,仍然是searc对于相同的路径,您是否触发了旧的已发布管道?在执行脚本pipeline.ipynb后,您应该会在实验“aml pipeline cicd”中看到管道运行。无需从UX.P.S.启动它:我建议为您的脚本提供扩展名.py-。ipynb通常用于Python笔记本s和使用错误的扩展可能会导致下游出现问题。
Pipeline run completed
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-22-a8a523969bb3> in <module>
    111 
    112 # Upload the model file explicitly into artifacts (for CI/CD)
--> 113 pipeline_run.upload_file(name = model_path, path_or_stream = model_path)
    114 print('Uploaded the model {} to experiment {}'.format(model_fname, pipeline_run.experiment.name))
    115 

/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azureml/core/run.py in wrapped(self, *args, **kwargs)
     47                                      "therefore, the {} cannot upload files, or log file backed metrics.".format(
     48                                          self, self.__class__.__name__))
---> 49         return func(self, *args, **kwargs)
     50     return wrapped
     51 

/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azureml/core/run.py in upload_file(self, name, path_or_stream)
   1749         :rtype: azure.storage.blob.models.ResourceProperties
   1750         """
-> 1751         return self._client.artifacts.upload_artifact(path_or_stream, RUN_ORIGIN, self._container, name)
   1752 
   1753     @_check_for_data_container_id

/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azureml/_restclient/artifacts_client.py in upload_artifact(self, artifact, *args, **kwargs)
    108         if isinstance(artifact, str):
    109             self._logger.debug("Uploading path artifact")
--> 110             return self.upload_artifact_from_path(artifact, *args, **kwargs)
    111         elif isinstance(artifact, IOBase):
    112             self._logger.debug("Uploading io artifact")

/anaconda/envs/azureml_py36/lib/python3.6/site-packages/azureml/_restclient/artifacts_client.py in upload_artifact_from_path(self, path, *args, **kwargs)
    100         path = os.path.normpath(path)
    101         path = os.path.abspath(path)
--> 102         with open(path, "rb") as stream:
    103             return self.upload_artifact_from_stream(stream, *args, **kwargs)
    104 

FileNotFoundError: [Errno 2] No such file or directory: '/mnt/azmnt/code/Users/aniello.spiezia/outputs/output.csv'
# azureml-core of version 1.0.72 or higher is required
from azureml.core import Workspace, Dataset, Datastore
import pandas as pd
import numpy as np
import datetime
import math

#Upload datasets
subscription_id = 'myid'
resource_group = 'myrg'
workspace_name = 'mywn'
workspace = Workspace(subscription_id, resource_group, workspace_name)
dataset_zre = Dataset.get_by_name(workspace, name='file1')
dataset_SLA = Dataset.get_by_name(workspace, name='file2')
df_zre = dataset_zre.to_pandas_dataframe()
df_SLA = dataset_SLA.to_pandas_dataframe()
result = pd.concat([df_SLA,df_zre], sort=True)

if not os.path.isdir('outputs')
    os.mkdir('outputs')
result.to_csv('outputs/output.csv', index=False)

print("\nFinished!")
#End of the file