【问题标题】:ValueError: Tensor Tensor("time_distributed_1/Reshape_1:0", shape=(?, ?, 23), dtype=float32) is not an element of this graphValueError: Tensor Tensor("time_distributed_1/Reshape_1:0", shape=(?, ?, 23), dtype=float32) 不是该图的元素
【发布时间】:2019-09-17 05:34:41
【问题描述】:

在从邮递员调用 api 时出现 tensorflow 维度的错误,但是当我在没有 api 调用的情况下运行函数时运行完美。 例如:

我在烧瓶中制作了这个 api:

def main_function():
    round2 =clean_text_round2(my_text)
    round3 = str(Punctuation(round2))

    -------
    test = json.dumps(somejsonformat)
    return test

我的 api 是

@app.route('/',methods=['POST','GET'])
def padd():
    main_function()
app.run()

抛出此错误: 从邮递员调用 api 时出现 tensorflow 维度的错误,但是当我在没有 api 调用的情况下运行函数时运行完美。

但是, 当我不从函数返回 json 数据时 然后它给了我想要的结果。代码是 test = json.dumps(somejsonformat)

这个测试是 JSON 数据 当我通过 api 返回它时 像这样:

@app.route('/',methods=['POST','GET'])
def padd():
    return test
app.run()

它为我提供以下 json 格式的数据:

array:22 [▼
  "edates" => array:21 [▶]
  "edate_tag" => array:21 [▶]
  "locations" => array:12 [▶]
  "location_tag" => array:12 [▶]
  "emails" => array:2 [▼
    0 => "Sameera.itops@gmail.com"
    1 => "https://www.linkedin.com/in/sameera-cherukuri-888589150/"
  ]
  "emails_tag" => array:2 [▶]
  "cdates" => []
  "cdates_tag" => []
]

但是当我返回 json 数据时出现上述错误(测试) 通过函数并通过api函数padd()调用它。

如果有人可以帮助我解决这个问题,那将是很大的帮助。

【问题讨论】:

  • Keras 模型在哪里?你在哪里使用模型?
  • 它在api调用函数之外。eg: from keras.models import Model, Input from keras.layers.merge import add from keras.layers import LSTM, Embedding, Dense, TimeDistributed,
  • 我不明白。在代码中的某处,您必须加载和使用模型,例如它的 predict 函数。它在哪里?您是否加载预训练模型? api调用(padd())和模型有什么关系?
  • 我已经邮寄给你了...我在哪里可以分享我的完整代码,以便您获得更多...请您检查邮件
  • 您可以使用 Github 存储库或 gist 公开您的代码。此外,最好编辑您的问题并在其中添加更多详细信息,以便其他遇到相同问题的人可以从中受益。

标签: python-3.x tensorflow flask keras deep-learning


【解决方案1】:

我认为它与此重复。

Tensor is not an element of this graph

这样的事情应该可以工作。

graph = tf.get_default_graph()
@app.route('/',methods=['POST','GET'])
def padd():
    with graph.as_default():
        main_function()  # contains model.predict

【讨论】:

  • 感谢您的解决方案,它确实解决了我的问题
猜你喜欢
  • 2020-06-09
  • 2019-10-23
  • 2018-04-27
  • 2019-04-22
  • 1970-01-01
  • 1970-01-01
  • 2019-09-24
  • 2018-04-25
  • 2019-07-18
相关资源
最近更新 更多