如何将在Sagemaker处理容器中创建的.html文件保存到S3中

0

【以下的问题经过翻译处理】 错误消息: “FileNotFoundError: [Errno 2] No such file or directory: '/opt/ml/processing/output/profile_case.html'”

背景: 我在Sagemaker里编写Python代码,尝试使用pandas profiling来分析保存在S3存储桶中的dataframe。由于数据非常大,所以我使用了SKLearn处理器,而不是启动一个大型的EC2实例。

一切运行良好,但当作业完成时,它不会将pandas profile(一个.html文件)保存到S3存储桶或实例Sagemaker正在运行的位置。

当我尝试导出从pandas profile创建的.html文件时,我不断收到文件找不到的错误。

有没有人知道如何将SKLearn处理器正在运行的临时24xl实例中的.html文件导出到S3中?以下是我正在使用的确切代码:

import os
import sys
import subprocess
def install(package):
    subprocess.check_call([sys.executable, "-q", "-m", "pip", "install", package])
install('awswrangler')
install('tqdm')
install('pandas')
install('botocore==1.19.4')
install('ruamel.yaml')
install('pandas-profiling==2.13.0')
import awswrangler as wr
import pandas as pd
import numpy as np
import datetime as dt
from dateutil.relativedelta import relativedelta
from string import Template
import gc
import boto3

from pandas_profiling import ProfileReport

client = boto3.client('s3')
session = boto3.Session(region_name="eu-west-2")

%%writefile casetableprofile.py

import os
import sys
import subprocess
def install(package):
    subprocess.check_call([sys.executable, "-q", "-m", "pip", "install", package])
install('awswrangler')
install('tqdm')
install('pandas')
install('botocore')
install('ruamel.yaml')
install('pandas-profiling')
import awswrangler as wr
import pandas as pd
import numpy as np
profile picture
专家
已提问 8 个月前59 查看次数
1 回答
0

【以下的回答经过翻译处理】 首先,通常情况下你不需要直接在处理脚本中与S3进行交互:在配置了 ProcessingOutput 的情况下,你的脚本保存在 /opt/ml/processing/output 中的任何文件都会自动上传到你设定的 s3://... 目标S3桶的地址里。当然,可能会有特殊情况需要直接从脚本中访问S3,但通常处理作业输入和输出应该为你做好了,这让你的代码更简洁明了。

我不是 Pandas Profiler 专家,但我认为你的错误可能来自这里:


```output_path_tblforprofile = ('profile_case.html')
    print(output_path_tblforprofile)
    
    profile_tblforprofile.to_file(output_path_tblforprofile)

这段代码的意图不就是将报告保存到当前工作目录下的 `profile_case.html` 中吗?但这不是 `/opt/ml/processing/output` 目录,这通常是脚本下载到容器中的文件夹。FileNotFound 错误告诉你该 HTML 文件没有在你期望的文件夹中创建。

所以,我建议你将输出路径明确设置为 `/opt/ml/processing/output/profile_case.html`,并且删掉最后的 boto3/s3 部分
profile picture
专家
已回答 8 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则