Closed andreassilva closed 6 years ago
Are you using threads? I think you must keep the same graphs for all inferences, or you will need to load the network everytime. If you are using threads you can pass a reference from actual session to thread function in order to keep the same session inside the thread.
something like this:
foo(net,session, **kwargs):
with session:
net.predict(predict_something)
Hi thank you for your response.
I am using threads. I don't mind loading the network on each start, in fact I prefer that way. My problem is that I'm not being able to load it on the second start.
The following code only runs fine on the first start.
yolo = YOLO(backend = yolo_config['model']['backend'],
input_size = yolo_config['model']['input_size'],
labels = yolo_config['model']['labels'],
max_box_per_image = yolo_config['model']['max_box_per_image'],
anchors = yolo_config['model']['anchors'])
What and how do I free the previous one, so I can init yolo again?
import tensorflow as tf
yolo = YOLO(backend = yolo_config['model']['backend'],
input_size = yolo_config['model']['input_size'],
labels = yolo_config['model']['labels'],
max_box_per_image = yolo_config['model']['max_box_per_image'],
anchors = yolo_config['model']['anchors'])
graph = tf.get_default_graph()
def foo(yolo,graph):
with graph.as_default():
yolo.predict(example_image)
I did something like this in my code, doing that I can pass the foo function into a thread and use the model without problems
I solved it by calling
from keras import backend as K
...
K.clear_session()
hi andreassilva can you leave your code here ?
Hi there,
I have a little Kivy app which has a button to start and stop reading frames from a camera and then predict from them.
The program runs fine on the first time, but when I start the prediction the second time I get the following error: Note: on each start I init YOLO
... File "...../venv/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 900, in run run_metadata_ptr) File "...../venv/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1079, in _run 'Cannot interpret feed_dict key as Tensor: ' + e.args[0]) TypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("Placeholder:0", shape=(3, 3, 3, 32), dtype=float32) is not an element of this graph.
Assuming that my problem is that I did not close the previous session, how do I do that with keras-yolo2?
Regards,