我一直在try 让文档人工智能批量提交工作,但遇到了一些困难.我使用RawDocument提交单个文件,假设我可以迭代我的数据集(27k图像),但 Select 了Batch,因为它似乎是更合适的技术.

当我运行我的代码时,我看到一个错误:"无法处理所有文档".调试信息的前几行是:

O:17:"Google\RPC\Status":5:{ S:7:"*代码";我:3;S:10:"*消息";S:32:"所有单据处理失败."; S:26:"谷歌\rpc\状态详情"; O:38:"Google\Protobuf\Internal\RepeatedField":4:{ S:49:"Google\Protobuf\Internal\RepeatedFieldcontainer";a:0:{}s:44:"Google\Protobuf\Internal\RepeatedFieldtype";i:11;s:45:"Google\Protobuf\Internal\RepeatedFieldklass";s:19:"Google\Protobuf\Any";s:52:"Google\Protobuf\Internal\RepeatedFieldlegacy_klass";s:19:"Google\Protobuf\Any";}s:38:"Google\Protobuf\Internal\Messagedesc";O:35:"Google\Protobuf\Internal\Descriptor":13:{s:46:"Google\Protobuf\Internal\Descriptorfull_name";s:17:"google.rpc.Status";s:42:"Google\Protobuf\Internal\Descriptorfield";a:3:{i:1;O:40:"Google\Protobuf\Internal\FieldDescriptor":14:{s:46:"Google\Protobuf\Internal\FieldDescriptorname";s:4:"code";```

support for this error说明错误的原因是:

GcsUriPrefix和gcsOutputConfig.gcsUri参数需要以gs://开头,以反斜杠(/)结尾.判断存储桶URI的配置.

我没有使用gcsUriPrefix(我应该吗?我的存储桶>最大批量限制),但我的gcsOutputConfig.gcsUri在这些限制之内.我提供的文件列表给出了文件名(指向正确的存储桶),因此不应该有尾随的反斜杠.

欢迎提出建议

    function filesFromBucket( $directoryPrefix ) {
        // NOT recursive, does not search the structure
        $gcsDocumentList = [];
    
        // see https://cloud.google.com/storage/docs/samples/storage-list-files-with-prefix
        $bucketName = 'my-input-bucket';
        $storage = new StorageClient();
        $bucket = $storage->bucket($bucketName);
        $options = ['prefix' => $directoryPrefix];
        foreach ($bucket->objects($options) as $object) {
            $doc = new GcsDocument();
            $doc->setGcsUri('gs://'.$object->name());
            $doc->setMimeType($object->info()['contentType']);
            array_push( $gcsDocumentList, $doc );
        }
    
        $gcsDocuments = new GcsDocuments();
        $gcsDocuments->setDocuments($gcsDocumentList);
        return $gcsDocuments;
    }
    
    function batchJob ( ) {
        $inputConfig = new BatchDocumentsInputConfig( ['gcs_documents'=>filesFromBucket('the-bucket-path/')] );
    
        // see https://cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.DocumentOutputConfig
        // nb: all uri paths must end with / or an error will be generated.
        $outputConfig = new DocumentOutputConfig( 
            [ 'gcs_output_config' =>
                   new GcsOutputConfig( ['gcs_uri'=>'gs://my-output-bucket/'] ) ]
        );
     
        // see https://cloud.google.com/php/docs/reference/cloud-document-ai/latest/V1.DocumentProcessorServiceClient
        $documentProcessorServiceClient = new DocumentProcessorServiceClient();
        try {
            // derived from the prediction endpoint
            $name = 'projects/######/locations/us/processors/#######';
            $operationResponse = $documentProcessorServiceClient->batchProcessDocuments($name, ['inputDocuments'=>$inputConfig, 'documentOutputConfig'=>$outputConfig]);
            $operationResponse->pollUntilComplete();
            if ($operationResponse->operationSucceeded()) {
                $result = $operationResponse->getResult();
                printf('<br>result: %s<br>',serialize($result));
            // doSomethingWith($result)
            } else {
                $error = $operationResponse->getError();
                printf('<br>error: %s<br>', serialize($error));
                // handleError($error)
            }
        } finally {
            $documentProcessorServiceClient->close();
        }    
    }

推荐答案

这被证明是一个ID-10-T错误,带有明确的PEBKAC含义.

$Object->;name()不返回存储桶名称作为路径的一部分.

$doc->setGcsUri('gs://'.$object->name());更改为$doc->setGcsUri('gs://'.$bucketName.'/'.$object->name());即可解决该问题.

Php相关问答推荐

PHP cUrl扩展与v8.2.12更新损坏

如何隐藏x轴图表上的值

一列必须指定多个变量的Laravel查询

为什么在我的PHP联系人脚本中开机自检后出现未定义变量错误?

将SVG包含在另一个php生成的SVG中

将WooCommerce WC_Order对象与wp_Schedule_Event一起使用

在个人资料页面上显示个人资料图像

Laravel Carbon DiffForHumans选项(年,月,天)

无法在Laravel中将日志(log)通道设置为空

Select 本地提货时隐藏WooCommerce显示的发货成本

无额外字段的Laravel同步

Shopware 6插件:由于删除了配置密钥,更新后配置值不正确

服务器升级到新的mysql版本8.0.34后查询错误

在 Woocommerce 邮箱订单中显示产品 GTIN

由于 PHP 版本不受支持,如何终止 PHP 脚本?

.htaccess环境变量条件不被判断

php-http/discovery 插件 1.15.1 是否仍在使用自己的模块 destruct Contao 4.13 中的composer 安装?

如何为多个表的id列设置不同的值

fopen 功能不断向我发送我重新加载网页时已发布的重复版本的表单

如何在 Laravel 9 中判断异常是否可报告?