[英]How to access sagemaker model registry metrics from within the endpoint
我正在尝试使用 amazon sagemaker 构建一个 enpoint,以便我可以从训练有素的模型中进行推断。 我正在使用的模型位于模型注册表中,并具有与之关联的指标。 我希望端点返回一个包含两列 ['model r2', 'model_prediction'] 的数据框。 我目前已经使用https://github.com/aws/sagemaker-inference-toolkit成功构建并查询了一个给出“model_prediction”的点。 但是,我不知道如何访问 enpoint 模型的“模型质量”指标。 模型 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 文档但找不到解决方案
您可以调用DescribeModelPackage
API 来获取模型指标 - https://docs.aws.amazon.com/cli/latest/reference/sagemaker/describe-model-package.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.