Load keras model and cache it in a variable without having to reloadValueError: Tensor 'A' must be from the same graph as Tensor 'B'Load the model and predict with keras and tensorflowTensor is not an element of this graph; deploying Keras modelInstantiate VGG model for once only in Keras when predicting continuously?Concatening Attention layer with decoder input seq2seq model on KerasKeras load model problem using Cannot interpret feed_dict key as Tensor threadingHow to use multiple keras models in a single thread?Got error: Output tensors to a Model must be the output of a Keras `Layer`The initial state or constants of an RNN layer cannot be specified with a mix of Keras tensors and non-Keras tensorsGraph Disconnected when trying to build CNN model with Keras Functional API
New coworker has strange workplace requirements - how should I deal with them?
What is the practical impact of using System.Random which is not cryptographically random?
How to Flip Rotation from Positive to Negative?
Why doesn't Starship have four landing legs?
Understanding data transmission rates over copper wire
Cheap oscilloscope showing 16 MHz square wave
How do I get my neighbour to stop disturbing with loud music?
Does FERPA require parental notification of disability assessment?
Can authors email you PDFs of their textbook for free?
How can I improve my formal definitions?
What's the origin of the concept of alternate dimensions/realities?
IList<T> implementation
I failed to respond to a potential advisor
What caused the end of cybernetic implants?
Quick Tilepaint Puzzles: Corridors and Corners
Is Borg adaptation only temporary?
'Horseshoes' for Deer?
Heuristic argument for the Riemann Hypothesis
Can the inductive kick be discharged without a freewheeling diode, in this example?
Do universities maintain secret textbooks?
Moscow SVO airport, how to avoid scam taxis without pre-booking?
Sum and average calculator
What was Captain Marvel supposed to do once she reached her destination?
Padding a column of lists
Load keras model and cache it in a variable without having to reload
ValueError: Tensor 'A' must be from the same graph as Tensor 'B'Load the model and predict with keras and tensorflowTensor is not an element of this graph; deploying Keras modelInstantiate VGG model for once only in Keras when predicting continuously?Concatening Attention layer with decoder input seq2seq model on KerasKeras load model problem using Cannot interpret feed_dict key as Tensor threadingHow to use multiple keras models in a single thread?Got error: Output tensors to a Model must be the output of a Keras `Layer`The initial state or constants of an RNN layer cannot be specified with a mix of Keras tensors and non-Keras tensorsGraph Disconnected when trying to build CNN model with Keras Functional API
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Loading a model at the beggining of my Flask application and then using it for predictions in my endpoints results in an error
'ValueError: Tensor Tensor("dense/Softmax:0", shape=(?, 4), dtype=float32) is not an element of this graph.'
model = keras.models.load_model("model.h5")
@app.route("/predict", methods=["POST"])
def predict():
json_data = request.get_json()
variable = preparePredictionInput(
[variable], alphabetDict, maxVariableLength)
prediction = list(model.predict(variable, steps=1, verbose=1)[0])
but loading keras model every time the prediction endpoint is called seems to be working perfectly
@app.route("/predict", methods=["POST"])
def predict():
json_data = request.get_json()
model = keras.models.load_model("model.h5")
variable = preparePredictionInput(
[variable], alphabetDict, maxVariableLength)
prediction = list(model.predict(variable, steps=1, verbose=1)[0])
is there a way to fix this? this quite radically reduces the performance having to reload the model every time.
python tensorflow keras
add a comment |
Loading a model at the beggining of my Flask application and then using it for predictions in my endpoints results in an error
'ValueError: Tensor Tensor("dense/Softmax:0", shape=(?, 4), dtype=float32) is not an element of this graph.'
model = keras.models.load_model("model.h5")
@app.route("/predict", methods=["POST"])
def predict():
json_data = request.get_json()
variable = preparePredictionInput(
[variable], alphabetDict, maxVariableLength)
prediction = list(model.predict(variable, steps=1, verbose=1)[0])
but loading keras model every time the prediction endpoint is called seems to be working perfectly
@app.route("/predict", methods=["POST"])
def predict():
json_data = request.get_json()
model = keras.models.load_model("model.h5")
variable = preparePredictionInput(
[variable], alphabetDict, maxVariableLength)
prediction = list(model.predict(variable, steps=1, verbose=1)[0])
is there a way to fix this? this quite radically reduces the performance having to reload the model every time.
python tensorflow keras
add a comment |
Loading a model at the beggining of my Flask application and then using it for predictions in my endpoints results in an error
'ValueError: Tensor Tensor("dense/Softmax:0", shape=(?, 4), dtype=float32) is not an element of this graph.'
model = keras.models.load_model("model.h5")
@app.route("/predict", methods=["POST"])
def predict():
json_data = request.get_json()
variable = preparePredictionInput(
[variable], alphabetDict, maxVariableLength)
prediction = list(model.predict(variable, steps=1, verbose=1)[0])
but loading keras model every time the prediction endpoint is called seems to be working perfectly
@app.route("/predict", methods=["POST"])
def predict():
json_data = request.get_json()
model = keras.models.load_model("model.h5")
variable = preparePredictionInput(
[variable], alphabetDict, maxVariableLength)
prediction = list(model.predict(variable, steps=1, verbose=1)[0])
is there a way to fix this? this quite radically reduces the performance having to reload the model every time.
python tensorflow keras
Loading a model at the beggining of my Flask application and then using it for predictions in my endpoints results in an error
'ValueError: Tensor Tensor("dense/Softmax:0", shape=(?, 4), dtype=float32) is not an element of this graph.'
model = keras.models.load_model("model.h5")
@app.route("/predict", methods=["POST"])
def predict():
json_data = request.get_json()
variable = preparePredictionInput(
[variable], alphabetDict, maxVariableLength)
prediction = list(model.predict(variable, steps=1, verbose=1)[0])
but loading keras model every time the prediction endpoint is called seems to be working perfectly
@app.route("/predict", methods=["POST"])
def predict():
json_data = request.get_json()
model = keras.models.load_model("model.h5")
variable = preparePredictionInput(
[variable], alphabetDict, maxVariableLength)
prediction = list(model.predict(variable, steps=1, verbose=1)[0])
is there a way to fix this? this quite radically reduces the performance having to reload the model every time.
python tensorflow keras
python tensorflow keras
asked Mar 27 at 13:41
HigeathHigeath
361 silver badge6 bronze badges
361 silver badge6 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Semms like your model variable is not global. Have a look at the below code:
def init():
global model
model = lkeras.models.load_model("model.h5")
@app.route("/predict", methods=["POST"])
def predict():
json_data = request.get_json()
variable = preparePredictionInput([variable], alphabetDict, maxVariableLength)
prediction = list(model.predict(variable, steps=1, verbose=1)[0])
if __name__ == "__main__":
init()
app.run()
It is assigned in global context, it is global..
– Higeath
Mar 29 at 18:14
Did you try the code?
– stacklikemind
Mar 30 at 10:48
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55378692%2fload-keras-model-and-cache-it-in-a-variable-without-having-to-reload%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Semms like your model variable is not global. Have a look at the below code:
def init():
global model
model = lkeras.models.load_model("model.h5")
@app.route("/predict", methods=["POST"])
def predict():
json_data = request.get_json()
variable = preparePredictionInput([variable], alphabetDict, maxVariableLength)
prediction = list(model.predict(variable, steps=1, verbose=1)[0])
if __name__ == "__main__":
init()
app.run()
It is assigned in global context, it is global..
– Higeath
Mar 29 at 18:14
Did you try the code?
– stacklikemind
Mar 30 at 10:48
add a comment |
Semms like your model variable is not global. Have a look at the below code:
def init():
global model
model = lkeras.models.load_model("model.h5")
@app.route("/predict", methods=["POST"])
def predict():
json_data = request.get_json()
variable = preparePredictionInput([variable], alphabetDict, maxVariableLength)
prediction = list(model.predict(variable, steps=1, verbose=1)[0])
if __name__ == "__main__":
init()
app.run()
It is assigned in global context, it is global..
– Higeath
Mar 29 at 18:14
Did you try the code?
– stacklikemind
Mar 30 at 10:48
add a comment |
Semms like your model variable is not global. Have a look at the below code:
def init():
global model
model = lkeras.models.load_model("model.h5")
@app.route("/predict", methods=["POST"])
def predict():
json_data = request.get_json()
variable = preparePredictionInput([variable], alphabetDict, maxVariableLength)
prediction = list(model.predict(variable, steps=1, verbose=1)[0])
if __name__ == "__main__":
init()
app.run()
Semms like your model variable is not global. Have a look at the below code:
def init():
global model
model = lkeras.models.load_model("model.h5")
@app.route("/predict", methods=["POST"])
def predict():
json_data = request.get_json()
variable = preparePredictionInput([variable], alphabetDict, maxVariableLength)
prediction = list(model.predict(variable, steps=1, verbose=1)[0])
if __name__ == "__main__":
init()
app.run()
answered Mar 27 at 23:32
stacklikemindstacklikemind
1661 silver badge10 bronze badges
1661 silver badge10 bronze badges
It is assigned in global context, it is global..
– Higeath
Mar 29 at 18:14
Did you try the code?
– stacklikemind
Mar 30 at 10:48
add a comment |
It is assigned in global context, it is global..
– Higeath
Mar 29 at 18:14
Did you try the code?
– stacklikemind
Mar 30 at 10:48
It is assigned in global context, it is global..
– Higeath
Mar 29 at 18:14
It is assigned in global context, it is global..
– Higeath
Mar 29 at 18:14
Did you try the code?
– stacklikemind
Mar 30 at 10:48
Did you try the code?
– stacklikemind
Mar 30 at 10:48
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55378692%2fload-keras-model-and-cache-it-in-a-variable-without-having-to-reload%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown