I'm trying to build SageMaker Pipeline based on Tensorflow framework. I have only Training, Evaluating steps, and Register model. On the evaluation step I declared MetricsSource
for ModelMetrics
and received an error.
Code is below:
pipeline_model = PipelineModel(
models=[tf_model],
role=role,
sagemaker_session=sagemaker_session
)
eval_res = step_evaluate_model.arguments['ProcessingOutputConfig']['Outputs'][0]['S3Output']['S3Uri']
evaluation_s3_uri = f'{eval_res}/evaluation.json'
model_statistics=MetricsSource(
s3_uri=evaluation_s3_uri,
content_type='application/json')
model_metrics = ModelMetrics(model_statistics=model_statistics)
step_register_pipeline_model = pipeline_model.register(
content_types=['application/json'],
response_types=['application/json'],
inference_instances=['ml.m4.xlarge','ml.c5.2xlarge'],
transform_instances=['ml.c5.2xlarge'],
model_package_group_name=model_package_group_name,
model_metrics=model_metrics,
approval_status=model_approval_status.default_value,
)
Error:
TypeError Traceback (most recent call last)
Input In [17], in <cell line: 17>()
14 model_metrics = ModelMetrics(model_statistics=model_statistics)
15 # print('\n',pipeline_model)
---> 17 step_register_pipeline_model = pipeline_model.register(
18 content_types=['application/json'],
19 response_types=['application/json'],
20 inference_instances=['ml.m4.xlarge','ml.c5.2xlarge'],
21 transform_instances=['ml.c5.2xlarge'],
22 model_package_group_name=model_package_group_name,
23 model_metrics=model_metrics,
24 approval_status=model_approval_status.default_value,
25 )
TypeError: Pipeline variables do not support __str__ operation. Please use `.to_string()` to convert it to string type in execution timeor use `.expr` to translate it to Json for display purpose in Python SDK.
Could you please help me to solve it? I'd appreciate for any idea. Thanks
They way to create model and register model on Pipelines has changed slightly with the introduction of ModelStep, also the instantiation of session_pipeline is needed. Similarly, ModelStep will be used for registering the model .
Reference: https://github.com/aws/sagemaker-python-sdk/pull/3076
Examples : https://sagemaker.readthedocs.io/en/stable/workflows/pipelines/sagemaker.workflow.pipelines.html?highlight=ModelStep#sagemaker.workflow.model_step.ModelStep