簡體   English   中英

python - ValueError: Tensor Tensor("dense_2/Softmax:0", shape=(?, 43), dtype=float32) 不是這個圖的一個元素

[英]python - ValueError: Tensor Tensor("dense_2/Softmax:0", shape=(?, 43), dtype=float32) is not an element of this graph

我正在嘗試運行本教程 我在 build_model.py 中沒有收到任何錯誤。 但是當我嘗試運行 app.py 時。 我收到一個 ValueError。 順便說一下,我使用 conda 環境。

Keras 版本:2.2.4

Tensorflow 版本:1.13.0

OpenCV 版本:4.0.0

燒瓶版本:1.0.2

終端

 (base) tarik:webapp tarik$ sudo python app.py 
    Password:
    Using TensorFlow backend.
    Loading model....
    WARNING:tensorflow:From /anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
    Instructions for updating:
    Colocations handled automatically by placer.
    2019-02-24 18:06:55.261293: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
    WARNING:tensorflow:From /anaconda3/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py:3445: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.
    Instructions for updating:
    Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.
    WARNING:tensorflow:From /anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
    Instructions for updating:
    Use tf.cast instead.
    ....Loaded model
     * Serving Flask app "app" (lazy loading)
     * Environment: production
       WARNING: Do not use the development server in a production environment.
       Use a production WSGI server instead.
     * Debug mode: off
     * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
    127.0.0.1 - - [24/Feb/2019 18:06:58] "GET / HTTP/1.1" 200 -
    /anaconda3/lib/python3.7/site-packages/skimage/transform/_warps.py:105: UserWarning: The default mode, 'constant', will be changed to 'reflect' in skimage 0.15.
      warn("The default mode, 'constant', will be changed to 'reflect' in "
    /anaconda3/lib/python3.7/site-packages/skimage/transform/_warps.py:110: UserWarning: Anti-aliasing will be enabled by default in skimage 0.15 to avoid aliasing artifacts when down-sampling images.
      warn("Anti-aliasing will be enabled by default in skimage 0.15 to "
    [2019-02-24 18:07:03,391] ERROR in app: Exception on /api/v1 [POST]
    Traceback (most recent call last):
      File "/anaconda3/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
        response = self.full_dispatch_request()
      File "/anaconda3/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "/anaconda3/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception
        reraise(exc_type, exc_value, tb)
      File "/anaconda3/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
        raise value
      File "/anaconda3/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
        rv = self.dispatch_request()
      File "/anaconda3/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
        return self.view_functions[rule.endpoint](**req.view_args)
      File "app.py", line 174, in traffic_light_prediction
        response_num = traffic_prediction(f)
      File "app.py", line 136, in traffic_prediction
        y_pred = model.predict_classes(X_test)
      File "/anaconda3/lib/python3.7/site-packages/keras/engine/sequential.py", line 267, in predict_classes
        proba = self.predict(x, batch_size=batch_size, verbose=verbose)
      File "/anaconda3/lib/python3.7/site-packages/keras/engine/training.py", line 1164, in predict
        self._make_predict_function()
      File "/anaconda3/lib/python3.7/site-packages/keras/engine/training.py", line 554, in _make_predict_function
        **kwargs)
      File "/anaconda3/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 2744, in function
        return Function(inputs, outputs, updates=updates, **kwargs)
      File "/anaconda3/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 2546, in __init__
        with tf.control_dependencies(self.outputs):
      File "/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 5028, in control_dependencies
        return get_default_graph().control_dependencies(control_inputs)
      File "/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 4528, in control_dependencies
        c = self.as_graph_element(c)
      File "/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 3478, in as_graph_element
        return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
      File "/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 3557, in _as_graph_element_locked
        raise ValueError("Tensor %s is not an element of this graph." % obj)
    ValueError: Tensor Tensor("dense_2/Softmax:0", shape=(?, 43), dtype=float32) is not an element of this graph.
    127.0.0.1 - - [24/Feb/2019 18:07:03] "POST /api/v1 HTTP/1.1" 500 -

通過在加載模型后在模型上調用 _make_predict_function() 為我解決了問題。

https://github.com/keras-team/keras/issues/6462得到這個

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM