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

Forms Recognizer Preview - can't load sample documents

我正在尝试使用 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."
        }
    ]
}

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

我什至在我们自己的基本表格上收到此错误消息,它完全符合大小限制。

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

在 Azure 门户中,我选择 SA blade,然后选择共享访问签名,采用所有默认选择,然后选择 生成 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."
    }
}

我必须将 &comp=list&restype=container 添加到 source,然后文件才能正确列出,但出现上述错误。显然,需要在 Azure Potral 生成的内容之外向 SAS URL 添加一些内容,而我添加的只是其中的一部分。

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

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

您是如何调用该服务的?使用 cURL 命令?此外,请确保您的 PDF 文件直接位于您获得共享访问签名的 Azure Blob 容器中(无子文件夹)。下面的 cURL 命令对我有用:

curl -X POST "https://Endpoint/formrecognizer/v1.0-preview/custom/train" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: Subscription Key" --data-ascii "{ \"source\": \" SAS URL\"}"

最后,确保您能够打开 PDF 文件(即检查它们是否无效)。

我能够通过将 blob 中的容器名称添加到生成的 SAS URL 来解决这个问题。示例:"yourblobname.blob.core.windows.net/name of your container/rest of the sas url".

我也遇到了这个问题,因为我没有发现快速入门文档非常清楚 - 公平地说,这部分是因为我没有在 Azure 中生成 SAS URLs 的经验,并且自从@iamsop 向他们提出 GitHub 问题后,它已经有了很小的改进。

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

  1. 需要一个 blob 存储容器来转储训练文档 在(转到存储帐户/{帐户名称}/Blobs/+容器 (给它起个名字并将 "Public access level" 保留为“Private(不 匿名访问)"
  2. 点击进入容器并上传训练 文档 - 都在根文件夹中,没有子文件夹(可以有一个 上传后延迟说它们在完成之前 实际显示在容器内)
  3. 创建共享访问 blob 容器的签名 (SAS) - 从存储重新开始 Accounts / {account name} 然后不要进入 Blobs,进入 Shared 访问签名 - 允许的权限只需要读取和 列表,单击 "Generate SAS and connection string" 并复制“Blob 服务 SAS URL"
  4. 将此 URL 粘贴到记事本(或其他)中,然后 在查询字符串前插入容器名称
  5. 现在你可以 使用
  6. 等命令

curl -X POST "{端点}/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" 值中使用单引号而不是双引号,因为那样你就不需要转义它们,使命令更易于阅读和编写)