【问题标题】:Form Recognizer speed issues表单识别器速度问题
【发布时间】:2020-07-11 08:46:34
【问题描述】:

我正在使用带有标签的自定义模型(使用示例标签工具创建),并使用此 1 页面底部的“Python 表单识别器异步分析”V2 SDK 代码获取结果。 它基本上可以工作,但是单页 PDF 文件需要 20 多秒才能获得结果(使用了 6 个标签,S0 定价模型)。 150 个单页 pdf 文件花了一个多小时。 我们还测试了表单识别器的 V1 SDK 预览版(不带标签),它比 V2 快得多

我知道 V2 现在是异步的,但是有什么可以加快表单识别的方法吗? 以下是我基本使用的代码:

########### Python Form Recognizer Async Analyze #############
import json
import time
from requests import get, post

# Endpoint URL
endpoint = r"<endpoint>"
apim_key = "<subsription key>"
model_id = "<model_id>"
post_url = endpoint + "/formrecognizer/v2.0-preview/custom/models/%s/analyze" % model_id
source = r"<file path>"
params = {
    "includeTextDetails": True
}

headers = {
    # Request headers
    'Content-Type': '<file type>',
    'Ocp-Apim-Subscription-Key': apim_key,
}
with open(source, "rb") as f:
    data_bytes = f.read()

try:
    resp = post(url = post_url, data = data_bytes, headers = headers, params = params)
    if resp.status_code != 202:
        print("POST analyze failed:\n%s" % json.dumps(resp.json()))
        quit()
    print("POST analyze succeeded:\n%s" % resp.headers)
    get_url = resp.headers["operation-location"]
except Exception as e:
    print("POST analyze failed:\n%s" % str(e))
    quit() 

n_tries = 15
n_try = 0
wait_sec = 5
max_wait_sec = 60
while n_try < n_tries:
    try:
        resp = get(url = get_url, headers = {"Ocp-Apim-Subscription-Key": apim_key})
        resp_json = resp.json()
        if resp.status_code != 200:
            print("GET analyze results failed:\n%s" % json.dumps(resp_json))
            quit()
        status = resp_json["status"]
        if status == "succeeded":
            print("Analysis succeeded:\n%s" % json.dumps(resp_json))
            quit()
        if status == "failed":
            print("Analysis failed:\n%s" % json.dumps(resp_json))
            quit()
        # Analysis still running. Wait and retry.
        time.sleep(wait_sec)
        n_try += 1
        wait_sec = min(2*wait_sec, max_wait_sec)     
    except Exception as e:
        msg = "GET analyze results failed:\n%s" % str(e)
        print(msg)
        quit()
print("Analyze operation did not complete within the allocated time.")

【问题讨论】:

    标签: python azure-cognitive-services form-recognizer


    【解决方案1】:

    感谢您提出问题,我们正在调查此问题,并会尽快为您更新。对于分析 150 个单页,您可以将所有页面并行发送到表单识别器以减少时间。

    【讨论】:

    • 所用时间不是训练时间。我使用 OCR 表单标签工具创建了一个自定义模型,该模型运行良好,具有 100% 的准确度并且速度相当快。所花费的时间用于分析 PDF 文件以获取具有创建模型的键值对 - 请参见上面的代码。 1 x PDF 仅包含一个页面大约需要 20-60 秒 150 个 PDF 文件需要一个多小时才能识别。 V1(无标签)速度快了很多。
    • 要分析 150 个 PDF,在我们调查问题时并行运行它们。您可以并行调用 API 请求来分析 API,以减少处理 150 个 PDF 的时间。
    猜你喜欢
    • 2021-05-02
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-03
    • 2021-08-20
    相关资源
    最近更新 更多