|
| 1 | +/* |
| 2 | + * Copyright 2020 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +'use strict'; |
| 18 | + |
| 19 | +async function main( |
| 20 | + datasetId, |
| 21 | + modelDisplayName, |
| 22 | + trainingPipelineDisplayName, |
| 23 | + project, |
| 24 | + location = 'us-central1' |
| 25 | +) { |
| 26 | + // [START aiplatform_create_training_pipeline_video_action_recognition_sample] |
| 27 | + /** |
| 28 | + * TODO(developer): Uncomment these variables before running the sample.\ |
| 29 | + * (Not necessary if passing values as arguments) |
| 30 | + */ |
| 31 | + |
| 32 | + // const datasetId = 'YOUR_DATASET_ID'; |
| 33 | + // const modelDisplayName = 'YOUR_MODEL_DISPLAY_NAME'; |
| 34 | + // const trainingPipelineDisplayName = 'YOUR_TRAINING_PIPELINE_DISPLAY_NAME'; |
| 35 | + // const project = 'YOUR_PROJECT_ID'; |
| 36 | + // const location = 'YOUR_PROJECT_LOCATION'; |
| 37 | + const aiplatform = require('@google-cloud/aiplatform'); |
| 38 | + const {definition} = |
| 39 | + aiplatform.protos.google.cloud.aiplatform.v1.schema.trainingjob; |
| 40 | + |
| 41 | + // Imports the Google Cloud Pipeline Service Client library |
| 42 | + const {PipelineServiceClient} = aiplatform.v1; |
| 43 | + |
| 44 | + // Specifies the location of the api endpoint |
| 45 | + const clientOptions = { |
| 46 | + apiEndpoint: 'us-central1-aiplatform.googleapis.com', |
| 47 | + }; |
| 48 | + |
| 49 | + // Instantiates a client |
| 50 | + const pipelineServiceClient = new PipelineServiceClient(clientOptions); |
| 51 | + |
| 52 | + async function createTrainingPipelineVideoActionRecognition() { |
| 53 | + // Configure the parent resource |
| 54 | + const parent = `projects/${project}/locations/${location}`; |
| 55 | + // Values should match the input expected by your model. |
| 56 | + const trainingTaskInputObj = |
| 57 | + new definition.AutoMlVideoActionRecognitionInputs({ |
| 58 | + // modelType can be either 'CLOUD' or 'MOBILE_VERSATILE_1' |
| 59 | + modelType: 'CLOUD', |
| 60 | + }); |
| 61 | + const trainingTaskInputs = trainingTaskInputObj.toValue(); |
| 62 | + |
| 63 | + const modelToUpload = {displayName: modelDisplayName}; |
| 64 | + const inputDataConfig = {datasetId: datasetId}; |
| 65 | + const trainingPipeline = { |
| 66 | + displayName: trainingPipelineDisplayName, |
| 67 | + trainingTaskDefinition: |
| 68 | + 'gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_video_action_recognition_1.0.0.yaml', |
| 69 | + trainingTaskInputs, |
| 70 | + inputDataConfig, |
| 71 | + modelToUpload, |
| 72 | + }; |
| 73 | + const request = { |
| 74 | + parent, |
| 75 | + trainingPipeline, |
| 76 | + }; |
| 77 | + |
| 78 | + // Create training pipeline request |
| 79 | + const [response] = |
| 80 | + await pipelineServiceClient.createTrainingPipeline(request); |
| 81 | + |
| 82 | + console.log('Create training pipeline video action recognition response'); |
| 83 | + console.log(`Name : ${response.name}`); |
| 84 | + console.log('Raw response:'); |
| 85 | + console.log(JSON.stringify(response, null, 2)); |
| 86 | + } |
| 87 | + createTrainingPipelineVideoActionRecognition(); |
| 88 | + // [END aiplatform_create_training_pipeline_video_action_recognition_sample] |
| 89 | +} |
| 90 | + |
| 91 | +process.on('unhandledRejection', err => { |
| 92 | + console.error(err.message); |
| 93 | + process.exitCode = 1; |
| 94 | +}); |
| 95 | + |
| 96 | +main(...process.argv.slice(2)); |
0 commit comments