在 sagemaker 中创建 catboost 模型非常简单。
tabular_estimator = Estimator( role=sagemaker_role, image_uri=train_image_uri, etc )
.但是,一旦我这样做了,就很难再做其他事情了。就我而言,我希望在端点收到请求后对其进行一些预处理。
例如,如果有人发送:
{ model: 'endpoint_001', body: ["cow", "cow", "pig"]}
如何找到插入 python 脚本的正确位置,用该脚本将请求转换为正确的结构,又名,
{ model: 'endpoint_001', body: ["1", "1", "2"]}
.
模型期望什么?
我尝试过查看大量过时的、杂乱无章的 AWS 文档。
在此脚本中,定义一个函数来接受输入请求并执行所需的转换。将此脚本保存为例如 preprocess.py。
def preprocess_request(request):
# Your custom logic to transform input strings to numerical values
为 CatBoost 模型创建“估算器”时,请确保包含 preprocess.py 脚本。
tabular_estimator = Estimator(
role=sagemaker_role,
image_uri=train_image_uri,
entry_point='preprocess.py', # Specify the name of your preprocessing script
# other parameters...
)
您可以利用“input_fn”函数对端点应用预处理。此功能允许您自定义传入请求在传递给模型之前的处理方式。
from preprocess import preprocess_request
def input_fn(request_body, request_content_type):
# Perform preprocessing on the request_body
processed_body = preprocess_request(request_body)
# Return the processed input in the format expected by your model
return processed_body, request_content_type
像以前一样使用更新后的 input_fn 部署模型。
希望这是找到一些信息,如果内容超出了内容,请告诉我需要什么。