Closed WheaTex closed 3 years ago
This appears to be due to the removal of the methods in version 2.x of the SageMaker:
content_type and accept in the Predictor Constructor
The content_type and accept parameters are now no-ops in the following classes and methods:
sagemaker.predictor.Predictor
sagemaker.estimator.Estimator.create_model
sagemaker.algorithms.AlgorithmEstimator.create_model
sagemaker.tensorflow.model.TensorFlowPredictor
Please specify content types in a serializer or deserializer class instead.
You need to specify the serializer and deserializer in the deploy method instead.
Here is a sample code:
from sagemaker.deserializers import JSONDeserializer
from sagemaker.serializers import JSONSerializer
class FMSerializer(JSONSerializer):
def serialize(self, data):
js = {'instances': []}
for row in data:
js['instances'].append({'features': row.tolist()})
return json.dumps(js)
predictor = estimator.deploy(
initial_instance_count=1,
instance_type="ml.m4.xlarge",
serializer=FMSerializer(),
deserializer= JSONDeserializer()
)
That's correct. Fixing these is on my to do list, once AWS re:Invent is out the way :)
Fixed.
In Chapter 4, Factorization Machines Notebook in the "Deploy Model" section there is an issue after creating the endpoint. While attempting to run this code:
'fm_predictor.content_type = "application/json" '
You get this error; 'AttributeError: can't set attribute'
If you try to comment it out & run the next block of code you get this error: 'AttributeError: "function" object has no attribute "CONTENT_TYPE"'
I attempted to follow @laurenyu's feedback: https://github.com/aws/sagemaker-python-sdk/issues/1126 but that code doesn't appear to work. Please advise.