如何从端点内访问sagemaker模型注册中心指标



我正在尝试使用amazon sagemaker来构建一个点,以便我可以从训练过的模型中进行推断。我正在使用的模型位于模型注册表中,并且具有与之关联的度量。我希望端点返回具有两列['model r2', 'model_prediction']的数据框。我目前已经使用https://github.com/aws/sagemaker-inference-toolkit成功构建并查询了一个给出"model_prediction"的端点。但是,我不知道如何访问端点模型的"模型质量"。指标。模型r2存储在"模型质量"中。模型注册表中模型版本的部分,我可以看到sagemaker studio中的值。我觉得可能有1-2行代码来返回这个值,但我在sagemaker文档中找不到任何东西。我想要在InferenceHandler

中看起来像这样
# See https://github.com/aws/sagemaker-inference-toolkit for more details on implementing a handler.
class InferenceHandler(DefaultInferenceHandler):
def default_model_fn(self, model_dir):
"""
Deserialize and return fitted model.
"""
model = joblib.load(model_dir+"/model.joblib")
return model
#raise NotImplementedError
def default_predict_fn(self, input_data, model):
"""
SageMaker model server invokes `predict_fn` on the return value of `input_fn`.
Args:
input_data
model
Returns: predictions based on the input data using the fitted model
"""
output = model.predict(features)
##### HERE
model_metric = model.model_metrics['r2']
###### HERE
return pd.DataFrame({'model_r2':model_metric, 'model_prediction':output})

我尝试搜索sagemaker文档,但无法找到解决方案

您可以调用DescribeModelPackageAPI来获取模型度量- https://docs.aws.amazon.com/cli/latest/reference/sagemaker/describe-model-package.html

最新更新