diff --git a/automl/snippets/list_operation_status.js b/automl/snippets/list_operation_status.js index 4894d001e7e..49c98effd01 100644 --- a/automl/snippets/list_operation_status.js +++ b/automl/snippets/list_operation_status.js @@ -32,7 +32,7 @@ function main(projectId = 'YOUR_PROJECT_ID', location = 'us-central1') { // Construct request const request = { name: client.locationPath(projectId, location), - filter: '', + filter: `worksOn=projects/${projectId}/locations/${location}/models/*`, }; const [response] = await client.operationsClient.listOperations(request); diff --git a/automl/snippets/test/automlTablesDataset.v1beta1.test.js b/automl/snippets/test/automlTablesDataset.v1beta1.test.js deleted file mode 100644 index ab3e8d30973..00000000000 --- a/automl/snippets/test/automlTablesDataset.v1beta1.test.js +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright 2019 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 {describe, it} = require('mocha'); -const {execSync} = require('child_process'); - -/** Tests for AutoML Tables "Dataset API" sample. */ - -const cmdDataset = 'node automlTablesDataset.js'; - -// TODO(developer): Before running the test cases, set the environment variables -// PROJECT_ID, REGION_NAME and change the values of datasetId, -// bigQueryDatasetId, importDataCsv, outputGcsUri, outputGcsUri and -// outputBigQueryUri. -//const projectId = process.env.PROJECT_ID; -//const computeRegion = process.env.REGION_NAME; -const datasetName = 'test_table_dataset'; -const filter = 'tablesDatasetMetadata:*'; -const datasetId = 'TBL2246891593778855936'; -const bigQueryDatasetId = 'TBL5314616996204118016'; -const importDataCsv = 'gs://automl-tables/input/train.csv'; -const updateDatasetDisplayName = 'test_table_dataset_01'; -const dataTypeCode = 'CATEGORY'; -const outputGcsUri = 'gs://automl-tables/export-data/'; -const outputBigQueryUri = 'bq://automl-tables-bg-output'; - -const exec = cmd => execSync(cmd, {encoding: 'utf8'}); - -describe('Tables DatasetAPI', () => { - it.skip('should create, import, update and delete a dataset', async () => { - // Create dataset - let output = exec(`${cmdDataset} create-dataset "${datasetName}"`); - const parsedOut = output.split('\n'); - const outputDatasetId = parsedOut[1].split(':')[1].trim(); - assert.match(output, /Dataset display name:/); - - // Import data - output = exec( - `${cmdDataset} import-data "${outputDatasetId}" "${importDataCsv}"` - ); - assert.match(output, /Processing import.../); - - // Update dataset - output = exec( - `${cmdDataset} update-dataset "${outputDatasetId}"` + - ` "${updateDatasetDisplayName}"` - ); - assert.match(output, /Dataset Id:/); - - // Delete dataset - output = exec(`${cmdDataset} delete-dataset "${outputDatasetId}"`); - assert.match(output, /Dataset delete details:/); - }); - - it.skip('should list datasets', async () => { - // List dataset - const output = exec(`${cmdDataset} list-datasets "${filter}"`); - assert.match(output, /Dataset Id:/); - }); - - it.skip('should get preexisting dataset', async () => { - // Get dataset - const output = exec(`${cmdDataset} get-dataset "${datasetId}"`); - assert.match(output, /Dataset Id:/); - }); - - it.skip('should get,list,update tablespec and columnspec', async () => { - // List table - let output = exec( - `${cmdDataset} list-table-specs` + ` "${datasetId}" "${filter}"` - ); - let parsedOut = output.split('\n'); - const outputTableId = parsedOut[1].split(':')[1].trim().split('/')[7]; - assert.match(output, /Table Id:/); - - // Get table - output = exec( - `${cmdDataset} get-table-spec` + ` "${datasetId}" "${outputTableId}"` - ); - assert.match(output, /Table Id:/); - - // List column - output = exec( - `${cmdDataset} list-column-specs` + ` "${datasetId}" "${outputTableId}"` - ); - parsedOut = output.split('\n'); - const outputColumnId = parsedOut[1].split(':')[1].trim().split('/')[9]; - assert.match(output, /Column Id:/); - - // Get column - output = exec( - `${cmdDataset} get-column-spec` + - ` "${datasetId}" "${outputTableId}" "${outputColumnId}"` - ); - assert.match(output, /Column Id:/); - - // Update column - output = exec( - `${cmdDataset} update-column-spec` + - ` "${datasetId}" "${outputTableId}" "${outputColumnId}" "${dataTypeCode}"` - ); - assert.match(output, /Column Id:/); - }); - - it.skip('should export CSV dataset', async () => { - // Export data to csv - const output = exec( - `${cmdDataset} export-data-to-csv` + ` "${datasetId}" "${outputGcsUri}"` - ); - assert.match(output, /Processing export.../); - }); - - it.skip('should export BigQuery dataset', async () => { - // Export data to bigquery - const output = exec( - `${cmdDataset} export-data-to-bigquery` + - ` "${bigQueryDatasetId}" "${outputBigQueryUri}"` - ); - assert.match(output, /Processing export.../); - }); -}); diff --git a/automl/snippets/test/automlTablesModel.v1beta1.test.js b/automl/snippets/test/automlTablesModel.v1beta1.test.js deleted file mode 100644 index 494e65d572b..00000000000 --- a/automl/snippets/test/automlTablesModel.v1beta1.test.js +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2019 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 {describe, it} = require('mocha'); -const {execSync} = require('child_process'); - -/** Tests for AutoML Tables "Model API" sample. */ - -const cmdModel = 'node automlTablesModel.js'; - -// TODO(developer): Before running the test cases, set the environment variables -// PROJECT_ID, REGION_NAME and change the values of datasetId, tableId, -// columnId, bqOutputUri, deployModelId and undeployModelId. -//const projectId = process.env.PROJECT_ID; -//const computeRegion = process.env.REGION_NAME; -const datasetId = 'TBL2246891593778855936'; -const testModelName = 'test_tables_model'; -const tableId = '2071233616125362176'; -const columnId = '773141392279994368'; -const trainBudget = '1000'; -const bqOutputUri = 'bq://automl-tables-bg-output'; -const deployModelId = 'TBL4704590352927948800'; -const undeployModelId = 'TBL4508824506625687552'; -const filter = 'tablesModelMetadata:*'; - -const exec = cmd => execSync(cmd, {encoding: 'utf8'}); - -describe('Tables ModelAPI', () => { - it.skip('should create a model', async () => { - // Create model - let output = exec( - `${cmdModel} create-model "${datasetId}" "${tableId}" "${columnId}"` + - ` "${testModelName}" "${trainBudget}"` - ); - const operationName = output.split('\n')[0].split(':')[1].trim(); - assert.match(output, /Training started.../); - - output = exec(`${cmdModel} get-operation-status "${operationName}"`); - assert.match(output, /Operation details:/); - }); - - it.skip(`should list models, get and delete a model. list, get, export and display - model evaluations from preexisting models`, async () => { - // List models - let output = exec(`${cmdModel} list-models "${filter}"`); - const parsedOut = output.split('\n'); - const ouputModelId = parsedOut[3].split(':')[1].trim(); - assert.match(output, /List of models:/); - - // Get model - output = exec(`${cmdModel} get-model "${ouputModelId}"`); - assert.match(output, /Model name:/); - - // List model evaluations - output = exec(`${cmdModel} list-model-evaluations "${ouputModelId}"`); - const parsedModelEvaluation = output.split('\n'); - const modelEvaluationId = parsedModelEvaluation[2].split(':')[1].trim(); - assert.match(output, /Model evaluation Id:/); - - // Get model evaluation - output = exec( - `${cmdModel} get-model-evaluation "${ouputModelId}"` + - ` "${modelEvaluationId}"` - ); - assert.match(output, /Model evaluation Id:/); - - // Display evaluation - output = exec(`${cmdModel} display-evaluation "${ouputModelId}"`); - assert.match(output, /Model Evaluation ID:/); - - // Export evaluated examples - output = exec( - `${cmdModel} export-evaluated-examples "${ouputModelId}"` + - ` "${bqOutputUri}"` - ); - assert.match(output, /Operation name:/); - - // Delete model - output = exec(`${cmdModel} delete-model "${ouputModelId}"`); - assert.match(output, /Model delete details:/); - }); - - it.skip('should deploy the model', async () => { - // Deploy model - const output = exec(`${cmdModel} deploy-model "${deployModelId}"`); - assert.match(output, /Name:/); - }); - - it.skip('should undeploy the model', async () => { - // Undeploy model - const output = exec(`${cmdModel} undeploy-model "${undeployModelId}"`); - assert.match(output, /Name:/); - }); - - it.skip('should list and get operation status', async () => { - // List operations status - let output = exec(`${cmdModel} list-operations-status `); - const operationFullId = output.split('\n')[3].split(':')[1].trim(); - assert.match(output, /Operation details:/); - - // Get operation status - // Poll operation status, here confirming that operation is not complete yet - output = exec(`${cmdModel} get-operation-status "${operationFullId}"`); - assert.match(output, /Operation details:/); - }); -}); diff --git a/automl/snippets/test/automlTranslation.test.js b/automl/snippets/test/automlTranslation.test.js deleted file mode 100644 index 1317ff6f84e..00000000000 --- a/automl/snippets/test/automlTranslation.test.js +++ /dev/null @@ -1,91 +0,0 @@ -// 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 {describe, it} = require('mocha'); -const cp = require('child_process'); -const uuid = require('uuid'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const automl = require('@google-cloud/automl'); - -const cmdDataset = 'node translate/automlTranslateCreateDataset.js'; -const cmdModel = 'node translate/automlTranslateCreateModel.js'; -const cmdPredict = 'node translate/automlTranslatePredict.js'; - -const projectId = process.env.AUTOML_PROJECT_ID || 'cdpe-automl-tests'; -const datasetId = process.env.TRANSLATION_DATASET_ID; -const modelId = process.env.TRANSLATION_MODEL_ID; - -const samplePredictionText = './translate/resources/testInput.txt'; - -describe('Translate AutoML sample tests', () => { - it('should create and delete a dataset', async () => { - const datasetDisplayName = `test_${uuid - .v4() - .replace(/-/g, '_') - .substring(0, 20)}`; - - // Create dataset - let output = execSync( - `${cmdDataset} "${projectId}" "${datasetDisplayName}"` - ); - - //extract dataset id from the output - const newDatasetId = output.split('\n')[1].split(':')[1].trim(); - assert.match(output, /Dataset id:/); - - // Delete the created dataset - output = execSync( - `node delete_dataset.js ${projectId} us-central1 ${newDatasetId}` - ); - assert.match(output, /Dataset deleted/); - }); - - it.skip('should create model and cancel the training operation', async () => { - // create a model with pre-existing dataset - const output = execSync( - `${cmdModel} ${projectId} us-central1 ${datasetId} translate_test_model` - ); - assert.match(output, /Training started../); - }); - - it('should run Prediction from translation model', async () => { - // Verify the model is deployed before trying to predict - const client = new automl.AutoMlClient(); - - const modelFullId = { - name: client.modelPath(projectId, 'us-central1', modelId), - }; - - const [response] = await client.getModel(modelFullId); - if (response.deploymentState !== 'DEPLOYED') { - // Deploy model if it is not deployed - const [operation] = await client.deployModel(modelFullId); - - // Wait for operation to complete. - const [response] = await operation.promise(); - console.log(`Model deployment finished. ${response}`); - } - - // Run prediction on 'testInput.txt' in resources folder - const output = execSync( - `${cmdPredict} "${projectId}" us-central1 "${modelId}" "${samplePredictionText}" "False"` - ); - assert.match(output, /Translated Content:/); - }); -}); diff --git a/automl/snippets/test/automlVideoIntelligenceClassificationDataset.v1beta1.test.js b/automl/snippets/test/automlVideoIntelligenceClassificationDataset.v1beta1.test.js deleted file mode 100644 index 3f6fc832dc8..00000000000 --- a/automl/snippets/test/automlVideoIntelligenceClassificationDataset.v1beta1.test.js +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2019 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 {describe, it} = require('mocha'); -const {execSync} = require('child_process'); - -/** Tests for AutoML Video Intelligence Classification "Dataset API" sample. */ - -const cmdDataset = 'node automlVideoIntelligenceDataset.js'; - -// TODO(developer): Before running the test cases, -// set the environment variables PROJECT_ID, REGION_NAME and -// change the value of datasetId -const projectId = process.env.PROJECT_ID; -//const computeRegion = process.env.REGION_NAME; -const bucket = projectId + '-video'; -const datasetName = 'test_video_dataset'; -const filter = 'videoClassificationDatasetMetadata:*'; -const datasetId = 'VCN1802794449273618432'; -const importDataCsv = 'gs://automl-video-demo-data/hmdb_split1.csv'; - -const exec = cmd => execSync(cmd, {encoding: 'utf8'}); - -describe.skip('DatasetAPI', () => { - it('should create, import and delete a dataset', async () => { - // Create dataset - let output = exec(`${cmdDataset} create-dataset "${datasetName}"`); - const parsedOut = output.split('\n'); - const outputDatasetId = parsedOut[1].split(':')[1].trim(); - assert.match(output, /Dataset display name:/); - - // Import data - output = exec( - `${cmdDataset} import-data "${outputDatasetId}" "${importDataCsv}"` - ); - assert.match(output, /Processing import.../); - - // Delete dataset - output = exec(`${cmdDataset} delete-dataset "${outputDatasetId}"`); - assert.match(output, /Dataset delete details:/); - }); - - it('should list datasets', async () => { - // List dataset - const output = exec(`${cmdDataset} list-datasets "${filter}"`); - assert.match(output, /List of datasets:/); - }); - - it('should get preexisting dataset', async () => { - // Get dataset - const output = exec(`${cmdDataset} get-dataset "${datasetId}"`); - assert.match(output, /Dataset display name:/); - }); - - it('should export dataset', async () => { - // Export data - const outputUri = 'gs://' + bucket + '/' + datasetId; - const output = exec( - `${cmdDataset} export-data "${datasetId}" "${outputUri}"` - ); - assert.match(output, /Processing export.../); - }); -}); diff --git a/automl/snippets/test/automlVideoIntelligenceClassificationModel.v1beta1.test.js b/automl/snippets/test/automlVideoIntelligenceClassificationModel.v1beta1.test.js deleted file mode 100644 index 85ac1c4bca4..00000000000 --- a/automl/snippets/test/automlVideoIntelligenceClassificationModel.v1beta1.test.js +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2019 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 {describe, it} = require('mocha'); -const {execSync} = require('child_process'); - -/** Tests for AutoML Video Intelligence Classification "Model API" sample. */ - -const cmdModel = 'node automlVideoIntelligenceModel.js'; - -// TODO(developer): Before running the test cases, -// set the environment variables PROJECT_ID, REGION_NAME and -// change the values of datasetId -//const projectId = process.env.PROJECT_ID; -//const computeRegion = process.env.REGION_NAME; -const filter = 'videoClassificationModelMetadata:*'; -const datasetId = 'VCN1653190499151904768'; -const testModelName = 'test_video_model'; - -const exec = cmd => execSync(cmd, {encoding: 'utf8'}); - -describe.skip('Video Intelligence ModelAPI', () => { - it('should create a model', async () => { - // Create model - let output = exec( - `${cmdModel} create-model "${datasetId}" "${testModelName}"` - ); - const operationName = output.split('\n')[0].split(':')[1].trim(); - assert.match(output, /Training started.../); - - output = exec(`${cmdModel} get-operation-status "${operationName}"`); - assert.match(output, /Operation details:/); - }); - - it(`should list models, get and delete a model. list, get and display model - evaluations from preexisting models`, async () => { - // List models - let output = exec(`${cmdModel} list-models "${filter}"`); - const parsedOut = output.split('\n'); - const ouputModelId = parsedOut[3].split(':')[1].trim(); - assert.match(output, /List of models:/); - - // Get model - output = exec(`${cmdModel} get-model "${ouputModelId}"`); - assert.match(output, /Model name:/); - - // List model evaluations - output = exec(`${cmdModel} list-model-evaluations "${ouputModelId}"`); - const parsedModelEvaluation = output.split('\n'); - const modelEvaluationId = parsedModelEvaluation[3].split(':')[1].trim(); - assert.match(output, /Model evaluation Id:/); - - // Get model evaluation - output = exec( - `${cmdModel} get-model-evaluation "${ouputModelId}" ` + - `"${modelEvaluationId}"` - ); - assert.match(output, /Model evaluation Id:/); - - // Display evaluation - output = exec(`${cmdModel} display-evaluation "${ouputModelId}"`); - assert.match(output, /Model Evaluation ID:/); - - // Delete model - output = exec(`${cmdModel} delete-model "${ouputModelId}"`); - assert.match(output, /Model delete details:/); - }); - - it('should list and get operation status', async () => { - // List operation status - let output = exec(`${cmdModel} list-operations-status`); - const operationFullId = output.split('\n')[3].split(':')[1].trim(); - assert.match(output, /Operation details:/); - - // Get operation status - // Poll operation status, here confirming that operation is not complete yet - output = exec(`${cmdModel} get-operation-status "${operationFullId}"`); - assert.match(output, /Operation details:/); - }); -}); diff --git a/automl/snippets/test/automlVideoIntelligenceClassificationPredict.v1beta1.test.js b/automl/snippets/test/automlVideoIntelligenceClassificationPredict.v1beta1.test.js deleted file mode 100644 index 68788d4a8db..00000000000 --- a/automl/snippets/test/automlVideoIntelligenceClassificationPredict.v1beta1.test.js +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2019 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 {describe, it} = require('mocha'); -const {execSync} = require('child_process'); - -/** Tests for AutoML Video Intelligence Classification "Prediction API" sample. - */ - -const cmdPredict = 'node automlVideoIntelligencePrediction.js'; - -// TODO(developer): Before running the test cases, -// set the environment variables PROJECT_ID, REGION_NAME and -// change the values of modelId, inputUri and outputUriPrefix -//const projectId = process.env.PROJECT_ID; -//const computeRegion = process.env.REGION_NAME; -const modelId = 'VCN5018751611309129728'; -const inputUri = 'gs://video-intelligence/input-csv/annotateVideo.csv'; -const outputUriPrefix = 'gs://video-intelligence/'; - -const exec = cmd => execSync(cmd, {encoding: 'utf8'}); - -describe.skip('Video Intelligence PredictionAPI', () => { - it('should run prediction from preexisting model', async () => { - // Run prediction on 'annotate_video.csv' from gcs inputUri - const output = exec( - `${cmdPredict} predict "${modelId}" "${inputUri}" "${outputUriPrefix}"` - ); - assert.match(output, /Operation name:/); - }); -}); diff --git a/automl/snippets/test/automlVision.test.js b/automl/snippets/test/automlVision.test.js deleted file mode 100644 index f5de798c4b1..00000000000 --- a/automl/snippets/test/automlVision.test.js +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2018 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 path = require('path'); -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const cp = require('child_process'); - -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const cmdDataset = 'node vision/automlVisionDataset.js'; -const cmdModel = 'node vision/automlVisionModel.js'; -const cmdPredict = 'node vision/automlVisionPredict.js'; - -const testDataSetName = 'testDataSet'; -const dummyDataSet = 'dummyDataSet'; -const testModelName = 'dummyModel'; -const testImgPath = './resources/'; -const sampleImage2 = path.join(testImgPath, 'testImage2.jpg'); - -describe('auto ml vision', () => { - it.skip('should create, list, and delete a dataset', async () => { - // Check to see that this dataset does not yet exist - let output = execSync(`${cmdDataset} list-datasets`); - assert.strictEqual(output.includes(testDataSetName), false); - - // Create dataset - output = execSync(`${cmdDataset} create-dataset -n "${testDataSetName}"`); - const dataSetId = output.split('\n')[1].split(':')[1].trim(); - assert.match(output, new RegExp(testDataSetName)); - - // Delete dataset - output = execSync(`${cmdDataset} delete-dataset -i "${dataSetId}"`); - assert.match(output, /Dataset deleted./); - }); - - // See : https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/vision/automl/model_test.py - // We make two models running this test, see hard-coded workaround below - it.skip('should create a dataset, import data, and start making a model', async () => { - // Check to see that this dataset does not yet exist - let output = execSync(`${cmdDataset} list-datasets`); - assert.strictEqual(output.includes(dummyDataSet), false); - - // Create dataset - output = execSync(`${cmdDataset} create-dataset -n "${dummyDataSet}"`); - const dataSetId = output.split('\n')[1].split(':')[1].trim(); - assert.match(output, new RegExp(dummyDataSet)); - - // Import Data - output = execSync( - `${cmdDataset} import-data -i "${dataSetId}" -p "gs://nodejs-docs-samples-vcm/flowerTraindata20lines.csv"` - ); - assert.match(output, /Data imported./); - - // Check to make sure model doesn't already exist - output = execSync(`${cmdModel} list-models`); - assert.notMatch(output, new RegExp(testModelName)); - - // begin training dataset, getting operation ID for next operation - output = execSync(` - ${cmdModel} create-model -i "${dataSetId}" -m "${testModelName}" -t "2"`); - const operationName = output - .split('\n')[0] - .split(':')[1] - .split('/') - .pop() - .trim(); - assert.match(output, /Training started.../); - - // poll operation status, here confirming that operation is not complete yet - output = execSync( - `${cmdModel} get-operation-status -i "${dataSetId}" -o "${operationName}"` - ); - assert.match(output, /done: false/); - }); - - it.skip('should display evaluation from prexisting model', async () => { - const flowersModelId = 'ICN723541179344731436'; - const flowersDisplayName = 'flowersTest'; - - // Confirm dataset exists - let output = execSync(`${cmdDataset} list-datasets`); - assert.match(output, new RegExp(flowersDisplayName)); - - // List model evaluations, confirm model exists - output = execSync( - `${cmdModel} list-model-evaluations -a "${flowersModelId}"` - ); - - // Display evaluation - output = execSync(`${cmdModel} display-evaluation -a "${flowersModelId}"`); - assert.match(output, /Model Precision/); - }); - - it.skip('should run Prediction from prexisting model', async () => { - const donotdeleteModelId = 'ICN723541179344731436'; - const flowersDisplayName = 'flowers'; - - // Confirm dataset exists - let output = execSync(`${cmdDataset} list-datasets`); - assert.match(output, new RegExp(flowersDisplayName)); - - // List model evaluations, confirm model exists - output = execSync( - `${cmdModel} list-model-evaluations -a "${donotdeleteModelId}"` - ); - // Run prediction on 'testImage.jpg' in resources folder - output = execSync( - `${cmdPredict} predict -i "${donotdeleteModelId}" -f "${sampleImage2}" -s "0.5"` - ); - assert.match(output, /dandelion/); - }); - - // List datasets - it('should list datasets', async () => { - const output = execSync(`${cmdDataset} list-datasets`); - assert.match(output, /List of datasets:/); - }); -}); diff --git a/automl/snippets/test/language_sentiment_analysis_create_model.test.js b/automl/snippets/test/language_sentiment_analysis_create_model.test.js index d8320354909..39994297c5e 100644 --- a/automl/snippets/test/language_sentiment_analysis_create_model.test.js +++ b/automl/snippets/test/language_sentiment_analysis_create_model.test.js @@ -20,21 +20,22 @@ const {AutoMlClient} = require('@google-cloud/automl').v1; const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - const CREATE_MODEL_REGION_TAG = 'language_sentiment_analysis_create_model'; const LOCATION = 'us-central1'; -const DATASET_ID = 'TST8765214337653538816'; +const DATASET_ID = 'TST00000000000000000'; describe('Automl Natural Language Sentiment Analysis Create Model Test', () => { const client = new AutoMlClient(); - it.skip('should create a model', async () => { + it('should create a model', async () => { + // As sentimental analysis does not let you cancel model creation, instead try + // to create a model from a nonexistent dataset, but other elements of the + // request were valid. const projectId = await client.getProjectId(); - const create_output = execSync( - `node ${CREATE_MODEL_REGION_TAG}.js ${projectId} ${LOCATION} ${DATASET_ID} sentiment_test_create_model` - ); + const args = [CREATE_MODEL_REGION_TAG, projectId, LOCATION, DATASET_ID]; + const output = cp.spawnSync('node', args, {encoding: 'utf8'}); - assert.match(create_output, /Training started/); + assert.match(output.stderr, /NOT_FOUND/); + assert.match(output.stderr, /does not exist/); }); }); diff --git a/automl/snippets/test/language_text_classification_create_model.test.js b/automl/snippets/test/language_text_classification_create_model.test.js index 9827244b9c2..d90352e680c 100644 --- a/automl/snippets/test/language_text_classification_create_model.test.js +++ b/automl/snippets/test/language_text_classification_create_model.test.js @@ -20,21 +20,19 @@ const {AutoMlClient} = require('@google-cloud/automl').v1; const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - const CREATE_MODEL_REGION_TAG = 'language_text_classification_create_model'; const LOCATION = 'us-central1'; -const DATASET_ID = 'TCN4742936920458264576'; +const DATASET_ID = 'TCN00000000000000000'; describe('Automl Natural Language Text Classification Create Model Test', () => { const client = new AutoMlClient(); - it.skip('should create a model', async () => { + 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} classification_test_create_model` - ); + const args = [CREATE_MODEL_REGION_TAG, projectId, LOCATION, DATASET_ID]; + const output = cp.spawnSync('node', args, {encoding: 'utf8'}); - assert.match(create_output, /Training started/); + assert.match(output.stderr, /NOT_FOUND/); + assert.match(output.stderr, /Dataset does not exist./); }); }); diff --git a/automl/snippets/test/list_operation_status.test.js b/automl/snippets/test/list_operation_status.test.js index e3bda7bac91..f8ec88528e8 100644 --- a/automl/snippets/test/list_operation_status.test.js +++ b/automl/snippets/test/list_operation_status.test.js @@ -28,12 +28,12 @@ const LOCATION = 'us-central1'; describe('Automl List Operation Status Tests', () => { const client = new AutoMlClient(); - it.skip('should list operation status', async () => { + it('should list operation status', async () => { const projectId = await client.getProjectId(); const list_output = execSync( `node ${LIST_OPERATION_STATUS_REGION_TAG}.js ${projectId} ${LOCATION} ` ); - assert.match(list_output, /Operation details/); + assert.match(list_output, /List of operation status:/); }); }); diff --git a/automl/snippets/test/video-classification-create-model.beta.test.js b/automl/snippets/test/video-classification-create-model.beta.test.js index 5c6aeb51f2f..68642281358 100644 --- a/automl/snippets/test/video-classification-create-model.beta.test.js +++ b/automl/snippets/test/video-classification-create-model.beta.test.js @@ -20,21 +20,22 @@ 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'; +const DATASET_ID = 'VCN0000000000000000000'; describe('Automl Video Classification Create Model Test', () => { const client = new AutoMlClient(); - it.skip('should create a model', async () => { + it('should create a model', async () => { + // As video classification does not let you cancel model creation, instead try + // to create a model from a nonexistent dataset, but other elements of the + // request were valid. const projectId = await client.getProjectId(); - const create_output = execSync( - `node ${CREATE_MODEL_REGION_TAG}.js ${projectId} ${LOCATION} ${DATASET_ID} video_test_create_model` - ); + const args = [CREATE_MODEL_REGION_TAG, projectId, LOCATION, DATASET_ID]; + const output = cp.spawnSync('node', args, {encoding: 'utf8'}); - assert.match(create_output, /Training started/); + assert.match(output.stderr, /NOT_FOUND/); + assert.match(output.stderr, /Dataset does not exist./); }); }); diff --git a/automl/snippets/test/video-object-tracking-create-model.beta.test.js b/automl/snippets/test/video-object-tracking-create-model.beta.test.js index fb1845b4803..68021fe9a88 100644 --- a/automl/snippets/test/video-object-tracking-create-model.beta.test.js +++ b/automl/snippets/test/video-object-tracking-create-model.beta.test.js @@ -20,21 +20,22 @@ 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-object-tracking-create-model'; const LOCATION = 'us-central1'; -const DATASET_ID = 'VOT9082518000266903552'; +const DATASET_ID = 'VOT0000000000000000000'; describe('Automl Video Object Tracking Create Model Test', () => { const client = new AutoMlClient(); - it.skip('should create a model', async () => { + it('should create a model', async () => { + // As object detection does not let you cancel model creation, instead try + // to create a model from a nonexistent dataset, but other elements of the + // request were valid. const projectId = await client.getProjectId(); - const create_output = execSync( - `node ${CREATE_MODEL_REGION_TAG}.js ${projectId} ${LOCATION} ${DATASET_ID} video_test_create_model` - ); + const args = [CREATE_MODEL_REGION_TAG, projectId, LOCATION, DATASET_ID]; + const output = cp.spawnSync('node', args, {encoding: 'utf8'}); - assert.match(create_output, /Training started/); + assert.match(output.stderr, /NOT_FOUND/); + assert.match(output.stderr, /Dataset does not exist./); }); }); diff --git a/automl/snippets/test/vision_classification_create_model.test.js b/automl/snippets/test/vision_classification_create_model.test.js index f2b3906d8ef..59b9a79e288 100644 --- a/automl/snippets/test/vision_classification_create_model.test.js +++ b/automl/snippets/test/vision_classification_create_model.test.js @@ -20,21 +20,22 @@ const {AutoMlClient} = require('@google-cloud/automl').v1; const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - const CREATE_MODEL_REGION_TAG = 'vision_classification_create_model'; const LOCATION = 'us-central1'; -const DATASET_ID = 'ICN6257835245115015168'; +const DATASET_ID = 'ICN000000000000000000'; describe('Automl Vision Classification Create Model Tests', () => { const client = new AutoMlClient(); - it.skip('should create a model', async () => { + it('should create a model', async () => { + // As vision classification does not let you cancel model creation, instead try + // to create a model from a nonexistent dataset, but other elements of the + // request were valid. const projectId = await client.getProjectId(); - const create_output = execSync( - `node ${CREATE_MODEL_REGION_TAG}.js ${projectId} ${LOCATION} ${DATASET_ID} classification_test_create_model` - ); + const args = [CREATE_MODEL_REGION_TAG, projectId, LOCATION, DATASET_ID]; + const output = cp.spawnSync('node', args, {encoding: 'utf8'}); - assert.match(create_output, /Training started/); + assert.match(output.stderr, /NOT_FOUND/); + assert.match(output.stderr, /Dataset does not exist./); }); }); diff --git a/automl/snippets/test/vision_object_detection_create_model.test.js b/automl/snippets/test/vision_object_detection_create_model.test.js index 2c53feea98c..a867bc1e533 100644 --- a/automl/snippets/test/vision_object_detection_create_model.test.js +++ b/automl/snippets/test/vision_object_detection_create_model.test.js @@ -20,21 +20,22 @@ const {AutoMlClient} = require('@google-cloud/automl').v1; const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - const CREATE_MODEL_REGION_TAG = 'vision_object_detection_create_model'; const LOCATION = 'us-central1'; -const DATASET_ID = 'IOD4700715673951666176'; +const DATASET_ID = 'IOD0000000000000000000'; describe('Automl Vision Object Detection Create Model Test', () => { const client = new AutoMlClient(); - it.skip('should create a model', async () => { + it('should create a model', async () => { + // As object detection does not let you cancel model creation, instead try + // to create a model from a nonexistent dataset, but other elements of the + // request were valid. const projectId = await client.getProjectId(); - const create_output = execSync( - `node ${CREATE_MODEL_REGION_TAG}.js ${projectId} ${LOCATION} ${DATASET_ID} object_test_create_model` - ); + const args = [CREATE_MODEL_REGION_TAG, projectId, LOCATION, DATASET_ID]; + const output = cp.spawnSync('node', args, {encoding: 'utf8'}); - assert.match(create_output, /Training started/); + assert.match(output.stderr, /NOT_FOUND/); + assert.match(output.stderr, /Dataset does not exist./); }); }); diff --git a/automl/snippets/vision/automlVisionDataset.js b/automl/snippets/vision/automlVisionDataset.js deleted file mode 100644 index 1854ab3eb75..00000000000 --- a/automl/snippets/vision/automlVisionDataset.js +++ /dev/null @@ -1,290 +0,0 @@ -// Copyright 2018 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. - -/** - * This application demonstrates how to perform basic operations on dataset - * with the Google AutoML Vision API. - * - * For more information, see the documentation at - * https://cloud.google.com/vision/automl/docs/ - */ - -'use strict'; - -function createDataset(projectId, computeRegion, datasetName, multiLabel) { - // [START automl_vision_create_dataset] - async function automlVisionCreateDataset() { - const automl = require('@google-cloud/automl').v1beta1; - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const datasetName = `name of the dataset to create, e.g. “myDataset”`; - // const multiLabel = `type of classification problem, true for multilabel and false for multiclass e.g. "false"`; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // Classification type is assigned based on multilabel value. - let classificationType = 'MULTICLASS'; - if (multiLabel) { - classificationType = 'MULTILABEL'; - } - - // Specify the text classification type for the dataset. - const datasetMetadata = { - classificationType: classificationType, - }; - - // Set dataset name and metadata. - const myDataset = { - displayName: datasetName, - imageClassificationDatasetMetadata: datasetMetadata, - }; - - // Create a dataset with the dataset metadata in the region. - const [dataset] = await client.createDataset({ - parent: projectLocation, - dataset: myDataset, - }); - // Display the dataset information. - console.log(`Dataset name: ${dataset.name}`); - console.log(`Dataset id: ${dataset.name.split('/').pop(-1)}`); - console.log(`Dataset display name: ${dataset.displayName}`); - console.log(`Dataset example count: ${dataset.exampleCount}`); - console.log('Image Classification type:'); - console.log( - `\t ${dataset.imageClassificationDatasetMetadata.classificationType}` - ); - console.log('Dataset create time:'); - console.log(`\tseconds: ${dataset.createTime.seconds}`); - console.log(`\tnanos: ${dataset.createTime.nanos}`); - } - - automlVisionCreateDataset().catch(console.error); - // [END automl_vision_create_dataset] -} - -function listDatasets(projectId, computeRegion, filter) { - // [START automl_vision_list_datasets] - async function automlVisionListDatasets() { - const automl = require('@google-cloud/automl').v1beta1; - - const client = new automl.AutoMlClient(); - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const filter = `filter expressions, must specify field e.g. “imageClassificationModelMetadata:*”`; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // List all the datasets available in the region by applying filter. - const [datasets] = await client.listDatasets({ - parent: projectLocation, - filter: filter, - }); - console.log('List of datasets:'); - datasets.forEach(dataset => { - console.log(`Dataset name: ${dataset.name}`); - console.log(`Dataset Id: ${dataset.name.split('/').pop(-1)}`); - console.log(`Dataset display name: ${dataset.displayName}`); - console.log(`Dataset example count: ${dataset.exampleCount}`); - console.log('Image Classification type:'); - console.log( - '\t', - dataset.imageClassificationDatasetMetadata.classificationType - ); - console.log('Dataset create time: '); - console.log(`\tseconds: ${dataset.createTime.seconds}`); - console.log(`\tnanos: ${dataset.createTime.nanos}`); - console.log('\n'); - }); - } - - automlVisionListDatasets().catch(console.error); - // [END automl_vision_list_datasets] -} - -function importData(projectId, computeRegion, datasetId, path) { - // [START automl_vision_import_data] - async function automlVisionImportData() { - const automl = require('@google-cloud/automl').v1beta1; - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const datasetId = `Id of the dataset`; - // const path = `string or array of .csv paths in AutoML Vision CSV format, e.g. “gs://myproject/traindata.csv”;` - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath( - projectId, - computeRegion, - datasetId - ); - - // Get one or more Google Cloud Storage URI(s). - const inputUris = path.split(','); - const inputConfig = { - gcsSource: { - inputUris: inputUris, - }, - }; - - // Import the dataset from the input URI. - const [operation] = await client.importData({ - name: datasetFullId, - inputConfig: inputConfig, - }); - console.log('Processing import...'); - - const [, , response] = await operation.promise(); - - // The final result of the operation. - if (response.done) { - console.log('Data imported.'); - } - } - - automlVisionImportData().catch(console.error); - // [END automl_vision_import_data] -} - -function deleteDataset(projectId, computeRegion, datasetId) { - // [START automl_vision_delete_dataset] - async function automlVisionDeleteDataset() { - const automl = require('@google-cloud/automl').v1beta1; - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const datasetId = `Id of the dataset`; - - // Get the full path of the dataset. - const datasetFullId = client.datasetPath( - projectId, - computeRegion, - datasetId - ); - - // Delete a dataset. - const [operation] = await client.deleteDataset({name: datasetFullId}); - const [, , response] = await operation.promise(); - // The final result of the operation. - if (response.done) { - console.log('Dataset deleted.'); - } - } - - automlVisionDeleteDataset().catch(console.error); - // [END automl_vision_delete_dataset] -} - -require(`yargs`) // eslint-disable-line - .demand(1) - .options({ - computeRegion: { - alias: 'c', - type: 'string', - default: 'us-central1', - requiresArg: true, - description: 'region name e.g. "us-central1"', - }, - datasetName: { - alias: 'n', - type: 'string', - default: 'testDataSet', - requiresArg: true, - description: 'Name of the Dataset', - }, - datasetId: { - alias: 'i', - type: 'string', - requiresArg: true, - description: 'Id of the dataset', - }, - filter: { - alias: 'f', - default: 'image_classification_dataset_metadata:*', - type: 'string', - requiresArg: false, - description: 'Name of the Dataset to search for', - }, - multilabel: { - alias: 'm', - type: 'string', - default: false, - requiresArg: true, - description: - 'Type of the classification problem, ' + - 'False - MULTICLASS, True - MULTILABEL.', - }, - path: { - alias: 'p', - type: 'string', - global: true, - default: 'gs://nodejs-docs-samples-vcm/flowerTraindataMini.csv', - requiresArg: true, - description: 'URI or local path to input .csv, or array of .csv paths', - }, - projectId: { - alias: 'z', - type: 'string', - default: process.env.GCLOUD_PROJECT, - requiresArg: true, - description: 'The GCLOUD_PROJECT string, e.g. "my-gcloud-project"', - }, - }) - .command('create-dataset', 'creates a new Dataset', {}, opts => - createDataset( - opts.projectId, - opts.computeRegion, - opts.datasetName, - opts.multilabel - ) - ) - .command('list-datasets', 'list all Datasets', {}, opts => - listDatasets(opts.projectId, opts.computeRegion, opts.filter) - ) - .command('delete-dataset', 'Delete a dataset', {}, opts => - deleteDataset(opts.projectId, opts.computeRegion, opts.datasetId) - ) - .command('import-data', 'Import labeled items into dataset', {}, opts => - importData(opts.projectId, opts.computeRegion, opts.datasetId, opts.path) - ) - .example('node $0 create-dataset -n "newDataSet"') - .example('node $0 list-datasets -f "image_classification_dataset_metadata:*"') - .example('node $0 delete-dataset -i "DATASETID"') - .example( - 'node $0 import-data -i "dataSetId" -p "gs://myproject/mytraindata.csv"' - ) - .wrap(120) - .recommendCommands() - .help() - .strict().argv; diff --git a/automl/snippets/vision/automlVisionModel.js b/automl/snippets/vision/automlVisionModel.js deleted file mode 100644 index 5ce83f31463..00000000000 --- a/automl/snippets/vision/automlVisionModel.js +++ /dev/null @@ -1,489 +0,0 @@ -// Copyright 2018 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. - -/** - * This application demonstrates how to perform basic operations on dataset - * with the Google AutoML Vision API. - * - * For more information, see the documentation at - * https://cloud.google.com/vision/automl/docs/ - */ - -'use strict'; - -function createModel( - projectId, - computeRegion, - datasetId, - modelName, - trainBudget -) { - // [START automl_vision_create_model] - async function automlVisionCreateModel() { - const automl = require('@google-cloud/automl').v1beta1; - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const datasetId = `Id of the dataset`; - // const modelName = `Name of the model, e.g. "myModel"`; - // const trainBudget = `Budget for training model, e.g. 50`; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // Check train budget condition. - if (trainBudget === 0) { - trainBudget = {}; - } else { - trainBudget = {trainBudget: trainBudget}; - } - - // Set model name and model metadata for the dataset. - const myModel = { - displayName: modelName, - datasetId: datasetId, - imageClassificationModelMetadata: trainBudget, - }; - - // Create a model with the model metadata in the region. - const [operation, initialApiResponse] = await client.createModel({ - parent: projectLocation, - model: myModel, - }); - console.log('Training operation name: ', initialApiResponse.name); - console.log('Training started...'); - const [model] = await operation.promise(); - - // Retrieve deployment state. - let deploymentState = ''; - if (model.deploymentState === 1) { - deploymentState = 'deployed'; - } else if (model.deploymentState === 2) { - deploymentState = 'undeployed'; - } - - // Display the model information. - console.log(`Model name: ${model.name}`); - console.log(`Model id: ${model.name.split('/').pop(-1)}`); - console.log(`Model display name: ${model.displayName}`); - console.log('Model create time:'); - console.log(`\tseconds: ${model.createTime.seconds}`); - console.log(`\tnanos: ${model.createTime.nanos}`); - console.log(`Model deployment state: ${deploymentState}`); - } - - automlVisionCreateModel().catch(console.error); - // [END automl_vision_create_model] -} - -function listModels(projectId, computeRegion, filter) { - // [START automl_vision_list_models] - async function automlVisinListModels() { - const automl = require('@google-cloud/automl'); - - const client = new automl.v1beta1.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const filter = `filter expressions, must specify field, e.g. “imageClassificationModelMetadata:*”`; - - // A resource that represents Google Cloud Platform location. - const projectLocation = client.locationPath(projectId, computeRegion); - - // List all the models available in the region by applying filter. - const [models] = await client.listModels({ - parent: projectLocation, - filter: filter, - }); - - // Display the model information. - console.log('List of models:'); - models.forEach(model => { - console.log(`Model name: ${model.name}`); - console.log(`Model id: ${model.name.split('/').pop(-1)}`); - console.log(`Model display name: ${model.displayName}`); - console.log(`Model dataset id: ${model.datasetId}`); - if (model.modelMetadata === 'translationModelMetadata') { - console.log('Translation model metadata:'); - console.log( - `\tBase model: ${model.translationModelMetadata.baseModel}` - ); - console.log( - `\tSource language code: ${model.translationModelMetadata.sourceLanguageCode}` - ); - console.log( - `\tTarget language code: ${model.translationModelMetadata.targetLanguageCode}` - ); - } else if (model.modelMetadata === 'textClassificationModelMetadata') { - console.log( - `Text classification model metadata: ${model.textClassificationModelMetadata}` - ); - } else if (model.modelMetadata === 'imageClassificationModelMetadata') { - console.log('Image classification model metadata:'); - console.log( - `\tBase model id: ${model.imageClassificationModelMetadata.baseModelId}` - ); - console.log( - `\tTrain budget: ${model.imageClassificationModelMetadata.trainBudget}` - ); - console.log( - `\tTrain cost: ${model.imageClassificationModelMetadata.trainCost}` - ); - console.log( - `\tStop reason: ${model.imageClassificationModelMetadata.stopReason}` - ); - } - console.log('Model create time:'); - console.log(`\tseconds: ${model.createTime.seconds}`); - console.log(`\tnanos: ${model.createTime.nanos}`); - console.log('Model update time:'); - console.log(`\tseconds: ${model.updateTime.seconds}`); - console.log(`\tnanos: ${model.updateTime.nanos}`); - console.log(`Model deployment state: ${model.deploymentState}`); - console.log('\n'); - }); - } - - automlVisinListModels().catch(console.error); - // [END automl_vision_list_models] -} - -function getModel(projectId, computeRegion, modelId) { - // [START automl_vision_get_model] - - async function automlVisionGetModel() { - const automl = require('@google-cloud/automl').v1beta1; - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const modelId = `id of the model, e.g. “ICN12345”`; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Get complete detail of the model. - const [model] = await client.getModel({name: modelFullId}); - - // Display the model information. - console.log(`Model name: ${model.name}`); - console.log(`Model id: ${model.name.split('/').pop(-1)}`); - console.log(`Model display name: ${model.displayName}`); - console.log(`Model dataset id: ${model.datasetId}`); - if (model.modelMetadata === 'translationModelMetadata') { - console.log('Translation model metadata:'); - console.log(`\tBase model: ${model.translationModelMetadata.baseModel}`); - console.log( - `\tSource language code: ${model.translationModelMetadata.sourceLanguageCode}` - ); - console.log( - `\tTarget language code: ${model.translationModelMetadata.targetLanguageCode}` - ); - } else if (model.modelMetadata === 'textClassificationModelMetadata') { - console.log( - `Text classification model metadata: ${model.textClassificationModelMetadata}` - ); - } else if (model.modelMetadata === 'imageClassificationModelMetadata') { - console.log('Image classification model metadata:'); - console.log( - `\tBase model id: ${model.imageClassificationModelMetadata.baseModelId}` - ); - console.log( - `\tTrain budget: ${model.imageClassificationModelMetadata.trainBudget}` - ); - console.log( - `\tTrain cost: ${model.imageClassificationModelMetadata.trainCost}` - ); - console.log( - `\tStop reason: ${model.imageClassificationModelMetadata.stopReason}` - ); - } - console.log('Model create time:'); - console.log(`\tseconds: ${model.createTime.seconds}`); - console.log(`\tnanos: ${model.createTime.nanos}`); - console.log('Model update time:'); - console.log(`\tseconds: ${model.updateTime.seconds}`); - console.log(`\tnanos: ${model.updateTime.nanos}`); - console.log(`Model deployment state: ${model.deploymentState}`); - } - - automlVisionGetModel().catch(console.error); - // [END automl_vision_get_model] -} - -function listModelEvaluations(projectId, computeRegion, modelId, filter) { - // [START automl_vision_list_model_evaluations] - async function automlVisionListModelEvalution() { - const automl = require('@google-cloud/automl').v1beta1; - const util = require('util'); - - const client = new automl.AutoMlClient(); - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const modelId = `id of the model, e.g. “ICN12345”`; - // const filter = `filter expressions, must specify field, e.g. “imageClassificationModelMetadata:*”`; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // List all the model evaluations in the model by applying filter. - const [elements] = await client.listModelEvaluations({ - parent: modelFullId, - filter: filter, - }); - elements.forEach(element => { - console.log(util.inspect(element, false, null)); - }); - } - - automlVisionListModelEvalution().catch(console.error); - // [END automl_vision_list_model_evaluations] -} - -function displayEvaluation(projectId, computeRegion, modelId, filter) { - // [START automl_vision_display_evaluation] - async function automlVisionDisplayEvalution() { - const automl = require('@google-cloud/automl').v1beta1; - const math = require('mathjs'); - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const modelId = `id of the model, e.g. “ICN12345”`; - // const filter = `filter expressions, must specify field, e.g. “imageClassificationModelMetadata:*”`; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // List all the model evaluations in the model by applying filter. - const [response] = await client.listModelEvaluations({ - parent: modelFullId, - filter: filter, - }); - response.forEach(async element => { - // There is evaluation for each class in a model and for overall model. - // Get only the evaluation of overall model. - if (!element.annotationSpecId) { - const modelEvaluationId = element.name.split('/').pop(-1); - - // Resource name for the model evaluation. - const modelEvaluationFullId = client.modelEvaluationPath( - projectId, - computeRegion, - modelId, - modelEvaluationId - ); - - let modelEvaluation = null; - - (async () => { - [modelEvaluation] = await client.getModelEvaluation({ - name: modelEvaluationFullId, - }); - })(); - const classMetrics = modelEvaluation.classificationEvaluationMetrics; - const confidenceMetricsEntries = classMetrics.confidenceMetricsEntry; - - // Showing model score based on threshold of 0.5 - confidenceMetricsEntries.forEach(confidenceMetricsEntry => { - if (confidenceMetricsEntry.confidenceThreshold === 0.5) { - console.log( - 'Precision and recall are based on a score threshold of 0.5' - ); - console.log( - 'Model Precision: %', - math.round(confidenceMetricsEntry.precision * 100, 2) - ); - console.log( - 'Model Recall: %', - math.round(confidenceMetricsEntry.recall * 100, 2) - ); - console.log( - 'Model F1 score: %', - math.round(confidenceMetricsEntry.f1Score * 100, 2) - ); - console.log( - 'Model Precision@1: %', - math.round(confidenceMetricsEntry.precisionAt1 * 100, 2) - ); - console.log( - 'Model Recall@1: %', - math.round(confidenceMetricsEntry.recallAt1 * 100, 2) - ); - console.log( - 'Model F1 score@1: %', - math.round(confidenceMetricsEntry.f1ScoreAt1 * 100, 2) - ); - } - }); - } - }); - } - - automlVisionDisplayEvalution().catch(console.error); - // [END automl_vision_display_evaluation] -} - -function deleteModel(projectId, computeRegion, modelId) { - // [START automl_vision_delete_model] - async function automlVisionDeleteModel() { - const automl = require('@google-cloud/automl').v1beta1; - - const client = new automl.AutoMlClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const modelId = `id of the model, e.g. “ICN12345”`; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Delete a model. - const [operation] = await client.deleteModel({name: modelFullId}); - const [, , response] = await operation.promise(); - // The final result of the operation. - if (response.done) { - console.log('Model deleted.'); - } - } - - automlVisionDeleteModel().catch(console.error); - // [END automl_vision_delete_model] -} - -require(`yargs`) // eslint-disable-line - .demand(1) - .options({ - computeRegion: { - alias: 'c', - type: 'string', - default: 'us-central1', - requiresArg: true, - description: 'region name e.g. "us-central1"', - }, - datasetId: { - alias: 'i', - type: 'string', - requiresArg: true, - description: 'Id of the dataset', - }, - filter: { - alias: 'f', - default: '', - type: 'string', - requiresArg: true, - description: 'Name of the Dataset to search for', - }, - modelName: { - alias: 'm', - type: 'string', - default: false, - requiresArg: true, - description: 'Name of the model', - }, - modelId: { - alias: 'a', - type: 'string', - default: '', - requiresArg: true, - description: 'Id of the model', - }, - modelEvaluationId: { - alias: 'e', - type: 'string', - default: '', - requiresArg: true, - description: 'Id of the model evaluation', - }, - projectId: { - alias: 'z', - type: 'string', - default: process.env.GCLOUD_PROJECT, - requiresArg: true, - description: 'The GCLOUD_PROJECT string, e.g. "my-gcloud-project"', - }, - trainBudget: { - alias: 't', - type: 'string', - default: '', - requiresArg: true, - description: 'Budget for training the model', - }, - }) - .command('create-model', 'creates a new Model', {}, opts => - createModel( - opts.projectId, - opts.computeRegion, - opts.datasetId, - opts.modelName, - opts.trainBudget - ) - ) - .command('list-models', 'list all Models', {}, opts => - listModels(opts.projectId, opts.computeRegion, opts.filter) - ) - .command('get-model', 'Get a Model', {}, opts => - getModel(opts.projectId, opts.computeRegion, opts.modelId) - ) - .command('list-model-evaluations', 'List model evaluations', {}, opts => - listModelEvaluations( - opts.projectId, - opts.computeRegion, - opts.modelId, - opts.filter - ) - ) - .command('display-evaluation', 'Display evaluation', {}, opts => - displayEvaluation( - opts.projectId, - opts.computeRegion, - opts.modelId, - opts.filter - ) - ) - .command('delete-model', 'Delete a Model', {}, opts => - deleteModel(opts.projectId, opts.computeRegion, opts.modelId) - ) - .example('node $0 create-model -i "datasetId" -m "myModelName" -t "2"') - .example('node $0 list-models -f "image_classification_dataset_metadata:*"') - .example('node $0 get-model -a "ModelID"') - .example('node $0 list-model-evaluations -a "ModelID"') - .example('node $0 display-evaluation -a "ModelId"') - .example('node $0 delete-model -a "ModelID"') - .wrap(120) - .recommendCommands() - .help() - .strict().argv; diff --git a/automl/snippets/vision/automlVisionPredict.js b/automl/snippets/vision/automlVisionPredict.js deleted file mode 100644 index 62da6fead21..00000000000 --- a/automl/snippets/vision/automlVisionPredict.js +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright 2018 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. - -/** - * This application demonstrates how to perform basic operations on dataset - * with the Google AutoML Natural Language API. - * - * For more information, see the documentation at - * https://cloud.google.com/natural-language/automl/docs/ - */ - -'use strict'; - -function predict(projectId, computeRegion, modelId, filePath, scoreThreshold) { - // [START automl_vision_predict] - async function automlVisionPredict() { - const automl = require('@google-cloud/automl').v1beta1; - const fs = require('fs'); - - // Create client for prediction service. - const client = new automl.PredictionServiceClient(); - - /** - * TODO(developer): Uncomment the following line before running the sample. - */ - // const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`; - // const computeRegion = `region-name, e.g. "us-central1"`; - // const modelId = `id of the model, e.g. “ICN12345”`; - // const filePath = `local text file path of content to be classified, e.g. "./resources/test.txt"`; - // const scoreThreshold = `value between 0.0 and 1.0, e.g. "0.5"`; - - // Get the full path of the model. - const modelFullId = client.modelPath(projectId, computeRegion, modelId); - - // Read the file content for prediction. - const content = fs.readFileSync(filePath, 'base64'); - - const params = {}; - - if (scoreThreshold) { - params.score_threshold = scoreThreshold; - } - - // Set the payload by giving the content and type of the file. - const payload = {}; - payload.image = {imageBytes: content}; - - // params is additional domain-specific parameters. - // currently there is no additional parameters supported. - const [response] = await client.predict({ - name: modelFullId, - payload: payload, - params: params, - }); - console.log('Prediction results:'); - response.payload.forEach(result => { - console.log(`Predicted class name: ${result.displayName}`); - console.log(`Predicted class score: ${result.classification.score}`); - }); - } - - automlVisionPredict().catch(console.error); - // [END automl_vision_predict] -} - -require(`yargs`) // eslint-disable-line - .demand(1) - .options({ - computeRegion: { - alias: 'c', - type: 'string', - default: 'us-central1', - requiresArg: true, - description: 'region name e.g. "us-central1"', - }, - filePath: { - alias: 'f', - default: './resources/testImage.jpg', - type: 'string', - requiresArg: true, - description: 'local text file path of the content to be classified', - }, - modelId: { - alias: 'i', - //default: ``, - type: 'string', - requiresArg: true, - description: 'Id of the model which will be used for text classification', - }, - projectId: { - alias: 'z', - type: 'string', - default: process.env.GCLOUD_PROJECT, - requiresArg: true, - description: 'The GCLOUD_PROJECT string, e.g. "my-gcloud-project"', - }, - scoreThreshold: { - alias: 's', - type: 'string', - default: '0.5', - requiresArg: true, - description: - 'A value from 0.0 to 1.0. When the model makes predictions for an image it will' + - 'only produce results that have at least this confidence score threshold. Default is .5', - }, - }) - .command('predict', 'classify the content', {}, opts => - predict( - opts.projectId, - opts.computeRegion, - opts.modelId, - opts.filePath, - opts.scoreThreshold - ) - ) - .example( - 'node $0 predict -i "modelId" -f "./resources/testImage.jpg" -s "0.5"' - ) - .wrap(120) - .recommendCommands() - .help() - .strict().argv; diff --git a/automl/snippets/vision/object-detection/get-operation-status.v1beta1.js b/automl/snippets/vision/object-detection/get-operation-status.v1beta1.js deleted file mode 100644 index addb460c31b..00000000000 --- a/automl/snippets/vision/object-detection/get-operation-status.v1beta1.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2019 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(operationFullId = 'OPERATION_FULL_ID') { - // [START automl_vision_object_detection_get_operation_status] - /** - * Demonstrates using the AutoML client to get operation status. - * TODO(developer): Uncomment the following lines before running the sample. - */ - // const operationFullId = '[OPERATION_FULL_ID]' - // eg., "projects//locations/us-central1/operations/", - // `Full name of an operation`; - - //Imports the Google Cloud Automl library - const {AutoMlClient} = require('@google-cloud/automl').v1beta1; - - // Instantiates a client - const automlClient = new AutoMlClient(); - async function getOperationStatus() { - // Get the latest state of a long-running operation. - const [response] = await automlClient.operationsClient.getOperation({ - name: operationFullId, - }); - console.log('Operation details:'); - console.log(`\tName: ${response.name}`); - console.log('\tMetadata:'); - console.log(`\t\tType Url: ${response.metadata.typeUrl}`); - console.log(`\tDone: ${response.done}`); - - if (response.response) { - console.log('\tResponse:'); - console.log(`\t\tType Url: ${response.response.typeUrl}`); - } - - if (response.error) { - console.log('\tResponse:'); - console.log(`\t\tError code: ${response.error.code}`); - console.log(`\t\tError message: ${response.error.message}`); - } - } - getOperationStatus(); - // [END automl_vision_object_detection_get_operation_status] -} -main(...process.argv.slice(2)); diff --git a/automl/snippets/vision/resources/flowerTraindata20lines.csv b/automl/snippets/vision/resources/flowerTraindata20lines.csv deleted file mode 100644 index a0617c06e9d..00000000000 --- a/automl/snippets/vision/resources/flowerTraindata20lines.csv +++ /dev/null @@ -1,19 +0,0 @@ -gs://nodejs-docs-samples-vcm/daisy/14354051035_1037b30421_n.jpg,daisy -gs://nodejs-docs-samples-vcm/daisy/5586977262_6b24412805_n.jpg,daisy -gs://nodejs-docs-samples-vcm/daisy/14707111433_cce08ee007.jpg,daisy -gs://nodejs-docs-samples-vcm/daisy/2488902131_3417698611_n.jpg,daisy -gs://nodejs-docs-samples-vcm/daisy/506348009_9ecff8b6ef.jpg,daisy -gs://nodejs-docs-samples-vcm/daisy/2331133004_582772d58f_m.jpg,daisy -gs://nodejs-docs-samples-vcm/daisy/4511693548_20f9bd2b9c_m.jpg,daisy -gs://nodejs-docs-samples-vcm/daisy/12601254324_3cb62c254a_m.jpg,daisy -gs://nodejs-docs-samples-vcm/daisy/2473825306_62fd5f8785_n.jpg,daisy -gs://nodejs-docs-samples-vcm/dandelion/18089878729_907ed2c7cd_m.jpg,dandelion -gs://nodejs-docs-samples-vcm/dandelion/284497199_93a01f48f6.jpg,dandelion -gs://nodejs-docs-samples-vcm/dandelion/3554992110_81d8c9b0bd_m.jpg,dandelion -gs://nodejs-docs-samples-vcm/dandelion/4558536575_d43a611bd4_n.jpg,dandelion -gs://nodejs-docs-samples-vcm/dandelion/15782158700_3b9bf7d33e_m.jpg,dandelion -gs://nodejs-docs-samples-vcm/dandelion/8754822932_948afc7cef.jpg,dandelion -gs://nodejs-docs-samples-vcm/dandelion/2229906591_e953785d13.jpg,dandelion -gs://nodejs-docs-samples-vcm/dandelion/3991962484_085ba2da94.jpg,dandelion -gs://nodejs-docs-samples-vcm/dandelion/4500964841_b1142b50fb_n.jpg,dandelion -gs://nodejs-docs-samples-vcm/dandelion/7808545612_546cfca610_m.jpg,dandelion diff --git a/automl/snippets/vision/resources/songbird.jpg b/automl/snippets/vision/resources/songbird.jpg deleted file mode 100644 index f10312d084e..00000000000 Binary files a/automl/snippets/vision/resources/songbird.jpg and /dev/null differ diff --git a/automl/snippets/vision/resources/testImage.jpg b/automl/snippets/vision/resources/testImage.jpg deleted file mode 100644 index 852c4635210..00000000000 Binary files a/automl/snippets/vision/resources/testImage.jpg and /dev/null differ diff --git a/automl/snippets/vision/resources/testImage2.jpg b/automl/snippets/vision/resources/testImage2.jpg deleted file mode 100644 index 674a1aa4ea7..00000000000 Binary files a/automl/snippets/vision/resources/testImage2.jpg and /dev/null differ