首页 > 解决方案 > 如何在 AWS Sagemaker 中查找不同区域的 XGBoost 容器

问题描述

我正在尝试按照 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.")

预期结果如下。

在此处输入图像描述

但是,我收到此错误。

KeyError Traceback (last recent call last) in () 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 + " 区域。您将使用 " + containers[my_region] + " SageMaker 端点的容器。")

KeyError:'ap-northeast-2'

我认为发生这种情况是因为我的区域是"ap-northeast-2"。我有一种感觉,我需要为我所在的地区更换容器。

如果我的猜测是正确的,我怎样才能找到我所在地区的容器?
另外,我是否忽略了其他任何事情?

标签: amazon-web-servicesamazon-sagemaker

解决方案


在此链接中找到您在 XGBoost (0.72) 中的训练图像和推理图像注册表路径: https ://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-algo-docker-registry-paths.html

在您的情况下,它将是“ap-northeast-2”。使用相关的 ecr 将其添加到您的容器中。它应该可以正常工作。


推荐阅读