表单识别器预览 - 无法加载示例文档

Dan*_*oft 2 microsoft-cognitive

我正在尝试使用 Forms Recognizer 预览,经过多次反复试验,我终于通过 SAS URL 读取了文档。但是,即使使用快速入门 [1] 中提供的示例文档,我也会得到以下响应:

{
    "modelId": "d7ba79e3-38bc-4913-bb11-82656cb08adc",
    "trainingDocuments": [
        {
            "documentName": "Invoice_1.pdf",
            "pages": 1,
            "errors": [
                "Page 1: Document is either invalid or exceeds the page/size limits."
            ],
            "status": "failure"
        },
        {
            "documentName": "Invoice_2.pdf",
            "pages": 1,
            "errors": [
                "Page 1: Document is either invalid or exceeds the page/size limits."
            ],
            "status": "failure"
        },
        {
            "documentName": "Invoice_3.pdf",
            "pages": 1,
            "errors": [
                "Page 1: Document is either invalid or exceeds the page/size limits."
            ],
            "status": "failure"
        },
        {
            "documentName": "Invoice_4.pdf",
            "pages": 1,
            "errors": [
                "Page 1: Document is either invalid or exceeds the page/size limits."
            ],
            "status": "failure"
        },
        {
            "documentName": "Invoice_5.pdf",
            "pages": 1,
            "errors": [
                "Page 1: Document is either invalid or exceeds the page/size limits."
            ],
            "status": "failure"
        }
    ],
    "errors": [
        {
            "errorMessage": "Unable to fit model. No documents clustered."
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

要使这些文档可用,是否需要在 BLOB 存储端发生一些特殊的事情?

即使在我们自己的基本形式上,我也收到了此错误消息,这完全符合大小限制。

更新:我认为这归结为我如何生成 SAS URL(其中文档根本不清楚)的一些问题。我有一个存储帐户 (SA),带有一个容器 (C),其中包含所有 PDF 文件。

在 Azure 门户中,我选择 SA 边栏选项卡,然后选择共享访问签名,采用所有默认选项,然后选择生成 SAS 和连接字符串。我尝试直接获取Blob 服务 SAS URL值并将其传递到source字段中,但这给出了错误:

{
    "error": {
        "code": "2024",
        "innerError": {
            "requestId": "77e73ba0-cbfe-4046-9730-beff8ec38be5"
        },
        "message": "Unable to list blobs on the Azure Blob storage account."
    }
}
Run Code Online (Sandbox Code Playgroud)

我不得不添加&comp=list&restype=containersource,然后文件被正确列出,但出现上述错误。显然,除了 Azure Potral 生成的内容之外,还需要向 SAS URL 添加一些内容,而我添加的内容只是其中的一部分。

我想念能够在 REST 负载中发送文档内容本身来训练模型。:-(

[1] - https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/curl/form-recognizer/sample_data.zip

Dan*_*rts 5

我也遇到了这个问题,因为我没有发现快速入门文档很清楚 - 公平地说,对微软来说,这部分是因为我没有在 Azure 中生成 SAS URL 的经验,而且自从@ iamsop 向他们提出了一个 GitHub 问题。

我做了以下笔记,这些笔记描述了我是如何让它工作的。希望他们将来能帮助其他人:

  1. 需要一个 blob 存储容器来转储训练文档(转到存储帐户 / {帐户名称} / Blob / + 容器(给它一个名称并将“公共访问级别”保留为“私人(无匿名访问)”)
  2. 点击进入容器并上传培训文档 - 全部在根文件夹中,没有子文件夹(上传后可能会有延迟,在它们实际显示在容器中之前说它们已完成)
  3. 为 blob 容器创建共享访问签名 (SAS) - 再次从 Storage Accounts / {account name} 开始,然后不要进入 Blob,进入共享访问签名 - 允许的权限只需要读取和列出,点击“生成 SAS 和连接字符串”并复制“Blob 服务 SAS URL”
  4. 将此 URL 粘贴到记事本(或其他)中,并在查询字符串之前插入容器的名称
  5. 现在您可以使用诸如

curl -X POST "{endpoint}/formrecognizer/v1.0-preview/custom/train" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: {subscription key}" -- data-ascii "{'source': '{SAS url}'}"

  • 将“{endpoint}”替换为提供的 API 端点(可能类似于https://region.api.cognitive.microsoft.com
  • 将 {subscription key} 替换为通过 Form Reognizer 资源概览选项卡可用的密钥
  • 将 {SAS url} 替换为上面生成的 SAS URL,包含容器名称的调整版本

(注意:我个人对上述命令的偏好是在“data-ascii”值中使用单引号而不是双引号,因为这样您就不需要转义它们,使命令更易于阅读和编写)