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년 전2496회 조회
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년 전
profile picture
전문가
검토됨 15일 전
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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