This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
/
get-model-evaluations.v1beta1.js
129 lines (122 loc) · 4 KB
/
get-model-evaluations.v1beta1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* Copyright 2019, 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`;
async function main(
projectId = 'YOUR_PROJECT_ID',
computeRegion = 'YOUR_REGION_NAME',
modelId = 'MODEL_ID',
modelEvaluationId = 'MODEL_EVALUATION_ID'
) {
// [START automl_video_intelligence_classification_get_model_evaluation]
const automl = require(`@google-cloud/automl`);
const math = require(`mathjs`);
const client = new automl.v1beta1.AutoMlClient();
/**
* Demonstrates using the AutoML client to get model evaluations.
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
// const computeRegion = '[REGION_NAME]' e.g., "us-central1";
// const modelId = '[MODEL_ID]' e.g., "VCN7209576908164431872";
// const modelEvaluationId = '[MODEL_EVALUATION_ID]'
// e.g., "3806191078210741236";
// Get the full path of the model evaluation.
const modelEvaluationFullId = client.modelEvaluationPath(
projectId,
computeRegion,
modelId,
modelEvaluationId
);
// Get complete detail of the model evaluation.
client
.getModelEvaluation({name: modelEvaluationFullId})
.then(responses => {
const response = responses[0];
const confidenceMetricsEntries =
response.classificationEvaluationMetrics.confidenceMetricsEntry;
// Display the model evaluations information.
console.log(`\nModel evaluation name: ${response.name}`);
console.log(
`Model evaluation Id: ${response.name
.split(`/`)
.slice(-1)
.pop()}`
);
console.log(
`Model evaluation annotation spec Id: ${response.annotationSpecId}`
);
console.log(`Model evaluation display name: ${response.displayName}`);
console.log(
`Model evaluation example count: ${response.evaluatedExampleCount}`
);
console.log(`Video classification evaluation metrics:`);
console.log(
`\tModel auPrc: ${math.round(
response.classificationEvaluationMetrics.auPrc,
6
)}`
);
console.log(`\tConfidence metrics entries:`);
for (const confidenceMetricsEntry of confidenceMetricsEntries) {
console.log(
`\t\tModel confidenceThreshold: ${math.round(
confidenceMetricsEntry.confidenceThreshold,
6
)}`
);
console.log(
`\t\tModel recall: ${math.round(
confidenceMetricsEntry.recall * 100,
2
)} %`
);
console.log(
`\t\tModel precision: ${math.round(
confidenceMetricsEntry.precision * 100,
2
)} %`
);
console.log(
`\t\tModel f1 score: ${math.round(
confidenceMetricsEntry.f1Score * 100,
2
)} %`
);
console.log(
`\t\tModel recall@1: ${math.round(
confidenceMetricsEntry.recallAt1 * 100,
2
)} %`
);
console.log(
`\t\tModel precision@1: ${math.round(
confidenceMetricsEntry.precisionAt1 * 100,
2
)} %`
);
console.log(
`\t\tModel f1 score@1: ${math.round(
confidenceMetricsEntry.f1ScoreAt1 * 100,
2
)} % \n`
);
}
})
.catch(err => {
console.error(err);
});
// [END automl_video_intelligence_classification_get_model_evaluation]
}
main(...process.argv.slice(2)).catch(console.error());