【问题标题】:xgboost sagemaker train failurexgboost sagemaker 火车故障
【发布时间】:2021-12-06 03:44:13
【问题描述】:

当我使用 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})

~/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/sagemaker/estimator.py in fit(自我,输入,等待,日志,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) 435返回名称 436 --> 437 self._ensure_base_job_name() 第438章 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 为无: --> 422 self.base_job_name = base_name_from_image(self.training_image_uri()) 423 第424章

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

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

TypeError:预期的字符串或类似字节的对象

【问题讨论】:

    标签: xgboost amazon-sagemaker


    【解决方案1】:
    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})
    

    我已按上述方式重写,可以进行训练。 谢谢!

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2015-04-03
    • 1970-01-01
    • 1970-01-01
    • 2020-06-10
    • 2018-12-06
    • 1970-01-01
    • 1970-01-01
    • 2022-10-14
    • 2015-07-19
    相关资源
    最近更新 更多