Skip to content

Commit ddf0e53

Browse files
nirupa-kumarAce Nassri
authored and
Ace Nassri
committed
docs(samples): add video-intelligence beta samples (#156)
* Adding video-intelligence beta samples * Skipping tests till fixed
1 parent 721a8f1 commit ddf0e53

19 files changed

+1461
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 execa = require('execa');
20+
21+
/** Tests for AutoML Video Intelligence Classification "Dataset API" sample. */
22+
23+
const cmdDataset = 'node automlVideoIntelligenceDataset.js';
24+
25+
// TODO(developer): Before running the test cases,
26+
// set the environment variables PROJECT_ID, REGION_NAME and
27+
// change the value of datasetId
28+
const projectId = process.env.PROJECT_ID;
29+
//const computeRegion = process.env.REGION_NAME;
30+
const bucket = projectId + '-video';
31+
const datasetName = 'test_video_dataset';
32+
const filter = 'videoClassificationDatasetMetadata:*';
33+
const datasetId = 'VCN1802794449273618432';
34+
const importDataCsv = 'gs://automl-video-demo-data/hmdb_split1.csv';
35+
36+
const exec = async cmd => (await execa.shell(cmd)).stdout;
37+
38+
describe.skip(`DatasetAPI`, () => {
39+
it(`should create, import and delete a dataset`, async () => {
40+
// Create dataset
41+
let output = await exec(`${cmdDataset} create-dataset "${datasetName}"`);
42+
const parsedOut = output.split('\n');
43+
const outputDatasetId = parsedOut[1].split(':')[1].trim();
44+
assert.match(output, /Dataset display name:/);
45+
46+
// Import data
47+
output = await exec(
48+
`${cmdDataset} import-data "${outputDatasetId}" "${importDataCsv}"`
49+
);
50+
assert.match(output, /Processing import.../);
51+
52+
// Delete dataset
53+
output = await exec(`${cmdDataset} delete-dataset "${outputDatasetId}"`);
54+
assert.match(output, /Dataset delete details:/);
55+
});
56+
57+
it(`should list datasets`, async () => {
58+
// List dataset
59+
const output = await exec(`${cmdDataset} list-datasets "${filter}"`);
60+
assert.match(output, /List of datasets:/);
61+
});
62+
63+
it(`should get preexisting dataset`, async () => {
64+
// Get dataset
65+
const output = await exec(`${cmdDataset} get-dataset "${datasetId}"`);
66+
assert.match(output, /Dataset display name:/);
67+
});
68+
69+
it(`should export dataset`, async () => {
70+
// Export data
71+
const outputUri = 'gs://' + bucket + '/' + datasetId;
72+
const output = await exec(
73+
`${cmdDataset} export-data "${datasetId}" "${outputUri}"`
74+
);
75+
assert.match(output, /Processing export.../);
76+
});
77+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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 execa = require('execa');
20+
21+
/** Tests for AutoML Video Intelligence Classification "Model API" sample. */
22+
23+
const cmdModel = 'node automlVideoIntelligenceModel.js';
24+
25+
// TODO(developer): Before running the test cases,
26+
// set the environment variables PROJECT_ID, REGION_NAME and
27+
// change the values of datasetId
28+
//const projectId = process.env.PROJECT_ID;
29+
//const computeRegion = process.env.REGION_NAME;
30+
const filter = 'videoClassificationModelMetadata:*';
31+
const datasetId = 'VCN1653190499151904768';
32+
const testModelName = 'test_video_model';
33+
34+
const exec = async cmd => (await execa.shell(cmd)).stdout;
35+
36+
describe.skip(`Video Intelligence ModelAPI`, () => {
37+
it(`should create a model`, async () => {
38+
// Create model
39+
let output = await exec(
40+
`${cmdModel} create-model "${datasetId}" "${testModelName}"`
41+
);
42+
const operationName = output
43+
.split('\n')[0]
44+
.split(':')[1]
45+
.trim();
46+
assert.match(output, /Training started.../);
47+
48+
output = await exec(`${cmdModel} get-operation-status "${operationName}"`);
49+
assert.match(output, /Operation details:/);
50+
});
51+
52+
it(`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 exec(`${cmdModel} list-models "${filter}"`);
56+
const parsedOut = output.split('\n');
57+
const ouputModelId = parsedOut[3].split(':')[1].trim();
58+
assert.match(output, /List of models:/);
59+
60+
// Get model
61+
output = await exec(`${cmdModel} get-model "${ouputModelId}"`);
62+
assert.match(output, /Model name:/);
63+
64+
// List model evaluations
65+
output = await exec(`${cmdModel} list-model-evaluations "${ouputModelId}"`);
66+
const parsedModelEvaluation = output.split('\n');
67+
const modelEvaluationId = parsedModelEvaluation[3].split(':')[1].trim();
68+
assert.match(output, /Model evaluation Id:/);
69+
70+
// Get model evaluation
71+
output = await exec(
72+
`${cmdModel} get-model-evaluation "${ouputModelId}" ` +
73+
`"${modelEvaluationId}"`
74+
);
75+
assert.match(output, /Model evaluation Id:/);
76+
77+
// Display evaluation
78+
output = await exec(`${cmdModel} display-evaluation "${ouputModelId}"`);
79+
assert.match(output, /Model Evaluation ID:/);
80+
81+
// Delete model
82+
output = await exec(`${cmdModel} delete-model "${ouputModelId}"`);
83+
assert.match(output, /Model delete details:/);
84+
});
85+
86+
it(`should list and get operation status`, async () => {
87+
// List operation status
88+
let output = await exec(`${cmdModel} list-operations-status`);
89+
const operationFullId = output
90+
.split('\n')[3]
91+
.split(':')[1]
92+
.trim();
93+
assert.match(output, /Operation details:/);
94+
95+
// Get operation status
96+
// Poll operation status, here confirming that operation is not complete yet
97+
output = await exec(
98+
`${cmdModel} get-operation-status "${operationFullId}"`
99+
);
100+
assert.match(output, /Operation details:/);
101+
});
102+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 execa = require('execa');
20+
21+
/** Tests for AutoML Video Intelligence Classification "Prediction API" sample.
22+
*/
23+
24+
const cmdPredict = 'node automlVideoIntelligencePrediction.js';
25+
26+
// TODO(developer): Before running the test cases,
27+
// set the environment variables PROJECT_ID, REGION_NAME and
28+
// change the values of modelId, inputUri and outputUriPrefix
29+
//const projectId = process.env.PROJECT_ID;
30+
//const computeRegion = process.env.REGION_NAME;
31+
const modelId = 'VCN5018751611309129728';
32+
const inputUri = 'gs://video-intelligence/input-csv/annotateVideo.csv';
33+
const outputUriPrefix = 'gs://video-intelligence/';
34+
35+
const exec = async cmd => (await execa.shell(cmd)).stdout;
36+
37+
describe.skip(`Video Intelligence PredictionAPI`, () => {
38+
it(`should run prediction from preexisting model`, async () => {
39+
// Run prediction on 'annotate_video.csv' from gcs inputUri
40+
const output = await exec(
41+
`${cmdPredict} predict "${modelId}" "${inputUri}" "${outputUriPrefix}"`
42+
);
43+
assert.match(output, /Operation name:/);
44+
});
45+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
async function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
computeRegion = 'YOUR_REGION_NAME',
20+
datasetName = 'YOUR_DATASET_NAME'
21+
) {
22+
// [START automl_video_intelligence_classification_create_dataset]
23+
const automl = require(`@google-cloud/automl`);
24+
const util = require(`util`);
25+
const client = new automl.v1beta1.AutoMlClient();
26+
27+
/**
28+
* Demonstrates using the AutoML client to create a dataset.
29+
* TODO(developer): Uncomment the following lines before running the sample.
30+
*/
31+
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
32+
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
33+
// const datasetName = '[DATASET_NAME]' e.g., "myDataset”;
34+
35+
// A resource that represents Google Cloud Platform location.
36+
const projectLocation = client.locationPath(projectId, computeRegion);
37+
38+
// Set dataset name and metadata.
39+
const myDataset = {
40+
displayName: datasetName,
41+
videoClassificationDatasetMetadata: {},
42+
};
43+
44+
// Create a dataset with the dataset metadata in the region.
45+
client
46+
.createDataset({parent: projectLocation, dataset: myDataset})
47+
.then(responses => {
48+
const dataset = responses[0];
49+
50+
// Display the dataset information.
51+
console.log(`Dataset name: ${dataset.name}`);
52+
console.log(`Dataset Id: ${dataset.name.split(`/`).pop(-1)}`);
53+
console.log(`Dataset display name: ${dataset.displayName}`);
54+
console.log(`Dataset example count: ${dataset.exampleCount}`);
55+
console.log(
56+
`Video classification dataset metadata: ${util.inspect(
57+
dataset.videoClassificationDatasetMetadata,
58+
false,
59+
null
60+
)}`
61+
);
62+
})
63+
.catch(err => {
64+
console.error(err);
65+
});
66+
// [END automl_video_intelligence_classification_create_dataset]
67+
}
68+
main(...process.argv.slice(2)).catch(console.error());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
async function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
computeRegion = 'YOUR_REGION_NAME',
20+
datasetId = 'YOUR_DATASET_ID',
21+
modelName = 'MODEL_NAME'
22+
) {
23+
// [START automl_video_intelligence_classification_create_model]
24+
const automl = require(`@google-cloud/automl`);
25+
const client = new automl.v1beta1.AutoMlClient();
26+
27+
/**
28+
* Demonstrates using the AutoML client to create a model.
29+
* TODO(developer): Uncomment the following lines before running the sample.
30+
*/
31+
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
32+
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
33+
// const datasetId = '[DATASET_ID]' e.g., "VCN7209576908164431872";
34+
// const modelName = '[MODEL_NAME]' e.g., "myModel";
35+
36+
// A resource that represents Google Cloud Platform location.
37+
const projectLocation = client.locationPath(projectId, computeRegion);
38+
39+
// Set datasetId, model name and model metadata for the dataset.
40+
const myModel = {
41+
displayName: modelName,
42+
datasetId: datasetId,
43+
videoClassificationModelMetadata: {},
44+
};
45+
46+
// Create a model with the model metadata in the region.
47+
client
48+
.createModel({parent: projectLocation, model: myModel})
49+
.then(responses => {
50+
const initialApiResponse = responses[1];
51+
console.log(`Training operation name: ${initialApiResponse.name}`);
52+
console.log(`Training started...`);
53+
})
54+
.catch(err => {
55+
console.error(err);
56+
});
57+
// [END automl_video_intelligence_classification_create_model]
58+
}
59+
main(...process.argv.slice(2)).catch(console.error());

0 commit comments

Comments
 (0)