![](/img/trans.png)
[英]Is it possible set up an endpoint for a model I created in AWS SageMaker without using the SageMaker SDK
[英]How to generate batch forecasts using model created by AWS SageMaker Autopilot?
我使用 Amazon Web Services (AWS) SageMaker Autopilot 創建了一個完整的模型。 我想看看模型對我的訓練數據做出了什么預測。 我在 SageMaker Studio 筆記本中運行它。 這是我的代碼。
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"
)
這是完整的錯誤堆棧。
---------------------------------------------------------------------------
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
您還需要指定 SageMaker 角色(名稱或完整 ARN)以授予 Amazon SageMaker 訓練作業訪問訓練數據和模型工件的權限。 這是文檔的鏈接。
因此,在您導入 sagemaker 之后,您需要添加類似
from sagemaker import get_execution_role
sagemaker_session = sagemaker.Session()
role = get_execution_role()
后來有
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.