-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(samples): adds samples for enhanced version of library (#16)
- Loading branch information
Showing
40 changed files
with
2,868 additions
and
39 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
ai-platform/snippets/create-batch-prediction-job-video-classification.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright 2020 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 | ||
* | ||
* https://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'; | ||
|
||
async function main( | ||
batchPredictionDisplayName, | ||
modelId, | ||
gcsSourceUri, | ||
gcsDestinationOutputUriPrefix, | ||
project, | ||
location = 'us-central1' | ||
) { | ||
// [START aiplatform_create_batch_prediction_job_video_classification] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample.\ | ||
* (Not necessary if passing values as arguments) | ||
*/ | ||
|
||
// const batchPredictionDisplayName = 'YOUR_BATCH_PREDICTION_DISPLAY_NAME'; | ||
// const modelId = 'YOUR_MODEL_ID'; | ||
// const gcsSourceUri = 'YOUR_GCS_SOURCE_URI'; | ||
// const gcsDestinationOutputUriPrefix = 'YOUR_GCS_DEST_OUTPUT_URI_PREFIX'; | ||
// eg. "gs://<your-gcs-bucket>/destination_path" | ||
// const project = 'YOUR_PROJECT_ID'; | ||
// const location = 'YOUR_PROJECT_LOCATION'; | ||
const aiplatform = require('@google-cloud/aiplatform'); | ||
const { | ||
params, | ||
} = aiplatform.protos.google.cloud.aiplatform.v1beta1.schema.predict; | ||
|
||
// Imports the Google Cloud Job Service Client library | ||
const {JobServiceClient} = require('@google-cloud/aiplatform'); | ||
|
||
// Specifies the location of the api endpoint | ||
const clientOptions = { | ||
apiEndpoint: 'us-central1-aiplatform.googleapis.com', | ||
}; | ||
|
||
// Instantiates a client | ||
const jobServiceClient = new JobServiceClient(clientOptions); | ||
|
||
async function createBatchPredictionJobVideoClassification() { | ||
// Configure the parent resource | ||
const parent = `projects/${project}/locations/${location}`; | ||
const modelName = `projects/${project}/locations/${location}/models/${modelId}`; | ||
|
||
// For more information on how to configure the model parameters object, see | ||
// https://cloud.google.com/ai-platform-unified/docs/predictions/batch-predictions | ||
const modelParamsObj = new params.VideoClassificationPredictionParams({ | ||
confidenceThreshold: 0.5, | ||
maxPredictions: 1000, | ||
segmentClassification: true, | ||
shotClassification: true, | ||
oneSecIntervalClassification: true, | ||
}); | ||
|
||
const modelParameters = modelParamsObj.toValue(); | ||
|
||
const inputConfig = { | ||
instancesFormat: 'jsonl', | ||
gcsSource: {uris: [gcsSourceUri]}, | ||
}; | ||
const outputConfig = { | ||
predictionsFormat: 'jsonl', | ||
gcsDestination: {outputUriPrefix: gcsDestinationOutputUriPrefix}, | ||
}; | ||
const batchPredictionJob = { | ||
displayName: batchPredictionDisplayName, | ||
model: modelName, | ||
modelParameters, | ||
inputConfig, | ||
outputConfig, | ||
}; | ||
const request = { | ||
parent, | ||
batchPredictionJob, | ||
}; | ||
|
||
// Create batch prediction job request | ||
const [response] = await jobServiceClient.createBatchPredictionJob(request); | ||
|
||
console.log('Create batch prediction job video classification response'); | ||
console.log(`Name : ${response.name}`); | ||
console.log('Raw response:'); | ||
console.log(JSON.stringify(response, null, 2)); | ||
} | ||
createBatchPredictionJobVideoClassification(); | ||
// [END aiplatform_create_batch_prediction_job_video_classification] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
|
||
main(...process.argv.slice(2)); |
106 changes: 106 additions & 0 deletions
106
ai-platform/snippets/create-batch-prediction-job-video-object-tracking.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright 2020 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 | ||
* | ||
* https://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'; | ||
|
||
async function main( | ||
batchPredictionDisplayName, | ||
modelId, | ||
gcsSourceUri, | ||
gcsDestinationOutputUriPrefix, | ||
project, | ||
location = 'us-central1' | ||
) { | ||
// [START aiplatform_create_batch_prediction_job_video_object_tracking] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample.\ | ||
* (Not necessary if passing values as arguments) | ||
*/ | ||
|
||
// const batchPredictionDisplayName = 'YOUR_BATCH_PREDICTION_DISPLAY_NAME'; | ||
// const modelId = 'YOUR_MODEL_ID'; | ||
// const gcsSourceUri = 'YOUR_GCS_SOURCE_URI'; | ||
// const gcsDestinationOutputUriPrefix = 'YOUR_GCS_DEST_OUTPUT_URI_PREFIX'; | ||
// eg. "gs://<your-gcs-bucket>/destination_path" | ||
// const project = 'YOUR_PROJECT_ID'; | ||
// const location = 'YOUR_PROJECT_LOCATION'; | ||
const aiplatform = require('@google-cloud/aiplatform'); | ||
const { | ||
params, | ||
} = aiplatform.protos.google.cloud.aiplatform.v1beta1.schema.predict; | ||
|
||
// Imports the Google Cloud Job Service Client library | ||
const {JobServiceClient} = require('@google-cloud/aiplatform'); | ||
|
||
// Specifies the location of the api endpoint | ||
const clientOptions = { | ||
apiEndpoint: 'us-central1-aiplatform.googleapis.com', | ||
}; | ||
|
||
// Instantiates a client | ||
const jobServiceClient = new JobServiceClient(clientOptions); | ||
|
||
async function createBatchPredictionJobVideoObjectTracking() { | ||
// Configure the parent resource | ||
const parent = `projects/${project}/locations/${location}`; | ||
const modelName = `projects/${project}/locations/${location}/models/${modelId}`; | ||
|
||
// For more information on how to configure the model parameters object, see | ||
// https://cloud.google.com/ai-platform-unified/docs/predictions/batch-predictions | ||
const modelParamsObj = new params.VideoObjectTrackingPredictionParams({ | ||
confidenceThreshold: 0.5, | ||
}); | ||
|
||
const modelParameters = modelParamsObj.toValue(); | ||
|
||
const inputConfig = { | ||
instancesFormat: 'jsonl', | ||
gcsSource: {uris: [gcsSourceUri]}, | ||
}; | ||
const outputConfig = { | ||
predictionsFormat: 'jsonl', | ||
gcsDestination: {outputUriPrefix: gcsDestinationOutputUriPrefix}, | ||
}; | ||
const batchPredictionJob = { | ||
displayName: batchPredictionDisplayName, | ||
model: modelName, | ||
modelParameters, | ||
inputConfig, | ||
outputConfig, | ||
}; | ||
const request = { | ||
parent, | ||
batchPredictionJob, | ||
}; | ||
|
||
// Create batch prediction job request | ||
const [response] = await jobServiceClient.createBatchPredictionJob(request); | ||
|
||
console.log('Create batch prediction job video object tracking response'); | ||
console.log(`Name : ${response.name}`); | ||
console.log('Raw response:'); | ||
console.log(JSON.stringify(response, null, 2)); | ||
} | ||
createBatchPredictionJobVideoObjectTracking(); | ||
// [END aiplatform_create_batch_prediction_job_video_object_tracking] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
|
||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
ai-platform/snippets/create-training-pipeline-image-object-detection.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright 2020 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 | ||
* | ||
* https://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'; | ||
|
||
async function main( | ||
datasetId, | ||
modelDisplayName, | ||
trainingPipelineDisplayName, | ||
project, | ||
location = 'us-central1' | ||
) { | ||
// [START aiplatform_create_training_pipeline_image_object_detection] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample.\ | ||
* (Not necessary if passing values as arguments) | ||
*/ | ||
|
||
// const datasetId = 'YOUR_DATASET_ID'; | ||
// const modelDisplayName = 'YOUR_MODEL_DISPLAY_NAME'; | ||
// const trainingPipelineDisplayName = 'YOUR_TRAINING_PIPELINE_DISPLAY_NAME'; | ||
// const project = 'YOUR_PROJECT_ID'; | ||
// const location = 'YOUR_PROJECT_LOCATION'; | ||
|
||
const aiplatform = require('@google-cloud/aiplatform'); | ||
const { | ||
definition, | ||
} = aiplatform.protos.google.cloud.aiplatform.v1beta1.schema.trainingjob; | ||
const ModelType = definition.AutoMlImageObjectDetectionInputs.ModelType; | ||
|
||
// Imports the Google Cloud Pipeline Service Client library | ||
const {PipelineServiceClient} = aiplatform; | ||
|
||
// Specifies the location of the api endpoint | ||
const clientOptions = { | ||
apiEndpoint: 'us-central1-aiplatform.googleapis.com', | ||
}; | ||
|
||
// Instantiates a client | ||
const pipelineServiceClient = new PipelineServiceClient(clientOptions); | ||
|
||
async function createTrainingPipelineImageObjectDetection() { | ||
// Configure the parent resource | ||
const parent = `projects/${project}/locations/${location}`; | ||
|
||
const trainingTaskInputsObj = new definition.AutoMlImageObjectDetectionInputs( | ||
{ | ||
disableEarlyStopping: false, | ||
modelType: ModelType.CLOUD_HIGH_ACCURACY_1, | ||
budgetMilliNodeHours: 20000, | ||
} | ||
); | ||
|
||
const trainingTaskInputs = trainingTaskInputsObj.toValue(); | ||
const modelToUpload = {displayName: modelDisplayName}; | ||
const inputDataConfig = {datasetId: datasetId}; | ||
const trainingPipeline = { | ||
displayName: trainingPipelineDisplayName, | ||
trainingTaskDefinition: | ||
'gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_image_object_detection_1.0.0.yaml', | ||
trainingTaskInputs, | ||
inputDataConfig, | ||
modelToUpload, | ||
}; | ||
const request = { | ||
parent, | ||
trainingPipeline, | ||
}; | ||
|
||
// Create training pipeline request | ||
const [response] = await pipelineServiceClient.createTrainingPipeline( | ||
request | ||
); | ||
|
||
console.log('Create training pipeline image object detection response'); | ||
console.log(`Name : ${response.name}`); | ||
console.log('Raw response:'); | ||
console.log(JSON.stringify(response, null, 2)); | ||
} | ||
createTrainingPipelineImageObjectDetection(); | ||
// [END aiplatform_create_training_pipeline_image_object_detection] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
|
||
main(...process.argv.slice(2)); |
Oops, something went wrong.