keras-yolo3: TypeError: Cannot interpret feed_dict key as Tensor
Ive been receiving this error
TypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("keras_learning_phase:0", shape=(), dtype=bool) is not an element of this graph. Aborted (core dumped)
as a result of running this section of code in line 116 of the yolo object file
out_boxes, out_scores, out_classes = self.sess.run( [self.boxes, self.scores, self.classes], feed_dict={ self.yolo_model.input: image_data, self.input_image_shape: [image.size[1], image.size[0]], K.learning_phase(): 0 })
I’m not sure if its a tensorflow dependency issue or an issue with my input image, but any help solving it would be greatly appreciated
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 3
- Comments: 17
Commits related to this issue
- TypeError: Cannot interpret feed_dict key as Tensor エラーが出るようになったため、下記を参考に対応 https://github.com/qqwweee/keras-yolo3/issues/251 — committed to osscat/DensityCalculator by nakanin 4 years ago
two step to solve this problem: (1) modify the “init(self, **kwargs)” method: def init(self, **kwargs): self.dict.update(self._defaults) # set up default values self.dict.update(kwargs) # and update with user overrides self.class_names = self._get_class() self.anchors = self._get_anchors() self.sess = K.get_session() with self.sess.as_default(): with self.sess.graph.as_default(): self.K_learning_phase = K.learning_phase() self.boxes, self.scores, self.classes = self.generate()
(2) modify the “detect_image(self, image)” method: out_boxes, out_scores, out_classes = self.sess.run( [self.boxes, self.scores, self.classes], feed_dict={ self.yolo_model.input: image_data, self.input_image_shape: [image.size[1], image.size[0]], self.K_learning_phase: 0 })
done.
you can comment out this code “keras_learning_phase:0” , it’s ok to run, I have tried
In my case, I encountered the same error when creating the session (i.e., creating a YOLO class variable) from a main thread and running the session (i.e., calling YOLO.detect_image()) from a different thread in a callback function. In this case when using multiple threads, you have to set the default graph in the non-main threads before running detection. The change below fixed the issue for me. (I am running tensorflow-gpu==1.14 with keras==2.2.4)
Note: some references state that you also have to set the session again, but in my case I found that setting the default graph was sufficient to prevent the error. I have included but commented out the line to set the session in case anyone else finds it necessary.