Tensorflow:将“输入”键作为线程的张量错误

2024-10-02 08:19:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在运行一个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.

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

^{pr2}$

我的班级是下面一个。在

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

Tags: runinpyselflibpackagestensorflowline

热门问题