Skip to content

Commit

Permalink
docs(samples): move AutoML vision samples from nodejs-vision (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkwlui authored and Ace Nassri committed Nov 17, 2022
1 parent 8ea2939 commit 17ca755
Show file tree
Hide file tree
Showing 10 changed files with 1,227 additions and 8 deletions.
14 changes: 11 additions & 3 deletions automl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@
"**/*.test.js"
]
},
"scripts": {},
"scripts": {
"test": "mocha --timeout 600000"
},
"dependencies": {
"@google-cloud/automl": "^0.1.3"
"@google-cloud/automl": "^0.1.3",
"chai": "^4.2.0",
"execa": "^1.0.0",
"mathjs": "^5.5.0",
"yargs": "^13.2.1"
},
"devDependencies": {}
"devDependencies": {
"mocha": "^6.0.1"
}
}
5 changes: 0 additions & 5 deletions automl/system-test/.eslintrc.yml

This file was deleted.

3 changes: 3 additions & 0 deletions automl/test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
env:
mocha: true
139 changes: 139 additions & 0 deletions automl/test/automlVision.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
* 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 execa = require('execa');

const exec = async cmd => (await execa.shell(cmd)).stdout;
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 = await exec(`${cmdDataset} list-datasets`);
assert.strictEqual(output.includes(testDataSetName), false);

// Create dataset
output = await exec(`${cmdDataset} create-dataset -n "${testDataSetName}"`);
const dataSetId = output
.split(`\n`)[1]
.split(`:`)[1]
.trim();
assert.match(output, new RegExp(testDataSetName));

// Delete dataset
output = await exec(`${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 = await exec(`${cmdDataset} list-datasets`);
assert.strictEqual(output.includes(dummyDataSet), false);

// Create dataset
output = await exec(`${cmdDataset} create-dataset -n "${dummyDataSet}"`);
const dataSetId = output
.split(`\n`)[1]
.split(`:`)[1]
.trim();
assert.match(output, new RegExp(dummyDataSet));

// Import Data
output = await exec(
`${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 = await exec(`${cmdModel} list-models`);
assert.notMatch(output, new RegExp(testModelName));

// begin training dataset, getting operation ID for next operation
output = await exec(`
${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 = await exec(
`${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 = await exec(`${cmdDataset} list-datasets`);
assert.match(output, new RegExp(flowersDisplayName));

// List model evaluations, confirm model exists
output = await exec(
`${cmdModel} list-model-evaluations -a "${flowersModelId}"`
);

// Display evaluation
output = await exec(
`${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 = await exec(`${cmdDataset} list-datasets`);
assert.match(output, new RegExp(flowersDisplayName));

// List model evaluations, confirm model exists
output = await exec(
`${cmdModel} list-model-evaluations -a "${donotdeleteModelId}"`
);
// Run prediction on 'testImage.jpg' in resources folder
output = await exec(
`${cmdPredict} predict -i "${donotdeleteModelId}" -f "${sampleImage2}" -s "0.5"`
);
assert.match(output, /dandelion/);
});

// List datasets
it(`should list datasets`, async () => {
const output = await exec(`${cmdDataset} list-datasets`);
assert.match(output, /List of datasets:/);
});
});
Loading

0 comments on commit 17ca755

Please sign in to comment.