データセットの管理

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

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

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

モデルをトレーニングする前にデータを準備してください。

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

データセットの作成

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

ウェブ UI

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

  1. AutoML Video Object Tracking UI を開きます。[データセット] ページに、現在のプロジェクトにこれまでに作成されたデータセットのステータスが表示されます。Google Cloud Console でのプロジェクトのデータセットのリスト 別のプロジェクトのデータセットを追加するには、タイトルバーの右上にあるプルダウン リストからプロジェクトを選択します。
  2. [データセット] ページで、[データセットを作成] をクリックします。
  3. [新しいデータセットの作成] ダイアログで、次の操作を行います。
    • このデータセットの名前を指定します。
    • [動画オブジェクト トラッキング] を選択します。
    • [データセットを作成] をクリックします。
  4. データセットのページで、トレーニング データの URI を含む CSV ファイルの Cloud Storage URI を指定します。先頭の gs:// は外してください。
  5. 同じページで [続行] をクリックしてトレーニングを開始します。データセット「my_dataset」のページ

REST

次の例では、オブジェクト トラッキングのユースケースをサポートする my_dataset01 という名前のデータセットを作成します。新しく作成されたデータセットには、項目をインポートするまでデータは含まれません。

コマンドのレスポンスから新しいデータセットの "name" をメモしておきます。これはデータセットへの項目のインポートやモデルのトレーニングなどの操作で使用します。

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

  • dataset-name: ターゲット データセットの名前。
    例: my_dataset_01
  • 注:
    • 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",
    "videoObjectTrackingDatasetMetadata": { }
}

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

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 Object Tracking API からオペレーションの名前が返されます。返されるレスポンスの例は、次のとおりです。ここで、project-number はプロジェクトの数、operation-id はリクエストに対して作成された長時間実行オペレーションの ID です。たとえば、VOT12345.... です。

Java

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

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.VideoObjectTrackingDatasetMetadata;
import java.io.IOException;

