Tensorflow:feed_dict键作为带有线程的Tensor错误

时间:2018-04-05 12:29:02

标签: python django multithreading tensorflow keras

我正在运行一个django服务器,当我启动一个守护程序线程并加载我的权重时,我意识到我遇到了问题。

有没有人遇到过同样的问题以及你是如何设法解决的?

我曾经用Keras的clear_session方法来解决这个问题,但现在看来它不起作用。

Exception in thread Thread-7:
Traceback (most recent call last):
  File "/Users/ale/.virtualenvs/LoceyeCloud/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1064, in _run
    allow_operation=False)
  File "/Users/ale/.virtualenvs/LoceyeCloud/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3035, in as_graph_element
    return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
  File "/Users/ale/.virtualenvs/LoceyeCloud/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3114, in _as_graph_element_locked
    raise ValueError("Tensor %s is not an element of this graph." % obj)
ValueError: Tensor Tensor("Placeholder:0", shape=(3, 3, 1, 64), dtype=float32) is not an element of this graph.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/ale/platform/Server/server_back/server_backend.py", line 196, in execute
    eyetracker = LoceyeEyetracker(self.screen_dimensions)
  File "/Users/ale/platform/Server/server_back/LoceyeEyetracker.py", line 24, in __init__
    self.iris_detector = IrisDetectorCnn(weights_filename, blink_filename)
  File "/Users/ale/platform/Server/server_back/IrisDetectorCnn.py", line 17, in __init__
    self.model = load_model(model_filename)
  File "/Users/ale/.virtualenvs/LoceyeCloud/lib/python3.6/site-packages/keras/models.py", line 246, in load_model
    topology.load_weights_from_hdf5_group(f['model_weights'], model.layers)
  File "/Users/ale/.virtualenvs/LoceyeCloud/lib/python3.6/site-packages/keras/engine/topology.py", line 3166, in load_weights_from_hdf5_group
    K.batch_set_value(weight_value_tuples)
  File "/Users/ale/.virtualenvs/LoceyeCloud/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2370, in batch_set_value
    get_session().run(assign_ops, feed_dict=feed_dict)
  File "/Users/ale/.virtualenvs/LoceyeCloud/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 889, in run
    run_metadata_ptr)
  File "/Users/ale/.virtualenvs/LoceyeCloud/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1067, in _run
    + e.args[0])
TypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("Placeholder:0", shape=(3, 3, 1, 64), dtype=float32) is not an element of this graph.

和我加载初始化对象和加载权重的代码

def startPredict(self):

    async = threading.Thread(target=self.execute)
    async.setDaemon(False)
    async.start()

def execute(self):

    clear_session()
    eyetracker = LoceyeEyetracker(self.screen_dimensions)

我的课程如下。

class LoceyeEyetracker:
    def __init__(self, screen_size,
             weights_filename=CNN_MODEL_FILENAME,
             blink_filename=CNN_BLINK_MODEL_FILENAME, 
             reference_filename=CNN_REFERENCE_MODEL_FILENAME):

        self.iris_detector = IrisDetectorCnn(weights_filename, blink_filename)
        self.screen_mapper = ScreenCoordinateMapper(screen_size)
        self.reference_detector = ReferencePointDetector(reference_filename)
        self.last_reference = PointPair(left=Point(x=0,y=0),right=Point(x=0,y=0))

0 个答案:

没有答案