首页 > 解决方案 > 从 Node.js 客户端库返回的 GCP AutoML 数据集 ID 与实际数据集 ID 不匹配

问题描述

以前,我使用 Node.js 客户端库创建数据集并在 GCP automl 上训练模型,一切正常。但是,现在我面临“错误:5 NOT_FOUND:数据集不存在或无法与 AutoMl 一起使用”

之后,我意识到从创建数据集请求返回的数据集 id 与实际的数据集 id不匹配(与 Web 界面相比)。所以我不能以编程方式与数据集交互。

我的目标是使用该数据集 id 上传图像并训练模型。我缺少任何更新吗?任何建议将不胜感激。

以下是来自https://cloud.google.com/vision/automl/docs/create-datasets的使用 GCP Automl 创建数据集的参考代码。

 * TODO(developer): Uncomment these variables before running the sample.
 */
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'us-central1';
// const displayName = 'YOUR_DISPLAY_NAME';

// Imports the Google Cloud AutoML library
const {AutoMlClient} = require(`@google-cloud/automl`).v1;

// Instantiates a client
const client = new AutoMlClient();

async function createDataset() {
  // Construct request
  // Specify the classification type
  // Types:
  // MultiLabel: Multiple labels are allowed for one example.
  // MultiClass: At most one label is allowed per example.
  const request = {
    parent: client.locationPath(projectId, location),
    dataset: {
      displayName: displayName,
      imageClassificationDatasetMetadata: {
        classificationType: 'MULTILABEL',
      },
    },
  };

  // Create dataset
  const [operation] = await client.createDataset(request);

  // Wait for operation to complete.
  const [response] = await operation.promise();

  console.log(`Dataset name: ${response.name}`);
  console.log(`
    Dataset id: ${
      response.name
        .split('/')
        [response.name.split('/').length - 1].split('\n')[0]
    }`);
}

createDataset();

标签: javascriptnode.jsgoogle-cloud-platformgoogle-cloud-automl

解决方案


现在我使用了来自https://github.com/googleapis/nodejs-automl/blob/master/samples/vision_object_detection_create_dataset.js的示例代码,它运行良好。是的,我应该在一开始就使用它。但我们总能找到行不通的方法,在工作之前,对吗?

快乐编码,创造一个更美好的世界;)。


推荐阅读