|
| 1 | +/** |
| 2 | + * Copyright 2019, Google LLC |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +'use strict'; |
| 17 | + |
| 18 | +const {assert} = require('chai'); |
| 19 | +const cp = require('child_process'); |
| 20 | + |
| 21 | +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); |
| 22 | + |
| 23 | +/** Tests for AutoML Vision Object Detection "Model API" sample. */ |
| 24 | +// TODO(developer): Before running the test cases, |
| 25 | +// set the environment variables PROJECT_ID, REGION_NAME and |
| 26 | +// change the value of datasetId, deployModelId and undeployModelId |
| 27 | +const projectId = 'nodejs-docs-samples'; |
| 28 | +const computeRegion = 'us-central1'; |
| 29 | +const filter = 'imageObjectDetectionModelMetadata:*'; |
| 30 | +const datasetId = 'ICN3217071205693347964'; |
| 31 | +const testModelName = 'birds2_201804101601_base'; |
| 32 | +const deployModelId = 'IOD1728502647608049664'; |
| 33 | +const undeployModelId = 'IOD3348109663601164288'; |
| 34 | + |
| 35 | +describe(' Vision Object Detection ModelAPI', () => { |
| 36 | + it.skip(`should create a model`, async () => { |
| 37 | + let output = await execSync( |
| 38 | + `node vision/object-detection/create-model.v1beta1.js "${projectId}" "${computeRegion}" "${datasetId}" "${testModelName}"` |
| 39 | + ); |
| 40 | + const operationName = output |
| 41 | + .split('\n')[0] |
| 42 | + .split(':')[1] |
| 43 | + .trim(); |
| 44 | + assert.match(output, /Training started.../); |
| 45 | + |
| 46 | + output = await execSync( |
| 47 | + `node vision/object-detection/get-operation-status.v1beta1.js "${operationName}"` |
| 48 | + ); |
| 49 | + assert.match(output, /Operation details:/); |
| 50 | + }); |
| 51 | + |
| 52 | + it.skip(`should list models, get and delete a model. list, get and display model |
| 53 | + evaluations from preexisting models`, async () => { |
| 54 | + // List models |
| 55 | + let output = await execSync( |
| 56 | + `node vision/object-detection/list-models.v1beta1.js "${projectId}" "${computeRegion}" "${filter}"` |
| 57 | + ); |
| 58 | + const parsedOut = output.split('\n'); |
| 59 | + const outputModelId = parsedOut[3].split(':')[1].trim(); |
| 60 | + assert.match(output, /List of models:/); |
| 61 | + |
| 62 | + // Get Model |
| 63 | + output = await execSync( |
| 64 | + `node vision/object-detection/get-model.v1beta1.js "${projectId}" "${computeRegion}" "${outputModelId}"` |
| 65 | + ); |
| 66 | + assert.match(output, /Model name:/); |
| 67 | + |
| 68 | + // List model evaluation |
| 69 | + output = await execSync( |
| 70 | + `node vision/object-detection/list-model-evaluations.v1beta1.js "${projectId}" "${computeRegion}" "${outputModelId}"` |
| 71 | + ); |
| 72 | + const parsedModelEvaluation = output.split('\n'); |
| 73 | + const modelEvaluationId = parsedModelEvaluation[3].split(':')[1].trim(); |
| 74 | + assert.match(output, /Model evaluation Id:/); |
| 75 | + |
| 76 | + // Get model evaluation |
| 77 | + output = await execSync( |
| 78 | + `node vision/object-detection/get-model-evaluation.v1beta1.js "${projectId}" "${computeRegion}" "${outputModelId}"` + |
| 79 | + ` "${modelEvaluationId}"` |
| 80 | + ); |
| 81 | + assert.match(output, /Model evaluation Id:/); |
| 82 | + |
| 83 | + // Display evaluation |
| 84 | + output = await execSync( |
| 85 | + `node vision/object-detection/display-evaluation.v1beta1.js "${projectId}" "${computeRegion}" "${outputModelId}" ` |
| 86 | + ); |
| 87 | + assert.match(output, /Model Evaluation ID:/); |
| 88 | + |
| 89 | + // Delete Model |
| 90 | + output = await execSync( |
| 91 | + `node vision/object-detection/delete-model.v1beta1.js "${projectId}" "${computeRegion}" "${outputModelId}"` |
| 92 | + ); |
| 93 | + assert.match(output, /Model delete details:/); |
| 94 | + }); |
| 95 | + |
| 96 | + it.skip(`should list and get operation status`, async () => { |
| 97 | + // List operation status |
| 98 | + let output = await execSync( |
| 99 | + `node vision/object-detection/list-operations-status.v1beta1.js` |
| 100 | + ); |
| 101 | + const parsedOut = output.split('\n'); |
| 102 | + const operationFullId = parsedOut[3].split(':')[1].trim(); |
| 103 | + |
| 104 | + // Get operation status |
| 105 | + // Poll operation status, here confirming that operation is not complete yet |
| 106 | + output = await execSync( |
| 107 | + `node vision/object-detection/get-operation-status.v1beta1.js "${operationFullId}"` |
| 108 | + ); |
| 109 | + assert.match(output, /Operation details:/); |
| 110 | + }); |
| 111 | + |
| 112 | + it.skip(`should deploy the model`, async () => { |
| 113 | + // Deploy the model |
| 114 | + const output = await execSync( |
| 115 | + `node vision/object-detection/deploy-model.v1beta1.js "${projectId}" "${computeRegion}" ${deployModelId}` |
| 116 | + ); |
| 117 | + assert.match(output, /Name:/); |
| 118 | + }); |
| 119 | + |
| 120 | + it.skip(`should undeploy the model`, async () => { |
| 121 | + // Undeploy the model |
| 122 | + const output = await execSync( |
| 123 | + `node vision/object-detection/undeploy-model.v1beta1.js "${projectId}" "${computeRegion}" ${undeployModelId}` |
| 124 | + ); |
| 125 | + assert.match(output, /Name:/); |
| 126 | + }); |
| 127 | +}); |
0 commit comments