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
gefragt vor 5 Jahren2516 Aufrufe
3 Antworten
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!

beantwortet vor 5 Jahren
profile picture
EXPERTE
überprüft vor 24 Tagen
0

Thank you. This solution worked!

hadi86
beantwortet vor 5 Jahren
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.

beantwortet vor 3 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen