diff --git a/automl/beta/video-classification-create-dataset.js b/automl/beta/video-classification-create-dataset.js new file mode 100644 index 00000000000..a0402e3df67 --- /dev/null +++ b/automl/beta/video-classification-create-dataset.js @@ -0,0 +1,62 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main( + projectId = 'YOUR_PROJECT_ID', + location = 'us-central1', + displayName = 'YOUR_DISPLAY_NAME' +) { + // [START automl_video_classification_create_dataset_beta] + /** + * 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(); + // [END automl_video_classification_create_dataset_beta] +} + +main(...process.argv.slice(2)); diff --git a/automl/beta/video-classification-create-model.js b/automl/beta/video-classification-create-model.js new file mode 100644 index 00000000000..4639668bc8c --- /dev/null +++ b/automl/beta/video-classification-create-model.js @@ -0,0 +1,59 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main( + projectId = 'YOUR_PROJECT_ID', + location = 'us-central1', + datasetId = 'YOUR_DATASET_ID', + displayName = 'YOUR_DISPLAY_NAME' +) { + // [START automl_video_classification_create_model_beta] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + // const projectId = 'YOUR_PROJECT_ID'; + // const location = 'us-central1'; + // const dataset_id = 'YOUR_DATASET_ID'; + // 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 createModel() { + // Construct request + const request = { + parent: client.locationPath(projectId, location), + model: { + displayName: displayName, + datasetId: datasetId, + videoClassificationModelMetadata: {}, + }, + }; + + // Don't wait for the LRO + const [operation] = await client.createModel(request); + console.log(`Training started... ${operation}`); + console.log(`Training operation name: ${operation.name}`); + } + + createModel(); + // [END automl_video_classification_create_model_beta] +} + +main(...process.argv.slice(2)); diff --git a/automl/test/video-classification-create-dataset.beta.test.js b/automl/test/video-classification-create-dataset.beta.test.js new file mode 100644 index 00000000000..4e9addeecee --- /dev/null +++ b/automl/test/video-classification-create-dataset.beta.test.js @@ -0,0 +1,57 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +const {assert} = require('chai'); +const {after, describe, it} = require('mocha'); +const {AutoMlClient} = require('@google-cloud/automl').v1beta1; + +const cp = require('child_process'); +const uuid = require('uuid'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + +const CREATE_DATASET_REGION_TAG = 'beta/video-classification-create-dataset'; +const LOCATION = 'us-central1'; + +describe('Automl Video Classification Create Dataset Test', () => { + const client = new AutoMlClient(); + let datasetId; + + it('should create a dataset', async () => { + const projectId = await client.getProjectId(); + const displayName = `test_${uuid + .v4() + .replace(/-/g, '_') + .substring(0, 26)}`; + + // create + const create_output = execSync( + `node ${CREATE_DATASET_REGION_TAG}.js ${projectId} ${LOCATION} ${displayName}` + ); + assert.match(create_output, /Dataset id:/); + + datasetId = create_output.split('Dataset id: ')[1].split('\n')[0]; + }); + + after('delete created dataset', async () => { + const projectId = await client.getProjectId(); + const request = { + name: client.datasetPath(projectId, LOCATION, datasetId), + }; + const [operation] = await client.deleteDataset(request); + await operation.promise(); + }); +}); diff --git a/automl/test/video-classification-create-model.beta.test.js b/automl/test/video-classification-create-model.beta.test.js new file mode 100644 index 00000000000..b6f1e595048 --- /dev/null +++ b/automl/test/video-classification-create-model.beta.test.js @@ -0,0 +1,49 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +const {assert} = require('chai'); +const {after, describe, it} = require('mocha'); +const {AutoMlClient} = require('@google-cloud/automl').v1beta1; + +const cp = require('child_process'); + +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + +const CREATE_MODEL_REGION_TAG = 'beta/video-classification-create-model'; +const LOCATION = 'us-central1'; +const DATASET_ID = 'VCN6097385712296919040'; + +describe('Automl Video Classification Create Model Test', () => { + const client = new AutoMlClient(); + let operationId; + + it('should create a model', async () => { + const projectId = await client.getProjectId(); + const create_output = execSync( + `node ${CREATE_MODEL_REGION_TAG}.js ${projectId} ${LOCATION} ${DATASET_ID} video_test_create_model` + ); + + assert.match(create_output, /Training started/); + + operationId = create_output + .split('Training operation name: ')[1] + .split('\n')[0]; + }); + + after('cancel model training', async () => { + await client.operationsClient.cancelOperation({name: operationId}); + }); +});