You should just load the different models, add them to the application as global variables as indicated below:
# Create Flask application and initialize Keras model
app = flask.Flask(__name__)
app.config['modelA'] = load_model("modelAPath")
app.config['modelB'] = load_model("modelAPath")
# also create two separate graphs for each model.
app.config['graphA'] = tf.Graph()
app.config['graphB'] = tf.Graph()
Then have respective endpoints for each model for instance:
@app.route("/predictA", methods =["POST"])
def predictA():
# get the data here, feed to the model and return json results.
with app.config['graphA'].as_default():
app.config['modelA'].predict()
@app.route("/predictB", methods =["POST"])
def predictB():
# get the data here, feed to the model and return json results.
with app.config['graphB'].as_default():
app.config['modelB'].predict()
Note that this is based on you wanting two separate endpoints, whereas you could do this with one too, using an extra "POST"ed form or json argument to select a model.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…