[英]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.