简体   繁体   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

I am trying to run this tutorial .我正在尝试运行本教程 I didn't get any error in build_model.py.我在 build_model.py 中没有收到任何错误。 But when I'm trying to run app.py.但是当我尝试运行 app.py 时。 I'm getting a ValueError.我收到一个 ValueError。 By the way I use conda environment.顺便说一下,我使用 conda 环境。

Keras version: 2.2.4 Keras 版本:2.2.4

Tensorflow version: 1.13.0 Tensorflow 版本:1.13.0

OpenCV version: 4.0.0 OpenCV 版本:4.0.0

Flask version: 1.0.2烧瓶版本:1.0.2

Terminal终端

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

Was solved for me by calling _make_predict_function() on the model after loading it.通过在加载模型后在模型上调用 _make_predict_function() 为我解决了问题。

Got this from https://github.com/keras-team/keras/issues/6462https://github.com/keras-team/keras/issues/6462得到这个

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tensor(“dense_2/Softmax:0”, shape=(?, 10), dtype=float32) 不是该图的元素 - Tensor(“dense_2/Softmax:0”, shape=(?, 10), dtype=float32) is not an element of this graph / image / Tensor Tensor上的ValueError(“activation_5 / Softmax:0”,shape =(?,4),dtype = float32)不是此图的元素 - ValueError at /image/ Tensor Tensor(“activation_5/Softmax:0”, shape=(?, 4), dtype=float32) is not an element of this graph Tensor Tensor("predictions/Softmax:0", shape=(?, 1000), dtype=float32) 不是这个图的元素 - Tensor Tensor("predictions/Softmax:0", shape=(?, 1000), dtype=float32) is not an element of this graph 错误:断言错误:无法计算输出张量(“dense_2/truediv:0”,形状=(无,无,1),dtype=float32) - Error: AssertionError: Could not compute output Tensor(“dense_2/truediv:0”, shape=(None, None, 1), dtype=float32) ValueError: Tensor Tensor("mrcnn_detection/Reshape_1:0", shape=(1, 100, 6), dtype=float32) 不是这个图的一个元素 - ValueError: Tensor Tensor("mrcnn_detection/Reshape_1:0", shape=(1, 100, 6), dtype=float32) is not an element of this graph ValueError: Tensor("ExponentialDecay_4:0", shape=(), dtype=float32) - ValueError: Tensor("ExponentialDecay_4:0", shape=(), dtype=float32) ValueError:Tensor(“ BN_1 / moments / Squeeze:0”,shape =(32,256,32),dtype = float32)必须与Tensor来自同一图 - ValueError: Tensor(“BN_1/moments/Squeeze:0”, shape=(32, 256, 32), dtype=float32) must be from the same graph as Tensor 无法将 feed_dict 键解释为 Tensor:Tensor Tensor("Placeholder:0", shape=(135162, 6), dtype=float32) 不是此图的元素 - Cannot interpret feed_dict key as Tensor: Tensor Tensor("Placeholder:0", shape=(135162, 6), dtype=float32) is not an element of this graph AssertionError:无法计算 output 张量(“dense_17/Sigmoid:0”,shape=(None,1),dtype=float32) - AssertionError: Could not compute output Tensor(“dense_17/Sigmoid:0”, shape=(None, 1), dtype=float32) ValueError:模型输出“Tensor(“activation_1/Identity:0”, shape=(?, 3), dtype=float32)”的形状无效 - ValueError: Model output "Tensor("activation_1/Identity:0", shape=(?, 3), dtype=float32)" has invalid shape
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM