美文网首页
通过Flask方式调用keras方法报错的怪异问题解决方法

通过Flask方式调用keras方法报错的怪异问题解决方法

作者: 陈亮2019 | 来源:发表于2020-05-22 15:53 被阅读0次

    最近使用keras+tensorflow的densent模型处理OCR,直接传入文件运行正常,但用Flask通过web 上传文件后调用相同的功能时会报如下错误:

    File "e:\big-data\ocr\BDP_SMARTOCR-REPO\trunk\Src\epocr-lic\ocr.py", line 69, in charRec

        text = keras_densenet(image)

      File "e:\big-data\ocr\BDP_SMARTOCR-REPO\trunk\Src\epocr-lic\densenet\model.py", line 54, in predict

        y_pred = basemodel.predict(X)

      File "e:\deep_learn\tf-gpu\lib\site-packages\keras\engine\training.py", line 1164, in predict

        self._make_predict_function()

      File "e:\deep_learn\tf-gpu\lib\site-packages\keras\engine\training.py", line 554, in _make_predict_function

        **kwargs)

      File "e:\deep_learn\tf-gpu\lib\site-packages\keras\backend\tensorflow_backend.py", line 2744, in function

        return Function(inputs, outputs, updates=updates, **kwargs)

      File "e:\deep_learn\tf-gpu\lib\site-packages\keras\backend\tensorflow_backend.py", line 2546, in __init__

        with tf.control_dependencies(self.outputs):

      File "e:\deep_learn\tf-gpu\lib\site-packages\tensorflow\python\framework\ops.py", line 5028, in control_dependencies

        return get_default_graph().control_dependencies(control_inputs)

      File "e:\deep_learn\tf-gpu\lib\site-packages\tensorflow\python\framework\ops.py", line 4528, in control_dependencies

        c = self.as_graph_element(c)

      File "e:\deep_learn\tf-gpu\lib\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 "e:\deep_learn\tf-gpu\lib\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("out_2/truediv:0", shape=(?, ?, 5990), dtype=float32) is not an element of this graph

    解决方案:

    在Flask启动文件中,先调用一次出错的功能,然后再接收到上传图片后调用该功能时就不会报上述错误了。 

    相关文章

      网友评论

          本文标题:通过Flask方式调用keras方法报错的怪异问题解决方法

          本文链接:https://www.haomeiwen.com/subject/bsnqahtx.html