xgboost sagemaker 训练失败

xgboost sagemaker train failure

当我 运行 使用 xgboost conatiner 在 sagemaker 上进行训练时出现类型错误。 请建议我解决问题。

container = 'southeast-2','783357654285.dkr.ecr.ap-southeast-2.amazonaws.com/sagemaker- xgboost:latest'`

train_input = TrainingInput(s3_data='s3://{}/train'.format(bucket, prefix), content_type='csv')
validation_input = TrainingInput(s3_data='s3://{}/validation/'.format(bucket, prefix), content_type='csv')

sess = sagemaker.Session()

xgb = sagemaker.estimator.Estimator(
container,
role, 
instance_count=1,
instance_type='ml.t2.medium',
output_path='s3://{}/output'.format(bucket, prefix),
sagemaker_session=sess
)

xgb.set_hyperparameters(
max_depth=5,
eta=0.1,
gamma=4,
min_child_weight=6,
subsample=0.8,
silent=0,
objective="binary:logistic",
num_round=25,
)

xgb.fit({"train": train_input, "validation": validation_input})

TypeError Traceback(最后一次调用) 在 21) 22 ---> 23 xgb.fit({"训练": train_input, "验证": validation_input})

~/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/sagemaker/estimator.py in fit(self, inputs, wait, logs, job_name, experiment_config) 685 * TrialComponentDisplayName用于在Studio中显示。 第686章 --> 687 self._prepare_for_training(job_name=job_name) 688 689 self.latest_training_job = _TrainingJob.start_new(自我,输入,experiment_config)

~/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/sagemaker/estimator.py in _prepare_for_training(self, job_name) 446 构造函数(如果适用)。 第447章 --> 448 self._current_job_name = self._get_or_create_name(job_name) 449 450 # 如果指定了 output_path 我们使用它,否则在这里初始化。

~/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/sagemaker/estimator.py in _get_or_create_name(self, name) 435return名字 436 --> 437 self._ensure_base_job_name() 第438话returnname_from_base(self.base_job_name) 439

~/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/sagemaker/estimator.py in _ensure_base_job_name(self) 420 # 尊重提供的 base_job_name 或生成它 421 如果 self.base_job_name 是 None: --> 422 self.base_job_name = base_name_from_image(self.training_image_uri()) 423 424 def _get_or_create_name(self, name=None):

~/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/sagemaker/utils.py in base_name_from_image(图片) 95 str:算法名称,从图像名称中提取。 96 """ ---> 97 m = re.match("^(.+/)?([^:/]+)(:[^:]+)?$", 图片) 98 algo_name = m.group(2) if m else 图像 99returnalgo_name

~/anaconda3/envs/mxnet_p36/lib/python3.6/re.py in match(pattern, string, flags) 170 """尝试在字符串的开头应用模式,returning 171 匹配对象,如果未找到匹配项,则为 None。""" --> 172 return _compile(模式、标志).匹配(字符串) 173 174 def fullmatch(模式,字符串,标志=0):

类型错误:预期的字符串或类字节对象

import sagemaker
from sagemaker.inputs import TrainingInput
from sagemaker.serializers import CSVSerializer
from sagemaker.session import TrainingInput
from sagemaker import image_uris
from sagemaker.session import Session

# initialize hyperparameters
hyperparameters = {
    "max_depth":"5",
    "eta":"0.1",
    "gamma":"4",
    "min_child_weight":"6",
    "subsample":"0.7",
    "objective":"binary:logistic",
    "num_round":"25"}

# set an output path where the trained model will be saved
bucket = sagemaker.Session().default_bucket()
output_path = 's3://{}/{}/output'.format(bucket, 'rain-xgb-built-in-algo')


# this line automatically looks for the XGBoost image URI and builds an 
XGBoost container.
# specify the repo_version depending on your preference.
xgboost_container = sagemaker.image_uris.retrieve("xgboost", 'ap-southeast- 
2', "1.3-1")


# construct a SageMaker estimator that calls the xgboost-container
estimator = sagemaker.estimator.Estimator(image_uri=xgboost_container, 
                                      hyperparameters=hyperparameters,
                                      role=sagemaker.get_execution_role(),
                                      instance_count=1, 
                                      instance_type='ml.m5.large', 
                                      volume_size=5, # 5 GB 
                                      output_path=output_path)



 # define the data type and paths to the training and validation datasets

 train_input = TrainingInput("s3://{}/{}/".format(bucket,'train'), 
 content_type='csv')
 validation_input = TrainingInput("s3://{}/{}".format(bucket,'validation'), 
 content_type='csv')


 # execute the XGBoost training job
 estimator.fit({'train': train_input, 'validation': validation_input})

我已经改写如上,可以运行训练了。 谢谢!