Skip to content

Commit fab9636

Browse files
nnegreyJustinBeckwithbcoe
authored and
Ahrar Monsur
committed
docs: move and update beta video object tracking samples (#340)
Co-authored-by: Justin Beckwith <[email protected]> Co-authored-by: Benjamin E. Coe <[email protected]>
1 parent 1ceb9e7 commit fab9636

4 files changed

+227
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2020 Google LLC
2+
//
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+
// https://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+
'use strict';
16+
17+
function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
location = 'us-central1',
20+
displayName = 'YOUR_DISPLAY_NAME'
21+
) {
22+
// [START automl_video_object_tracking_create_dataset_beta]
23+
/**
24+
* TODO(developer): Uncomment these variables before running the sample.
25+
*/
26+
// const projectId = 'YOUR_PROJECT_ID';
27+
// const location = 'us-central1';
28+
// const displayName = 'YOUR_DISPLAY_NAME';
29+
30+
// Imports the Google Cloud AutoML library
31+
const {AutoMlClient} = require(`@google-cloud/automl`).v1beta1;
32+
33+
// Instantiates a client
34+
const client = new AutoMlClient();
35+
36+
async function createDataset() {
37+
// Construct request
38+
const request = {
39+
parent: client.locationPath(projectId, location),
40+
dataset: {
41+
displayName: displayName,
42+
videoObjectTrackingDatasetMetadata: {},
43+
},
44+
};
45+
46+
// Create dataset
47+
const [response] = await client.createDataset(request);
48+
49+
console.log(`Dataset name: ${response.name}`);
50+
console.log(`
51+
Dataset id: ${
52+
response.name
53+
.split('/')
54+
[response.name.split('/').length - 1].split('\n')[0]
55+
}`);
56+
}
57+
58+
createDataset();
59+
// [END automl_video_object_tracking_create_dataset_beta]
60+
}
61+
62+
main(...process.argv.slice(2));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2020 Google LLC
2+
//
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+
// https://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+
'use strict';
16+
17+
function main(
18+
projectId = 'YOUR_PROJECT_ID',
19+
location = 'us-central1',
20+
datasetId = 'YOUR_DATASET_ID',
21+
displayName = 'YOUR_DISPLAY_NAME'
22+
) {
23+
// [START automl_video_object_tracking_create_model_beta]
24+
/**
25+
* TODO(developer): Uncomment these variables before running the sample.
26+
*/
27+
// const projectId = 'YOUR_PROJECT_ID';
28+
// const location = 'us-central1';
29+
// const dataset_id = 'YOUR_DATASET_ID';
30+
// const displayName = 'YOUR_DISPLAY_NAME';
31+
32+
// Imports the Google Cloud AutoML library
33+
const {AutoMlClient} = require(`@google-cloud/automl`).v1beta1;
34+
35+
// Instantiates a client
36+
const client = new AutoMlClient();
37+
38+
async function createModel() {
39+
// Construct request
40+
const request = {
41+
parent: client.locationPath(projectId, location),
42+
model: {
43+
displayName: displayName,
44+
datasetId: datasetId,
45+
videoObjectTrackingModelMetadata: {},
46+
},
47+
};
48+
49+
// Don't wait for the LRO
50+
const [operation] = await client.createModel(request);
51+
console.log(`Training started... ${operation}`);
52+
console.log(`Training operation name: ${operation.name}`);
53+
}
54+
55+
createModel();
56+
// [END automl_video_object_tracking_create_model_beta]
57+
}
58+
59+
main(...process.argv.slice(2));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2020 Google LLC
2+
//
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+
// https://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+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const {after, describe, it} = require('mocha');
19+
const {AutoMlClient} = require('@google-cloud/automl').v1beta1;
20+
21+
const cp = require('child_process');
22+
const uuid = require('uuid');
23+
24+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
25+
26+
const CREATE_DATASET_REGION_TAG = 'beta/video-object-tracking-create-dataset';
27+
const LOCATION = 'us-central1';
28+
29+
describe('Automl Video Object Tracking Create Dataset Test', () => {
30+
const client = new AutoMlClient();
31+
let datasetId;
32+
33+
it('should create a dataset', async () => {
34+
const projectId = await client.getProjectId();
35+
const displayName = `test_${uuid
36+
.v4()
37+
.replace(/-/g, '_')
38+
.substring(0, 26)}`;
39+
40+
// create
41+
const create_output = execSync(
42+
`node ${CREATE_DATASET_REGION_TAG}.js ${projectId} ${LOCATION} ${displayName}`
43+
);
44+
assert.match(create_output, /Dataset id:/);
45+
46+
datasetId = create_output.split('Dataset id: ')[1].split('\n')[0];
47+
});
48+
49+
after('delete created dataset', async () => {
50+
const projectId = await client.getProjectId();
51+
const request = {
52+
name: client.datasetPath(projectId, LOCATION, datasetId),
53+
};
54+
const [operation] = await client.deleteDataset(request);
55+
await operation.promise();
56+
});
57+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2020 Google LLC
2+
//
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+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const {after, describe, it} = require('mocha');
19+
const {AutoMlClient} = require('@google-cloud/automl').v1beta1;
20+
21+
const cp = require('child_process');
22+
23+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
24+
25+
const CREATE_MODEL_REGION_TAG = 'beta/video-object-tracking-create-model';
26+
const LOCATION = 'us-central1';
27+
const DATASET_ID = 'VOT9082518000266903552';
28+
29+
describe('Automl Video Object Tracking Create Model Test', () => {
30+
const client = new AutoMlClient();
31+
let operationId;
32+
33+
it('should create a model', async () => {
34+
const projectId = await client.getProjectId();
35+
const create_output = execSync(
36+
`node ${CREATE_MODEL_REGION_TAG}.js ${projectId} ${LOCATION} ${DATASET_ID} video_test_create_model`
37+
);
38+
39+
assert.match(create_output, /Training started/);
40+
41+
operationId = create_output
42+
.split('Training operation name: ')[1]
43+
.split('\n')[0];
44+
});
45+
46+
after('cancel model training', async () => {
47+
await client.operationsClient.cancelOperation({name: operationId});
48+
});
49+
});

0 commit comments

Comments
 (0)