SageMaker:TypeError:Join类型的对象不可JSON序列化



我正试图为计算机视觉模型构建一个SM管道。数据是存储在S3存储桶中的图像。我使用ScriptProcessor进行了预处理,现在正试图构建估计器。预处理工作正常。但是估计器部分给出了TypeError:Join类型的对象不是JSON可序列化的:error。

from sagemaker.tensorflow import TensorFlow

output_config = preprocessing_job_description["ProcessingOutputConfig"]
for output in output_config["Outputs"]:
if output["OutputName"] == "train_data":
preprocessed_training_data = output["S3Output"]["S3Uri"]
if output["OutputName"] == "valid_data":
preprocessed_test_data = output["S3Output"]["S3Uri"]
s3_train = "s3://bucketname/image_data/train/"
s3_val = "s3://bucketname/image_data/val/"

tf_estimator = TensorFlow(entry_point="train.py",
sagemaker_session=sess,
role=role,
instance_count=1, 
instance_type="ml.m5.xlarge",
# output_path = "/opt/ml/processing/output",
model_dir="s3://bucketname/image_data/output",
py_version='py37',
framework_version='2.4', 
hyperparameters={'epochs': epochs,
'learning_rate': learning_rate, 
'train_batch_size': 64,
},
metric_definitions=metrics_definitions,
script_mode=True,
max_run=7200 # max 2 hours * 60 minutes seconds per hour * 60 sec per minutes
)
tf_estimator.fit({"train": preprocessed_training_data})

这给了我以下错误:


TypeError Traceback(最近调用最后)36)37--->38 tf_estimator.fit({"train":预处理训练数据})39#tf_estimator.fit({"train":s3_train})

/opt/conda/lib/python3.7/site-packages/sagemaker/workflow/pipeline_context.py在包装器中(*args,**kwargs)207返回self-instance.sagemaker_session.conf208-->209返回run_func(*args,**kwargs)210211退货包装

/opt/conda/lib/python3.7/site-packages/sagemaker/estimator.py in适合(self、inputs、wait、logs、job_name、experiment_config)976自我_prepare_for_training(作业名称=作业名称)977-->978 self.latest_training_job=_TrainingJob.start_new(self,inputs,experiment_config)979 self.jobs.append(self.latest_training_job)980如果等待:

/opt/conda/lib/python3.7/site-packages/sagemaker/estimator.py instart_new(cls,估计器,输入,实验配置)1806
train_args=cls_get_train_args(估计器、输入、实验配置)1807->1808估计器.sagemaker_session.train(**train_args)1809 1810返回cls(估计器.semager_session,估计器_current_job_name)

/opt/conda/lib/python3.7/site-packages/sagemaker/session.py intrain(self、input_mode、input_config、role、job_name、output_config,resource_config,vpc_config,超参数,stop_condition,标记,metric_definitions、enable_network_isolation、image_uri、,algorithm_arn,encrypt_inter_container_traffic,use_spot_instances,checkpoint_s3_uri,checkpoint_local_path,experiment_config,debugger_rule_configs、debugger_hook_config、,tensorboard_output_config,enable_sanagemaker_metrics,profiler_rule_configs、profiler_config、环境、重试策略)592 encrypt_ inter_,593个use_ spot_,-->594校验点_ s3_,595 checkpoint_ cal_ path=checkpoint_,596实验配置=实验配置,

/opt/conda/lib/python3.7/site-packages/sagemaker/session.py in_intercept_create_request(self,request,create,func_name)4201"quot;4202 region=self.boto_session.reregion_->4203 sts_client=self.boto_session.client(4204"sts",region_name=region,endpoint_url=sts_regonal_endpoint(region)4205)

/opt/conda/lib/python3.7/site-packages/sagemaker/session.py in提交(请求)589 enable_ network_,590 image_ uri=image_,-->591算法arn=算法arn,592 encrypt_ inter_,593 use_spot_instances=use_spot-instances,

/转储中的opt/conda/lib/python3.7/json/init.py(obj、skipkeys、,ensure_ascii、check_c圆形、allow_nan、cls、缩进、分隔符、,默认,sort_keys,**kw)236 check_c圆形=check_c圆形,allow_nan=allow_nan,indent=indent,237个分隔符=分隔符,默认值=默认值,sort_keys=sort_keys,-->238**kw)。编码(obj)239240

/encode中的opt/conda/lib/python3.7/json/encoder.py(self,o)199个块=self.iterecode(o,_one_shot=True)200,如果不存在(块,(列表,元组)):-->201组块=列表(组块)202返回"。join(chunks)203

/iterencode(o,_current_indent_level)429来自_iterencode_list的收益率(o,_current_intent_level)430 elif isistance(o,dict):-->431来自_iterencode_dict(o,_current_intent_level)的收益率432其他:433如果标记不是无:

/interencode_dict(dct,_current_indent_level)403其他:404块=_iterencode(值,_current_intent_level)-->405块产量406如果newline_indent不是None:407 _当前_缩进_级别-=1

/interencode_dict(dct,_current_indent_level)403其他:404块=_iterencode(值,_current_intent_level)-->405块产量406如果newline_indent不是None:407 _当前_缩进_级别-=1

/iterencode(o,_current_indent_level)436升高ValueError("检测到循环引用")437个标记[markrid]=o-->438 o=_default(o)439来自_iterencode的收益率(o,_current_intent_level)440如果标记不是无:

/默认情况下为opt/conda/lib/python3.7/json/encoder.py(self,o)177178〃"quot;-->179引发TypeError(f'类型为{o..名称}的对象'180 f"不可JSON序列化")181

TypeError:Join类型的对象不是JSON可序列化的

我已经尝试更改我为估计器给出的所有参数。有时启用它们,有时禁用它们。-->594校验点_ s3_,如果这是起源,我也试着给出它。

不知道我在哪里搞砸了。我正在使用

sagemaker 2.94.0
Python3 Data Science kernel
boto3 '1.24.8'

也许,尝试使用PipelineSession而不是普通的会话对象:

from sagemaker.workflow.pipeline_context import PipelineSession
tf_estimator = TensorFlow(entry_point="train.py",
sagemaker_session=PipelineSession()
)

https://github.com/aws/sagemaker-python-sdk/issues/3860

最新更新