Best way to load model tensorflow












0














I want to ask that how to load model 1 time and use this to predict a lot of time?



HERE IS CODE



`class CLASSIFY(object):
cls_model = None
def Classification_model(self, img):
with tf.Session(graph=graph) as sess:
if not self.cls_model:
print("load model classify")
self.cls_model = load_model(
"C:\Users\BootAI\Desktop\hensolt_13_11\Hensoldt_ServerDetect_deadline\model\model_data/model.h5",
compile=False)
x = self.cls_model.predict(img)
z = self.cls_model.predict_classes(img)


`


Can you see cls_model. In the first call Classification_model. It's work but in the second it got error:



`Traceback (most recent call last):
File "C:UsersBootAIAppDataLocalProgramsPythonPython36libthreading.py", line 916, in _bootstrap_inner
self.run()
File "C:UsersBootAIAppDataLocalProgramsPythonPython36libthreading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_ServerDetect_deadlineappdrone_detection.py", line 30, in detect_drone
data = predict_stack(stack_img, frame_id, list_path)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_ServerDetect_deadlineappdrone_detection.py", line 36, in predict_stack
out_classes, out_scores, out_boxes = yolo.detect_image2(stack_data, list_path)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_ServerDetect_deadlinemodelRunModel.py", line 318, in detect_image2
pred, predclass = self.Classification_model(img)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_ServerDetect_deadlinemodelRunModel.py", line 173, in Classification_model
x = self.cls_model.predict(img)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packageskerasenginetraining.py", line 1169, in predict
steps=steps)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packageskerasenginetraining_arrays.py", line 294, in predict_loop
batch_outs = f(ins_batch)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packageskerasbackendtensorflow_backend.py", line 2715, in call
return self._call(inputs)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packageskerasbackendtensorflow_backend.py", line 2675, in _call
fetched = self._callable_fn(*array_vals)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packagestensorflowpythonclientsession.py", line 1439, in call
run_metadata_ptr)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packagestensorflowpythonframeworkerrors_impl.py", line 528, in exit
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value conv2d/kernel
[[{{node conv2d/kernel/read}} = IdentityT=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]]
[[{{node dense_1/Softmax/_11}} = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_114_dense_1/Softmax", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]]



`










share|improve this question






















  • Why are you mixing TF and Keras? Just using Keras and load_model should just work.
    – Matias Valdenegro
    Nov 23 at 9:46
















0














I want to ask that how to load model 1 time and use this to predict a lot of time?



HERE IS CODE



`class CLASSIFY(object):
cls_model = None
def Classification_model(self, img):
with tf.Session(graph=graph) as sess:
if not self.cls_model:
print("load model classify")
self.cls_model = load_model(
"C:\Users\BootAI\Desktop\hensolt_13_11\Hensoldt_ServerDetect_deadline\model\model_data/model.h5",
compile=False)
x = self.cls_model.predict(img)
z = self.cls_model.predict_classes(img)


`


Can you see cls_model. In the first call Classification_model. It's work but in the second it got error:



`Traceback (most recent call last):
File "C:UsersBootAIAppDataLocalProgramsPythonPython36libthreading.py", line 916, in _bootstrap_inner
self.run()
File "C:UsersBootAIAppDataLocalProgramsPythonPython36libthreading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_ServerDetect_deadlineappdrone_detection.py", line 30, in detect_drone
data = predict_stack(stack_img, frame_id, list_path)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_ServerDetect_deadlineappdrone_detection.py", line 36, in predict_stack
out_classes, out_scores, out_boxes = yolo.detect_image2(stack_data, list_path)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_ServerDetect_deadlinemodelRunModel.py", line 318, in detect_image2
pred, predclass = self.Classification_model(img)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_ServerDetect_deadlinemodelRunModel.py", line 173, in Classification_model
x = self.cls_model.predict(img)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packageskerasenginetraining.py", line 1169, in predict
steps=steps)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packageskerasenginetraining_arrays.py", line 294, in predict_loop
batch_outs = f(ins_batch)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packageskerasbackendtensorflow_backend.py", line 2715, in call
return self._call(inputs)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packageskerasbackendtensorflow_backend.py", line 2675, in _call
fetched = self._callable_fn(*array_vals)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packagestensorflowpythonclientsession.py", line 1439, in call
run_metadata_ptr)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packagestensorflowpythonframeworkerrors_impl.py", line 528, in exit
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value conv2d/kernel
[[{{node conv2d/kernel/read}} = IdentityT=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]]
[[{{node dense_1/Softmax/_11}} = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_114_dense_1/Softmax", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]]



`










share|improve this question






















  • Why are you mixing TF and Keras? Just using Keras and load_model should just work.
    – Matias Valdenegro
    Nov 23 at 9:46














0












0








0







I want to ask that how to load model 1 time and use this to predict a lot of time?



HERE IS CODE



