xgboost-sagemaker列车故障



当我使用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":train_input,"validation":validation_input}(

~/anconda3/envs/mxnet_p36/lib/python3.6/site-packages/sagemaker/estimator.py适合(self、inputs、wait、logs、job_name、experiment_config(685*TrialComponentDisplayName用于Studio中的显示。686〃"quot;-->687自我_prepare_for_training(作业名称=作业名称(688689 self.latest_training_job=_TrainingJob.start_new(self,inputs,experiment_config(

~/anconda3/envs/mxnet_p36/lib/python3.6/site-packages/sagemaker/estimator.py in _prepare_for_training(self,job_name(446构造函数(如果适用(。447〃"quot;-->448自我_current_job_name=自我_get_or_create_name(作业名称(449450#如果指定了output_path,则在此处使用它进行初始化。

_get_or_create_name(self,name(中的~/anconda3/envs/mxnet_p36/lib/python3.6/site-packages/sagemaker/estimator.py435返回名称436-->437自我_ensure_base_job_name((438 return name_from_base(self.base_job_name(439

~/anconda3/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为"无":-->422 self.base_job_name=base_name_from_image(self.training_image_uri(((423424 def_get_or_create_name(self,name=None(:

~/anconda3/envs/mxnet_p36/lib/python3.6/site-packages/sagemaker/utils.py在base_name_from_image(image(中95 str:从图像名称中提取的算法名称。96〃"quot;--->97 m=重新匹配("^(.+/(?([^:/]+((:[^:]+($&";,图像(98 algor_name=m.group(2(if m else image99返回算法名称

~/anconda3/envs/mxnet_p36/lib/python3.6/re.py匹配(模式、字符串、标志(170〃"quot;尝试在字符串的开头应用该模式,返回171匹配对象,如果未找到匹配对象则为None"quot"-->172 return _compile(模式,标志(.match(字符串(173174 def fullmatch(模式,字符串,标志=0(:

TypeError:应为字符串或字节,如对象

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})

我已经重写了上面的内容,可以进行训练了。非常感谢。

最新更新