简体   繁体   English

如何使用 AWS SageMaker Autopilot 创建的模型生成批量预测?

[英]How to generate batch forecasts using model created by AWS SageMaker Autopilot?

I created a complete model using Amazon Web Services (AWS) SageMaker Autopilot.我使用 Amazon Web Services (AWS) SageMaker Autopilot 创建了一个完整的模型。 I would like to see what forecasts the model makes on my training data.我想看看模型对我的训练数据做出了什么预测。 I'm running this in a SageMaker Studio notebook.我在 SageMaker Studio 笔记本中运行它。 Here's my code.这是我的代码。

import sagemaker

image = sagemaker.image_uris.retrieve("xgboost", sagemaker.session.Session().boto_region_name, version="latest")

model = sagemaker.model.Model(
    image_uri = image,
    model_data = "s3://sagemaker-us-east-.../batch-prediction/sagemaker-xgboost-2021-.../output/model.tar.gz"
)

transformer = model.transformer(
    instance_count = 1,
    instance_type = "ml.c4.xlarge"
)

Here's the full error stack.这是完整的错误堆栈。

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-14-23386d1fc99a> in <module>
      1 transformer = my_model.transformer(
      2     instance_count = 1,
----> 3     instance_type = "ml.c4.xlarge"
      4 )

/opt/conda/lib/python3.7/site-packages/sagemaker/model.py in transformer(self, instance_count, instance_type, strategy, assemble_with, output_path, output_kms_key, accept, env, max_concurrent_transforms, max_payload, tags, volume_kms_key)
    772         self._init_sagemaker_session_if_does_not_exist(instance_type)
    773 
--> 774         self._create_sagemaker_model(instance_type, tags=tags)
    775         if self.enable_network_isolation():
    776             env = None

/opt/conda/lib/python3.7/site-packages/sagemaker/model.py in _create_sagemaker_model(self, instance_type, accelerator_type, tags)
    259             vpc_config=self.vpc_config,
    260             enable_network_isolation=enable_network_isolation,
--> 261             tags=tags,
    262         )
    263 

/opt/conda/lib/python3.7/site-packages/sagemaker/session.py in create_model(self, name, role, container_defs, vpc_config, enable_network_isolation, primary_container, tags)
   2596             enable_network_isolation=enable_network_isolation,
   2597             primary_container=primary_container,
-> 2598             tags=tags,
   2599         )
   2600         LOGGER.info("Creating model with name: %s", name)

/opt/conda/lib/python3.7/site-packages/sagemaker/session.py in _create_model_request(self, name, role, container_defs, vpc_config, enable_network_isolation, primary_container, tags)
   2512             container_defs = primary_container
   2513 
-> 2514         role = self.expand_role(role)
   2515 
   2516         if isinstance(container_defs, list):

/opt/conda/lib/python3.7/site-packages/sagemaker/session.py in expand_role(self, role)
   3466             str: The corresponding AWS IAM role ARN.
   3467         """
-> 3468         if "/" in role:
   3469             return role
   3470         return self.boto_session.resource("iam").Role(role).arn

TypeError: argument of type 'NoneType' is not iterable

You also need to specify a SageMaker role (either name or full ARN) to give permissions to Amazon SageMaker training jobs to access training data and model artifacts.您还需要指定 SageMaker 角色(名称或完整 ARN)以授予 Amazon SageMaker 训练作业访问训练数据和模型工件的权限。 Here is the link to the documentation .这是文档的链接。

So after your import sagemaker you need to add something like因此,在您导入 sagemaker 之后,您需要添加类似

from sagemaker import get_execution_role

sagemaker_session = sagemaker.Session() 
role = get_execution_role()

and later have后来有

model = sagemaker.model.Model(
    image_uri = image,
    model_data = "s3://sagemaker-us-east-.../batch-prediction/sagemaker-xgboost-2021-.../output/model.tar.gz",
role=role
...

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

相关问题 是否可以在不使用 SageMaker SDK 的情况下为我在 AWS SageMaker 中创建的模型设置终端节点 - Is it possible set up an endpoint for a model I created in AWS SageMaker without using the SageMaker SDK AWS自动驾驶生成的Model - Model generated by AWS autopilot 在 aws sagemaker 中使用外部库进行模型训练 - Using external libraries for model training in aws sagemaker 如何在AWS Sagemaker中训练自己的模型? - How to train your own model in AWS Sagemaker? 用于批量转换的 AWS SageMaker 部署 - AWS SageMaker Deployment for Batch Transform 使用 SageMaker 模型预测一批图像 - Predict batch of images with a SageMaker model 如何使用 CDK、sagemaker 部署 AWS? - How to deploy AWS using CDK, sagemaker? AWS SageMaker:使用托管在 S3 中的经过训练的 model 创建终端节点 - AWS SageMaker: Create an endpoint using a trained model hosted in S3 借助 AWS SageMaker,是否可以使用 sagemaker SDK 部署预训练模型? - With AWS SageMaker, is it possible to deploy a pre-trained model using the sagemaker SDK? 如何选择超参数来训练AWS sagemaker上的良好物体检测模型? - How to choose hyperparameters to train a good object detection model on AWS sagemaker?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM