ValueError: Tensor when hosting a model in Sagemaker with Gunicorn and Flask

1533 views amazon-web-services
3

I created a time series predictor with Keras and Dockerized the model with with Flash and Gunicorn as per AWS docs. I am loading the serialized model with this code.

@classmethod
def get_model(cls):
    if cls.model == None:
        cls.model = load_model('/opt/ml/bitcoin_model.h5')
    return cls.model

Then I used the predict method to produce the results , the dockerized container is working perfectly in the local environment , but when I try to host the model in sagemaker it produces this error.

ValueError: Tensor Tensor("dense_1/BiasAdd:0", shape=(?, 1), dtype=float32) is not an element of this graph.

So how can I resolve this issue ?

answered question

1 Answer

2

The issue was resolved by calling _make_predict_function() method in the model load phase.

@classmethod
def get_model(cls):
    if cls.model == None:
        cls.model = load_model('/opt/ml/bitcoin_model.h5')
        cls.model._make_predict_function()
    return cls.model

Bug Reference : https://github.com/keras-team/keras/issues/6462

posted this

Have an answer?

JD

Please login first before posting an answer.