`class CLASSIFY(object):
cls_model = None
def Classification_model(self, img):
with tf.Session(graph=graph) as sess:
if not self.cls_model:
print("load model classify")
self.cls_model = load_model(
"C:\Users\BootAI\Desktop\hensolt_13_11\Hensoldt_ServerDetect_deadline\model\model_data/model.h5",
compile=False)
x = self.cls_model.predict(img)
z = self.cls_model.predict_classes(img)


`


Can you see cls_model. In the first call Classification_model. It's work but in the second it got error:



`Traceback (most recent call last):
File "C:UsersBootAIAppDataLocalProgramsPythonPython36libthreading.py", line 916, in _bootstrap_inner
self.run()
File "C:UsersBootAIAppDataLocalProgramsPythonPython36libthreading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_ServerDetect_deadlineappdrone_detection.py", line 30, in detect_drone
data = predict_stack(stack_img, frame_id, list_path)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_ServerDetect_deadlineappdrone_detection.py", line 36, in predict_stack
out_classes, out_scores, out_boxes = yolo.detect_image2(stack_data, list_path)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_ServerDetect_deadlinemodelRunModel.py", line 318, in detect_image2
pred, predclass = self.Classification_model(img)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_ServerDetect_deadlinemodelRunModel.py", line 173, in Classification_model
x = self.cls_model.predict(img)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packageskerasenginetraining.py", line 1169, in predict
steps=steps)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packageskerasenginetraining_arrays.py", line 294, in predict_loop
batch_outs = f(ins_batch)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packageskerasbackendtensorflow_backend.py", line 2715, in call
return self._call(inputs)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packageskerasbackendtensorflow_backend.py", line 2675, in _call
fetched = self._callable_fn(*array_vals)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packagestensorflowpythonclientsession.py", line 1439, in call
run_metadata_ptr)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packagestensorflowpythonframeworkerrors_impl.py", line 528, in exit
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value conv2d/kernel
[[{{node conv2d/kernel/read}} = IdentityT=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]]
[[{{node dense_1/Softmax/_11}} = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_114_dense_1/Softmax", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]]



`










share|improve this question













I want to ask that how to load model 1 time and use this to predict a lot of time?



HERE IS CODE



`class CLASSIFY(object):
cls_model = None
def Classification_model(self, img):
with tf.Session(graph=graph) as sess:
if not self.cls_model:
print("load model classify")
self.cls_model = load_model(
"C:\Users\BootAI\Desktop\hensolt_13_11\Hensoldt_ServerDetect_deadline\model\model_data/model.h5",
compile=False)
x = self.cls_model.predict(img)
z = self.cls_model.predict_classes(img)


`


Can you see cls_model. In the first call Classification_model. It's work but in the second it got error:



`Traceback (most recent call last):
File "C:UsersBootAIAppDataLocalProgramsPythonPython36libthreading.py", line 916, in _bootstrap_inner
self.run()
File "C:UsersBootAIAppDataLocalProgramsPythonPython36libthreading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_ServerDetect_deadlineappdrone_detection.py", line 30, in detect_drone
data = predict_stack(stack_img, frame_id, list_path)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_ServerDetect_deadlineappdrone_detection.py", line 36, in predict_stack
out_classes, out_scores, out_boxes = yolo.detect_image2(stack_data, list_path)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_ServerDetect_deadlinemodelRunModel.py", line 318, in detect_image2
pred, predclass = self.Classification_model(img)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_ServerDetect_deadlinemodelRunModel.py", line 173, in Classification_model
x = self.cls_model.predict(img)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packageskerasenginetraining.py", line 1169, in predict
steps=steps)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packageskerasenginetraining_arrays.py", line 294, in predict_loop
batch_outs = f(ins_batch)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packageskerasbackendtensorflow_backend.py", line 2715, in call
return self._call(inputs)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packageskerasbackendtensorflow_backend.py", line 2675, in _call
fetched = self._callable_fn(*array_vals)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packagestensorflowpythonclientsession.py", line 1439, in call
run_metadata_ptr)
File "C:UsersBootAIDesktophensolt_13_11Hensoldt_orchestratorvenv1libsite-packagestensorflowpythonframeworkerrors_impl.py", line 528, in exit
c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value conv2d/kernel
[[{{node conv2d/kernel/read}} = IdentityT=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]]
[[{{node dense_1/Softmax/_11}} = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_114_dense_1/Softmax", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"]]



`







python tensorflow keras






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 at 4:42









Quang Huy Nguyễn

11




11












  • Why are you mixing TF and Keras? Just using Keras and load_model should just work.
    – Matias Valdenegro
    Nov 23 at 9:46


















  • Why are you mixing TF and Keras? Just using Keras and load_model should just work.
    – Matias Valdenegro
    Nov 23 at 9:46
















Why are you mixing TF and Keras? Just using Keras and load_model should just work.
– Matias Valdenegro
Nov 23 at 9:46




Why are you mixing TF and Keras? Just using Keras and load_model should just work.
– Matias Valdenegro
Nov 23 at 9:46

















active

oldest

votes











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440742%2fbest-way-to-load-model-tensorflow%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440742%2fbest-way-to-load-model-tensorflow%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks