loading and deploying a previously trained sagemaker xgboost model

0

I am trying to write an inference pipeline where I load a previously trained sagemaker xgboost model stored in s3 as a tar.gz file (following sagemaker tutorial) and deploy it as an endpoint for prediction. Here is my code:

trainedmodel = sagemaker.model.Model(    
    model_data='data-path-to-my-model-in-s3/model.tar.gz',
    image=container,  
    role=role)  

xgb_predictor = trainedmodel.deploy(initial_instance_count=1, instance_type='ml.m4.xlarge')

The code runs fine but after that when I try to call predict() on xgb_predictor I get an error saying 'NoneType' object has no attribute 'predict'. I followed the example here to train the xgboost model:

https://aws.amazon.com/blogs/machine-learning/simplify-machine-learning-with-xgboost-and-amazon-sagemaker/

Why am I getting this error? What's the correct way to load a previously trained model? Help would be appreciated.

hadi86
已提问 5 年前2444 查看次数
3 回答
0

thanks for using SageMaker! you're on the right path - you'll need to pass in an argument for "predictor_cls" when creating your Model instance in order for a predictor object to be returned after calling deploy(), e.g.

from sagemaker.model import Model
from sagemaker.predictor import RealTimePredictor, csv_serializer, csv_deserializer

class Predictor(RealTimePredictor):
    def __init__(self, endpoint_name, sagemaker_session=None):
        super(Predictor, self).__init__(
            endpoint_name, sagemaker_session, csv_serializer, csv_deserializer
        )

trainedmodel = Model(..., predictor_cls=Predictor)
xgb_predictor = trainedmodel.deploy(...)

xgb_predictor.predict(...)

API reference:

hope that helps!

已回答 5 年前
0

Thank you. This solution worked!

hadi86
已回答 5 年前
0

Any special reason for using csv serializer/deserializer? In my case I reload a model to analyze videos (frames in numpy array actually). What serializer/deserializer should I use?
Actually, any doc regarding how to properly use the argument predictor_cls would be highly appreicated.

已回答 3 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则