繁体   English   中英

从 AWS SageMaker Pipeline 训练组件中的训练脚本将自定义文件上传到 s3

[英]Upload custom file to s3 from training script in training component of AWS SageMaker Pipeline

我是 Sagmaker 的新手,我已经从 SageMaker notebook 创建了一个管道,其中包含训练和部署组件。 在训练脚本中,我们可以通过SM_MODEL_DIR将 model 上传到 s3。 但是现在,我想将分类报告上传到s3。 我试过这段代码。 但它表明这不是一个合适的 s3 存储桶。

df_classification_report = pd.DataFrame(class_report).transpose()
classification_report_file_name = os.path.join(args.output_data_dir,
                                               f"{args.eval_model_name}_classification_report.csv")
df_classification_report.to_csv(classification_report_file_name)
# instantiate S3 client and upload to s3

# save classification report to s3
s3 = boto3.resource('s3')
print(f"classification_report is being uploaded to s3- {args.model_dir}")
s3.meta.client.upload_file(classification_report_file_name, args.model_dir,
                            f"{args.eval_model_name}_classification_report.csv")

和错误

Invalid bucket name "/opt/ml/output/data": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$" or be an ARN matching the regex "^arn:(aws).*:(s3|s3-object-lambda):[a-z\-0-9]+:[0-9]{12}:accesspoint[/:][a-zA-Z0-9\-]{1,63}$|^arn:(aws).*:s3-outposts:[a-z\-0-9]+:[0-9]{12}:outpost[/:][a-zA-Z0-9\-]{1,63}[/:]accesspoint[/:][a-zA-Z0-9\-]{1,63}$"

有人可以帮忙吗? 我真的很感激你能提供的任何帮助。

SageMaker 培训作业将压缩位于/opt/ml/modelSM_MODEL_DIR的值)中的任何文件,并自动将其上传到 S3。 您可以考虑将文件保存到SM_MODEL_DIR (您的分类报告将因此上传到 model tar 球中的 S3)。

upload_file() function 要求您传递一个 S3 存储桶。 您还可以查看在代码中手动指定一个 S3 存储桶以将文件上传到。

s3.meta.client.upload_file(classification_report_file_name, <YourS3Bucket>,
                            f"{args.eval_model_name}_classification_report.csv")

您可以将非 model 工件(例如报告)保存到output_data_dir 这里

parser.add_argument("--output_data_dir", type=str, 
default=os.environ.get('SM_OUTPUT_DATA_DIR'),                              
     help="Directory to save output data artifacts.")

如果您希望将工件与 model 文件打包在一起,请按照@Marc 的回答进行操作。 对于与特定 model 相关的报告,这可能是有意义的,尽管在 model 注册表中捕获它对我来说更有意义。
请注意,如果您将 model 部署到端点(可能会混淆推理运行时 model 加载代码),这些额外的工件将被保留。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM