GCP Document AI转换器转换外部JSON无输出的问题咨询
Azure Form Recognizer注释转Document AI JSON失败问题排查
操作背景与步骤
- 目标:将Azure Form Recognizer生成的JSON注释转换为GCP Document AI JSON格式
- 操作细节:
- 基于Document AI官方示例函数
convert_external_annotations_sample()实现转换逻辑 - 采用Azure发票示例配置文件,仅将单位从"pxl"修改为"inch"
- 输入存储桶路径包含三个文件:
sample-invoice.pdf、sample-invoice_annotations.json、sample-invoice_config.json,指定输出存储桶路径 - 尝试过多种processor_id:全新Invoice Parser处理器、带微调模型的处理器、预训练模型ID
pretrained-invoice-v1.3-2022-07-15
- 基于Document AI官方示例函数
运行日志
-------- Downloading Started -------- -------- Finished Downloading -------- -------- Converting Started -------- -------- Finished Converting -------- -------- Uploading Started -------- -------- Finished Uploading -------- -------- Schema Information -------- Unique Entity Types: []
问题描述
日志显示所有步骤执行完成,但输出存储桶中无任何内容。已确认注释JSON包含配置文件中用到的所有字段,询问是否存在配置错误,是否需要修改config.json。
相关文件内容
sample-invoice_config.json
{ "entity_object":"analyzeResult.documentResults.0.fields", "page": { "height":"analyzeResult.readResults.0.height", "width":"analyzeResult.readResults.0.width" }, "entity": { "type_":"analyzeResult.documentResults.0.fields:self", "mention_text":"text", "normalized_vertices":{ "type":"3", "unit":"inch", "base":"boundingBox", "x":"x", "y":"y" } } }
sample-invoice_annotations.json(部分内容)
{ "status": "succeeded", "createdDateTime": "2020-11-06T23:32:11Z", "lastUpdatedDateTime": "2020-11-06T23:32:20Z", "analyzeResult": { "version": "2.1.0", "readResults": [{ "page": 1, "angle": 0, "width": 8.5, "height": 11, "unit": "inch" }], "pageResults": [{ "page": 1, "tables": [{ "rows": 3, "columns": 4, "cells": [{ "rowIndex": 0, "columnIndex": 0, "text": "QUANTITY", "boundingBox": [0.4953, 5.7306, 1.8097, 5.7306, 1.7942, 6.0122, 0.4953, 6.0122] }], "VendorName": { "type": "string", "valueString": "CONTOSO LTD.", "text": "CONTOSO LTD.", "boundingBox": [0.5909, 0.6827, 2.3215, 0.6827, 2.3215, 0.8644, 0.5909, 0.8644], "page": 1, "confidence": 0.998 } }] }] } }
问题排查与修复建议
日志中Unique Entity Types: []说明转换器未识别到任何实体类型,这是输出为空的核心原因,问题出在配置文件的路径匹配错误:
entity_object路径错误
注释JSON里的实体字段(如VendorName)位于analyzeResult.pageResults.0.tables.0节点下,但配置文件中写的是analyzeResult.documentResults.0.fields——而你的注释JSON中根本不存在documentResults节点,导致转换器找不到实体对象。实体类型路径错误
配置里的type_字段写的是analyzeResult.documentResults.0.fields:self,同样因documentResults节点不存在,无法获取实体类型。需改为获取当前实体的键名(如VendorName)作为实体类型。修正后的配置文件示例
调整路径指向正确的实体父节点,并修改实体类型的取值方式:
{ "entity_object":"analyzeResult.pageResults.0.tables.0", "page": { "height":"analyzeResult.readResults.0.height", "width":"analyzeResult.readResults.0.width" }, "entity": { "type_":"self:key", "mention_text":"text", "normalized_vertices":{ "type":"3", "unit":"inch", "base":"boundingBox", "x":"x", "y":"y" } } }
其中self:key表示用当前实体对象的键名(如VendorName)作为Document AI的实体类型,entity_object指向包含所有实体字段的父节点。
- 额外验证点
- 确认注释JSON中所有实体都包含
text和boundingBox字段 - 检查存储桶权限,确保转换程序拥有输出桶的写入权限
- 验证processor_id对应的模型是否支持自定义实体类型,或是否需要配置实体schema
- 确认注释JSON中所有实体都包含
内容的提问来源于stack exchange,提问作者Augusto Firmo
相关产品推荐
相关产品推荐

