How to deploy an existing pytorch model previously trained with Amazon Sagemaker and stored in S3 bucket
I have trained a Pytorch model using SageMaker and the model is now stored in an S3 bucket.
I am trying to retrieve that model and deploying it.

This is the code I am using:

estimator = sagemaker.model.FrameworkModel(
    model_data= #link to  model location in s3
    image=  # image
    role=role,
    entry_point='train.py', 
    source_dir='pytorch_source',
    sagemaker_session = sagemaker_session
) 

predictor = estimator.deploy(initial_instance_count=1, instance_type="ml.p2.xlarge")


But after the deployment process (that seems to run smoothly), the predictor is just a NoneType.
I haven't found any weird message in the logs...

I have also made another attempt with the following code:

estimator = PyTorchModel(model_data= #link to model location in s3 
                             role=role,
                             image= #image
                             entry_point='pytorch_source/train.py',
                            predictor_cls = 'pytorch_source/train.py',
                           framework_version = '1.1.0')

predictor = estimator.deploy(initial_instance_count=1, instance_type="ml.p2.xlarge")


But it doesn't even complete the deployment.

Can anyone help with this?

I actually solved using PyTorchModel with the following settings:

estimator = PyTorchModel(model_data='#path to model, 
                             role=role,
                             source_dir='pytorch_source',
                             entry_point='deploy.py',
                            predictor_cls = ImgPredictor,
                           framework_version = '1.1.0')


where ImgPredictor is

from sagemaker.predictor import RealTimePredictor, json_deserializer

class ImgPredictor(RealTimePredictor):
    def __init__(self, endpoint_name, sagemaker_session):
        super(ImgPredictor, self).__init__(endpoint_name, sagemaker_session, content_type='application/x-image', 
                                           deserializer = json_deserializer ,accept='application/json')


and deploy.py contains the required functions input_fn, output_fn, model_fn and predict_fn.
Also, a requirements.txt file was missing in the source directory.
