データセットの管理

データセットには分類するコンテンツ タイプの代表的なサンプルが含まれ、サンプルにはカスタムモデルで使用するカテゴリラベルが付けられています。このデータセットを入力値として利用し、モデルをトレーニングします。

データセットの主な作成手順は次のとおりです。

  1. データセットを作成し、各項目に複数のラベルを付けるかどうかを指定します。
  2. データセットにデータ項目をインポートします
  3. 項目にラベルを付けます

1 つのプロジェクトに複数のデータセットを含めることができ、それぞれ別個のモデルのトレーニングに使用されます。使用可能なデータセットの一覧の取得し、不要になったデータセットを削除できます。

データセットの作成

カスタムモデルを作成するには、まず空のデータセットを作成します。作成したデータセットには、最終的にそのモデルのトレーニング データが格納されます。

ウェブ UI

AutoML Video UI を使用すると、新しいデータセットの作成とそのデータセットへの項目のインポートを同じページで行うことができます。

  1. AutoML Video UI を開きます。[データセット] ページに、現在のプロジェクトにこれまでに作成されたデータセットのステータスが表示されます。 別のプロジェクトのデータセットを追加するには、タイトルバーの右上にあるプルダウン リストからプロジェクトを選択します。
  2. [データセット] ページで、[データセットを作成] をクリックします。
    [Create dataset] アイコン

    次の画面が表示されます。 Click_new_dataset
  3. データセットに関する情報を入力します。
    1. このデータセットの名前を指定します。
    2. [動画分類] を選択します。
    3. [データセットを作成] をクリックします。

      次の画面が表示されます。データセット「my_dataset」のページ
  4. 次の情報を入力します。
    1. トレーニング データの URI を含む CSV ファイルの Cloud Storage URI を指定します(データの準備をご覧ください)。
      このクイックスタートでは、次のコマンドを使用します。
      automl-video-demo-data/hmdb_split1.csv

    2. [続行] をクリックして、データのインポートを開始します。
      次の画面が表示されます。
      データのインポート

指定した動画の数と長さによっては、インポート処理が終わるまで時間がかかることがあります。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • dataset-name: インターフェースに表示するデータセットの名前
  • 注:
    • project-number: プロジェクトの番号。
    • location-id: アノテーションを実行する Cloud リージョン。サポート対象のクラウド リージョンは us-east1us-west1europe-west1asia-east1 です。リージョンを指定しないと、動画ファイルの場所に基づいてリージョンが決まります。

HTTP メソッドと URL:

POST  https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets

リクエストの本文(JSON):

{
  "displayName": "dataset-name",
  "videoClassificationDatasetMetadata": {
  }
}

リクエストを送信するには、次のいずれかのオプションを選択します。

curl

リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-number" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
" https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets"

PowerShell

リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-number" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri " https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets" | Select-Object -Expand Content
レスポンスが成功すると、AutoML Video Intelligence API はオペレーションの name を返します。このようなレスポンスの例を次に示します。project-number はプロジェクトの番号、operation-id はリクエストに対して作成された長時間実行オペレーションの ID です。

Java

AutoML Video に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.cloud.automl.v1beta1.AutoMlClient;
import com.google.cloud.automl.v1beta1.Dataset;
import com.google.cloud.automl.v1beta1.LocationName;
import com.google.cloud.automl.v1beta1.VideoClassificationDatasetMetadata;
import java.io.IOException;

class VideoClassificationCreateDataset {

  public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "YOUR_PROJECT_ID";
    String displayName = "YOUR_DATASET_NAME";
    createDataset(projectId, displayName);
  }

  // Create a dataset
  static void createDataset(String projectId, String displayName) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
      // A resource that represents Google Cloud Platform location.
      LocationName projectLocation = LocationName.of(projectId, "us-central1");
      VideoClassificationDatasetMetadata metadata =
          VideoClassificationDatasetMetadata.newBuilder().build();
      Dataset dataset =
          Dataset.newBuilder()
              .setDisplayName(displayName)
              .setVideoClassificationDatasetMetadata(metadata)
              .build();

      Dataset createdDataset = client.createDataset(projectLocation, dataset);

      // Display the dataset information.
      System.out.format("Dataset name: %s%n", createdDataset.getName());
      // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are
      // required for other methods.
      // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}`
      String[] names = createdDataset.getName().split("/");
      String datasetId = names[names.length - 1];
      System.out.format("Dataset id: %s%n", datasetId);
    }
  }
}