class VideoObjectTrackingCreateDataset {

  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");
      VideoObjectTrackingDatasetMetadata metadata =
          VideoObjectTrackingDatasetMetadata.newBuilder().build();
      Dataset dataset =
          Dataset.newBuilder()
              .setDisplayName(displayName)
              .setVideoObjectTrackingDatasetMetadata(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 Object Tracking への認証を行うには、アプリケーションのデフォルト認証情報を設定します。 詳細については、ローカル開発環境の認証の設定をご覧ください。

/**
 * 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,
      videoObjectTrackingDatasetMetadata: {},
    },
  };

  // 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 Object Tracking への認証を行うには、アプリケーションのデフォルト認証情報を設定します。 詳細については、ローカル開発環境の認証の設定をご覧ください。

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 object tracking dataset."""
    client = automl.AutoMlClient()

    # A resource that represents Google Cloud Platform location.
    project_location = f"projects/{project_id}/locations/us-central1"
    metadata = automl.VideoObjectTrackingDatasetMetadata()
    dataset = automl.Dataset(
        display_name=display_name,
        video_object_tracking_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}")
    print("Dataset id: {}".format(created_dataset.name.split("/")[-1]))

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

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

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

ウェブ UI

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

ただし、データセットの作成後にデータをインポートする必要がある場合は、次の操作を行います。

  1. AutoML Video Object Tracking UI を開きます。[データセット] ページに、現在のプロジェクトにこれまでに作成されたデータセットのステータスが表示されます。Google Cloud Console でのプロジェクトのデータセットのリスト
  2. リストから、データのインポート先となるデータセットをクリックします。
  3. [インポート] タブで、トレーニング データの URI を含む CSV ファイルの Cloud Storage URI を指定します。先頭の gs:// は外してください。
  4. また、データセットの [インポート] タブで、[続行] をクリックしてインポートを開始します。データセット「my_dataset」のページ

REST

トレーニング データをインポートするには、importData メソッドを使用します。この方法では、次の 2 つのパラメータを指定する必要があります。

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

  • dataset-id: データセットの IDこの ID は、データセットの名前の最後の要素です。例:
    • データセット名: projects/project-number/locations/location-id/datasets/3104518874390609379
    • データセット ID: 3104518874390609379
  • bucket-name: モデル トレーニング ファイルリストの CSV ファイルを保存した Cloud Storage バケットの名前に置き換えます。
  • csv-file-name: モデル トレーニング ファイルリストの CSV ファイル名に置き換えます。
  • 注:
    • 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": ["gs://bucket-name/csv-file-name.csv"]
    }
  }
}

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

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 VOT7506374678919774208 を含むレスポンスを示しています。

Java

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

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 Object Tracking への認証を行うには、アプリケーションのデフォルト認証情報を設定します。 詳細については、ローカル開発環境の認証の設定をご覧ください。

/**
 * 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 Object Tracking への認証を行うには、アプリケーションのデフォルト認証情報を設定します。 詳細については、ローカル開発環境の認証の設定をご覧ください。

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 つの境界ボックスと 1 つのカテゴリラベルが割り当てられている必要があります。トレーニング項目には、次の 2 つの方法でラベルと境界ボックスを付けることができます。

  • CSV ファイルにラベルと境界ボックスを含める
  • AutoML Video Object Tracking UI でラベルと境界ボックスを適用する

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

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

データセット内の動画

ラベルのない動画へのラベルや境界ボックスの割り当て、または動画ラベルと境界ボックスを変更するには、次の操作を行います。

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

    1. ラベルを付ける項目が表示されるまで、動画を実行します。
    2. カーソルをドラッグしてアイテムの周囲に境界ボックスを描画します。
    3. 境界ボックスを描画したら、使用するラベルを選択します。
    4. [保存] をクリックします。

動画内で牛を囲む境界ボックスを描画する

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

データ内のラベルの変更

データセット内の動画に適用されているラベルを変更することもできます。AutoML Video Object Tracking UI で、次の操作を行います。

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

    1. 左側のラベルのリストで、変更するラベルを選択します。
    2. 動画のプレビューで、動画の境界ボックスを右クリックして、目的のラベルを選択します。
    3. [保存] をクリックします。

動画内のセダンに適用されたラベルの変更

データセットの一覧表示

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

ウェブ UI

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

プロジェクト内のデータセットを一覧表示します。

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

REST

次の curl または PowerShell コマンドを使用して、データセットのリストと、データセットにインポートされたサンプル動画の数を取得します。

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

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

HTTP メソッドと URL:

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

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

curl

次のコマンドを実行します。

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-number" \
"https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets "

PowerShell

次のコマンドを実行します。

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

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets " | Select-Object -Expand Content
下記のレスポンスの VOT3940649673949184000 は、リクエストに対して作成され、オペレーション開始時にレスポンスで指定された、長時間実行オペレーションのオペレーション ID です。

Java

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

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 object tracking dataset metadata: %s%n",
            dataset.getVideoObjectTrackingDatasetMetadata());
      }
    }
  }
}

Node.js

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

/**
 * 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 object tracking dataset metadata: ${dataset.videoObjectTrackingDatasetMetadata}`
    );
  }
}

listDatasets();

Python

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

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 object tracking dataset metadata: {}".format(
                dataset.video_object_tracking_dataset_metadata
            )
        )

データセットの削除

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

ウェブ UI

  1. AutoML Video Object Tracking UI で [データセット] ページに移動します。

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

REST

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

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

HTTP メソッドと URL:

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

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

成功したことを示すステータス コード(2xx)と空のレスポンスが返されます。

Java

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

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 Object Tracking への認証を行うには、アプリケーションのデフォルト認証情報を設定します。 詳細については、ローカル開発環境の認証の設定をご覧ください。

/**
 * 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 Object Tracking への認証を行うには、アプリケーションのデフォルト認証情報を設定します。 詳細については、ローカル開発環境の認証の設定をご覧ください。

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()}")