Forums

Error running WSGI application OSError: SavedModel file does not exist at: saved_model.h5/{saved_model.pbtxt|saved_model.pb}

Hello, I am having an issue when trying to load a keras model from html frontend when posting to flask. The flask_app code is the following:

from tensorflow.keras.models import load_model

app = Flask(name)

def get_model():

global model

model = load_model('saved_model.h5')

print(" * Model loaded!")

get_model()

@app.route('/', methods=["POST"])

def hello_world(): …..

When I am running from console it runs fine but when trying to run from html I get the following: jquery-3.3.1.min.js:2 POST http://myusername.pythonanywhere.com/ 500 (Internal Server Error)

Error running WSGI application OSError: SavedModel file does not exist at: saved_model.h5/{saved_model.pbtxt|saved_model.pb}

Could you please help me?

You're using a relative path name without paying attention to the working directory. See http://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/ for how to deal with that.

Hello again! Thanks for the response it was solved! But now i am dealing with another issue if you could help me.. I am using the aforementioned model to make a prediction, and pass it to the html page:

Flask:

predictions = model.predict([input1, input2]).tolist()
response = {
    'predictions': {
        'rating': predictions
    }
}
return jsonify(response)

HTML:

$.post("http://username.pythonanywhere.com/", JSON.stringify(message), function(response){ $("#rating-prediction").text(response.predictions.rating); console.log(response); });

The above code works perfectly in localserver but in pythonanywhere it hangs for some minutes and then i get the error Error code: 504-backend..

Is it not possible to run a tf keras trained model in pythonanywhere?

Have a look at http://help.pythonanywhere.com/pages/MachineLearningInWebsiteCode/