Node.js

AutoML Video に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

/**
 * 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').v1beta1;

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

async function createDataset() {
  // Construct request
  const request = {
    parent: client.locationPath(projectId, location),
    dataset: {
      displayName: displayName,
      videoClassificationDatasetMetadata: {},
    },
  };

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

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

createDataset();

Python

AutoML Video に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

from google.cloud import automl_v1beta1 as automl

def create_dataset(
    project_id="YOUR_PROJECT_ID", display_name="your_datasets_display_name"
):
    """Create a automl video classification dataset."""

    client = automl.AutoMlClient()

    # A resource that represents Google Cloud Platform location.
    project_location = f"projects/{project_id}/locations/us-central1"
    metadata = automl.VideoClassificationDatasetMetadata()
    dataset = automl.Dataset(
        display_name=display_name,
        video_classification_dataset_metadata=metadata,
    )

    # Create a dataset with the dataset metadata in the region.
    created_dataset = client.create_dataset(parent=project_location, dataset=dataset)

    # Display the dataset information
    print(f"Dataset name: {created_dataset.name}")

    # To get the dataset id, you have to parse it out of the `name` field.
    # As dataset Ids are required for other methods.
    # Name Form:
    #    `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}`
    print("Dataset id: {}".format(created_dataset.name.split("/")[-1]))

データセットへの項目のインポート

データセットを作成したら、Cloud Storage バケットに保存されている CSV ファイルからラベル付きデータをインポートできます。データの準備とインポート用の CSV ファイルの作成の詳細については、トレーニング データの準備をご覧ください。

空のデータセットに項目をインポートすることも、既存のデータセットに追加項目をインポートすることもできます。

ウェブ UI

データはデータセットを作成するときにインポートします。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • input-uri: アノテーションを付けるファイルを含む Cloud Storage バケット(ファイル名を含む)。先頭は gs:// でなければなりません。例:
    "inputUris": ["gs://automl-video-demo-data/hmdb_split1.csv"]
  • dataset-id: データセットのデータセット識別子(表示名ではない)に置き換えます。例: VCN4798585402963263488
  • 注:
    • project-number: プロジェクトの番号。
    • location-id: アノテーションを実行する Cloud リージョン。サポート対象のクラウド リージョンは us-east1us-west1europe-west1asia-east1 です。リージョンを指定しないと、動画ファイルの場所に基づいてリージョンが決まります。

HTTP メソッドと URL:

POST  https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets/dataset-id:importData

リクエストの本文(JSON):

{
   "inputConfig": {
      "gcsSource": {
         "inputUris": input-uri
      }
   }
}

リクエストを送信するには、次のいずれかのオプションを選択します。

curl

リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-number" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
" https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets/dataset-id:importData"

PowerShell

リクエスト本文を request.json という名前のファイルに保存して、次のコマンドを実行します。

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-number" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri " https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets/dataset-id:importData" | Select-Object -Expand Content
データ インポート オペレーションのオペレーション ID が返されます。この例は、インポート オペレーション ID VCN7506374678919774208 を含むレスポンスを示しています。

オペレーション ID を使用して、タスクのステータスを取得できます。例については、オペレーションのステータスの取得をご覧ください。

Java

AutoML Video に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.retrying.RetrySettings;
import com.google.cloud.automl.v1beta1.AutoMlClient;
import com.google.cloud.automl.v1beta1.AutoMlSettings;
import com.google.cloud.automl.v1beta1.DatasetName;
import com.google.cloud.automl.v1beta1.GcsSource;
import com.google.cloud.automl.v1beta1.InputConfig;
import com.google.cloud.automl.v1beta1.OperationMetadata;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.threeten.bp.Duration;

class ImportDataset {

  public static void main(String[] args)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "YOUR_PROJECT_ID";
    String datasetId = "YOUR_DATASET_ID";
    String path = "gs://BUCKET_ID/path_to_training_data.csv";
    importDataset(projectId, datasetId, path);
  }

  // Import a dataset
  static void importDataset(String projectId, String datasetId, String path)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    Duration totalTimeout = Duration.ofMinutes(45);
    RetrySettings retrySettings = RetrySettings.newBuilder().setTotalTimeout(totalTimeout).build();
    AutoMlSettings.Builder builder = AutoMlSettings.newBuilder();
    builder.importDataSettings().setRetrySettings(retrySettings).build();
    AutoMlSettings settings = builder.build();

    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create(settings)) {
      // Get the complete path of the dataset.
      DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId);

      // Get multiple Google Cloud Storage URIs to import data from
      GcsSource gcsSource =
          GcsSource.newBuilder().addAllInputUris(Arrays.asList(path.split(","))).build();

      // Import data from the input URI
      InputConfig inputConfig = InputConfig.newBuilder().setGcsSource(gcsSource).build();
      System.out.println("Processing import...");

      // Start the import job
      OperationFuture<Empty, OperationMetadata> operation =
          client.importDataAsync(datasetFullId, inputConfig);

      System.out.format("Operation name: %s%n", operation.getName());

      // If you want to wait for the operation to finish, adjust the timeout appropriately. The
      // operation will still run if you choose not to wait for it to complete. You can check the
      // status of your operation using the operation's name.
      Empty response = operation.get(45, TimeUnit.MINUTES);
      System.out.format("Dataset imported. %s%n", response);
    } catch (TimeoutException e) {
      System.out.println("The operation's polling period was not long enough.");
      System.out.println("You can use the Operation's name to get the current status.");
      System.out.println("The import job is still running and will complete as expected.");
      throw e;
    }
  }
}

Node.js

AutoML Video に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// const projectId = 'YOUR_PROJECT_ID';
// const location = 'us-central1';
// const datasetId = 'YOUR_DISPLAY_ID';
// const path = 'gs://BUCKET_ID/path_to_training_data.csv';

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

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

async function importDataset() {
  // Construct request
  const request = {
    name: client.datasetPath(projectId, location, datasetId),
    inputConfig: {
      gcsSource: {
        inputUris: path.split(','),
      },
    },
  };

  // Import dataset
  console.log('Proccessing import');
  const [operation] = await client.importData(request);

  // Wait for operation to complete.
  const [response] = await operation.promise();
  console.log(`Dataset imported: ${response}`);
}

importDataset();

Python

AutoML Video に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

from google.cloud import automl_v1beta1 as automl

def import_dataset(
    project_id="YOUR_PROJECT_ID",
    dataset_id="YOUR_DATASET_ID",
    path="gs://YOUR_BUCKET_ID/path/to/data.csv",
):
    """Import a dataset."""
    client = automl.AutoMlClient()
    # Get the full path of the dataset.
    dataset_full_id = client.dataset_path(project_id, "us-central1", dataset_id)
    # Get the multiple Google Cloud Storage URIs
    input_uris = path.split(",")
    gcs_source = automl.GcsSource(input_uris=input_uris)
    input_config = automl.InputConfig(gcs_source=gcs_source)
    # Import data from the input URI
    response = client.import_data(name=dataset_full_id, input_config=input_config)

    print("Processing import...")
    print(f"Data imported. {response.result()}")

トレーニング項目のラベル付け

モデルのトレーニングで役立つように、データセット内の各項目には少なくとも 1 つのカテゴリラベルが割り当てられている必要があります。AutoML Video ではカテゴリラベルのない項目は無視されます。トレーニング項目には、次の 2 つの方法でラベルを付けることができます。

  • .csv ファイルにラベルを含める
  • AutoML Video UI で項目にラベルを付ける

.csv ファイルで項目にラベルを付ける方法については、トレーニング データの準備をご覧ください。

AutoML Video UI で項目にラベルを付けるには、データセットの一覧ページからデータセットを選択してデータセットの詳細を表示します。 選択したデータセットの表示名がタイトルバーに表示され、データセット内の個々の項目がラベルと一緒にページに一覧表示されます。 左側のナビゲーション バーには、ラベル付き項目数とラベルなし項目数の要約が表示されます。項目の一覧をラベル別にフィルタすることもできます。

データセット内の動画

ラベルのない動画へのラベルの割り当てや動画のラベル変更は、次の手順で行います。

  1. データセットのページで、追加やラベル変更を行う動画をクリックします。
  2. 動画のページで次の操作を行います。

    1. [Add Segment] をクリックします。
    2. 動画のタイムラインの両側にある矢印をドラッグして、ラベルを付ける範囲を指定します。デフォルトでは、動画の最初から最後までが選択されます。
    3. ラベルのリストから、動画に付けるラベルをクリックします。選択すると、ラベルのカラーバーがはっきり表示されます。
    4. [保存] をクリックします。

階段をかけあがっている人の動画にラベルを付ける

データセットに新しいラベルを追加するには、データセットのページで、既存ラベルの一覧の上部にある [Filter labels] の横のその他のメニューをクリックし、[Add new label] をクリックします。

データセットの一覧表示

1 つのプロジェクトには多数のデータセットを含めることができます。このセクションでは、プロジェクトで使用できるデータセットを一覧表示する方法を説明します。

ウェブ UI

AutoML Video UI を使用して利用可能なデータセットを一覧表示するには、[Datasets] ページに移動します。

別のプロジェクトのデータセットを表示するには、タイトルバーの右上にあるプルダウン リストからプロジェクトを選択します。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • project-number: プロジェクトの番号。
  • location-id: アノテーションを実行する Cloud リージョン。サポート対象のクラウド リージョンは us-east1us-west1europe-west1asia-east1 です。リージョンを指定しないと、動画ファイルの場所に基づいてリージョンが決まります。

HTTP メソッドと URL:

 https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets

リクエストを送信するには、次のいずれかのオプションを展開します。

次のような JSON レスポンスが返されます。

Java

AutoML Video に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.cloud.automl.v1beta1.AutoMlClient;
import com.google.cloud.automl.v1beta1.Dataset;
import com.google.cloud.automl.v1beta1.ListDatasetsRequest;
import com.google.cloud.automl.v1beta1.LocationName;
import java.io.IOException;

class ListDatasets {

  static void listDatasets() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "YOUR_PROJECT_ID";
    listDatasets(projectId);
  }

  // List the datasets
  static void listDatasets(String projectId) throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
      // A resource that represents Google Cloud Platform location.
      LocationName projectLocation = LocationName.of(projectId, "us-central1");
      ListDatasetsRequest request =
          ListDatasetsRequest.newBuilder().setParent(projectLocation.toString()).build();

      // List all the datasets available in the region by applying filter.
      System.out.println("List of datasets:");
      for (Dataset dataset : client.listDatasets(request).iterateAll()) {
        // Display the dataset information
        System.out.format("%nDataset name: %s%n", dataset.getName());
        // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are
        // required for other methods.
        // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}`
        String[] names = dataset.getName().split("/");
        String retrievedDatasetId = names[names.length - 1];
        System.out.format("Dataset id: %s%n", retrievedDatasetId);
        System.out.format("Dataset display name: %s%n", dataset.getDisplayName());
        System.out.println("Dataset create time:");
        System.out.format("\tseconds: %s%n", dataset.getCreateTime().getSeconds());
        System.out.format("\tnanos: %s%n", dataset.getCreateTime().getNanos());

        System.out.format(
            "Video classification dataset metadata: %s%n",
            dataset.getVideoClassificationDatasetMetadata());
      }
    }
  }
}

Node.js

AutoML Video に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

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

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

async function listDatasets() {
  // Construct request
  const request = {
    parent: client.locationPath(projectId, location),
    filter: 'translation_dataset_metadata:*',
  };

  const [response] = await client.listDatasets(request);

  console.log('List of datasets:');
  for (const dataset of response) {
    console.log(`Dataset name: ${dataset.name}`);
    console.log(
      `Dataset id: ${
        dataset.name.split('/')[dataset.name.split('/').length - 1]
      }`
    );
    console.log(`Dataset display name: ${dataset.displayName}`);
    console.log('Dataset create time');
    console.log(`\tseconds ${dataset.createTime.seconds}`);
    console.log(`\tnanos ${dataset.createTime.nanos / 1e9}`);

    console.log(
      `Video classification dataset metadata: ${dataset.videoClassificationDatasetMetadata}`
    );
  }
}

listDatasets();

Python

AutoML Video に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

from google.cloud import automl_v1beta1 as automl

def list_datasets(project_id="YOUR_PROJECT_ID"):
    """List datasets."""
    client = automl.AutoMlClient()
    # A resource that represents Google Cloud Platform location.
    project_location = f"projects/{project_id}/locations/us-central1"

    # List all the datasets available in the region.
    request = automl.ListDatasetsRequest(parent=project_location, filter="")
    response = client.list_datasets(request=request)

    print("List of datasets:")
    for dataset in response:
        print(f"Dataset name: {dataset.name}")
        print("Dataset id: {}".format(dataset.name.split("/")[-1]))
        print(f"Dataset display name: {dataset.display_name}")
        print(f"Dataset create time: {dataset.create_time}")

        print(
            "Video classification dataset metadata: {}".format(
                dataset.video_classification_dataset_metadata
            )
        )

データセットの削除

次のコードは、データセットを削除する方法を示しています。

ウェブ UI

  1. AutoML Video UI で [Datasets] ページに移動します。

    [Create dataset] タブ
  2. 削除する行の右端にあるその他メニューをクリックし、[Delete dataset] を選択します。
  3. 確認ダイアログ ボックスで [確認] をクリックします。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • dataset-name: 完全なデータセット名。データセットの作成時にレスポンスで返されます。完全な名前の形式:
    projects/project-number/locations/location-id/datasets/dataset-id
    • project-number: プロジェクトの番号。
    • location-id: アノテーションを実行する Cloud リージョン。サポート対象のクラウド リージョンは us-east1us-west1europe-west1asia-east1 です。リージョンを指定しないと、動画ファイルの場所に基づいてリージョンが決まります。
    • dataset-id: データセットの作成時に指定された ID

HTTP メソッドと URL:

DELETE  https://automl.googleapis.com/v1beta1/dataset-name

リクエストを送信するには、次のいずれかのオプションを展開します。

次のような JSON レスポンスが返されます。

Java

AutoML Video に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

import com.google.cloud.automl.v1beta1.AutoMlClient;
import com.google.cloud.automl.v1beta1.DatasetName;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

class DeleteDataset {

  static void deleteDataset() throws IOException, ExecutionException, InterruptedException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "YOUR_PROJECT_ID";
    String datasetId = "YOUR_DATASET_ID";
    deleteDataset(projectId, datasetId);
  }

  // Delete a dataset
  static void deleteDataset(String projectId, String datasetId)
      throws IOException, ExecutionException, InterruptedException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
      // Get the full path of the dataset.
      DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId);
      Empty response = client.deleteDatasetAsync(datasetFullId).get();
      System.out.format("Dataset deleted. %s%n", response);
    }
  }
}

Node.js

AutoML Video に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

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

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

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

async function deleteDataset() {
  // Construct request
  const request = {
    name: client.datasetPath(projectId, location, datasetId),
  };

  const [operation] = await client.deleteDataset(request);

  // Wait for operation to complete.
  const [response] = await operation.promise();
  console.log(`Dataset deleted: ${response}`);
}

deleteDataset();

Python

AutoML Video に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

from google.cloud import automl_v1beta1 as automl

def delete_dataset(project_id="YOUR_PROJECT_ID", dataset_id="YOUR_DATASET_ID"):
    """Delete a dataset."""
    client = automl.AutoMlClient()
    # Get the full path of the dataset
    dataset_full_id = client.dataset_path(project_id, "us-central1", dataset_id)
    response = client.delete_dataset(name=dataset_full_id)

    print(f"Dataset deleted. {response.result()}")