如何在AWS Sagemaker中查找不同区域的XGBoost容器

问题描述 投票:0回答:1

我正在尝试遵循AWS Sagemaker教程,以在Jupyter笔记本环境中训练机器学习模型。

根据本教程,我应该复制以下代码并运行它以导入所需的库并设置环境变量。

# import libraries
import boto3, re, sys, math, json, os, sagemaker, urllib.request
from sagemaker import get_execution_role
import numpy as np                                
import pandas as pd                               
import matplotlib.pyplot as plt                   
from IPython.display import Image                 
from IPython.display import display               
from time import gmtime, strftime                 
from sagemaker.predictor import csv_serializer   

# Define IAM role
role = get_execution_role()
prefix = 'sagemaker/DEMO-xgboost-dm'
containers = {'us-west-2': '433757028032.dkr.ecr.us-west-2.amazonaws.com/xgboost:latest',
              'us-east-1': '811284229777.dkr.ecr.us-east-1.amazonaws.com/xgboost:latest',
              'us-east-2': '825641698319.dkr.ecr.us-east-2.amazonaws.com/xgboost:latest',
              'eu-west-1': '685385470294.dkr.ecr.eu-west-1.amazonaws.com/xgboost:latest'} # each region has its XGBoost container
my_region = boto3.session.Session().region_name # set the region of the instance
print("Success - the MySageMakerInstance is in the " + my_region + " region. You will use the " + containers[my_region] + " container for your SageMaker endpoint.")

预期结果如下。

enter image description here

但是,我遇到此错误。

KeyError Traceback(最近一次通话)在()中18'eu-west-1':'685385470294.dkr.ecr.eu-west-1.amazonaws.com/xgboost:latest'}#每个区域都有其XGBoost容器19 my_region = boto3.session.Session()。region_name#设置实例的区域---> 20 print(“成功-MySageMakerInstance位于” + my_region +“区域。您将使用” + container [my_region] +“容器作为SageMaker端点。”]

KeyError:'ap-northeast-2'

我认为是因为我所在的地区是“ ap-northeast-2”。我觉得我需要为我所在的区域更换容器。

如果我的猜测是正确的,如何找到我所在地区的容器?而且,我还能俯瞰其他地方吗?

amazon-web-services amazon-sagemaker
1个回答
0
投票

我希望你的理性是正确的。代码中没有您所在地区的条目。我不知道每个区域是否有这些容器的列表。话虽如此,您可以在ECR(弹性容器注册表)中找到它们。

请记住,您可以通过切换到受支持的区域之一来快速解决此问题。否则:

如果您所在地区没有AWS公开列出的容器,则可以使用ECR在AWS中自己注册该容器。您需要使用AWS CLI和docker登录名登录ECR。

您可以使用命令aws ecr get-login --region ap-northeast-2来获取docker登录所需的令牌。

然后克隆此仓库:https://github.com/aws/sagemaker-xgboost-container

您可以在本地构建此映像并将其推送到ECR。之后,登录到AWS控制台(或使用AWS CLI)并找到映像的ARN。它应该与代码中其他格式匹配。

之后,只需在containers变量的代码中添加另一个键/值条目,然后使用'ap-northeast-2': '<ARN of the docker image>'

© www.soinside.com 2019 - 2024. All rights reserved.