|
| 1 | +# Copyright 2019 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 | + |
| 16 | +def get_model_evaluation(project_id, model_id, model_evaluation_id): |
| 17 | + """Get model evaluation.""" |
| 18 | + # [START automl_language_entity_extraction_get_model_evaluation] |
| 19 | + # [START automl_language_sentiment_analysis_get_model_evaluation] |
| 20 | + # [START automl_language_text_classification_get_model_evaluation] |
| 21 | + # [START automl_translate_get_model_evaluation] |
| 22 | + # [START automl_vision_classification_get_model_evaluation] |
| 23 | + # [START automl_vision_object_detection_get_model_evaluation] |
| 24 | + from google.cloud import automl |
| 25 | + |
| 26 | + # TODO(developer): Uncomment and set the following variables |
| 27 | + # project_id = "YOUR_PROJECT_ID" |
| 28 | + # model_id = "YOUR_MODEL_ID" |
| 29 | + # model_evaluation_id = "YOUR_MODEL_EVALUATION_ID" |
| 30 | + |
| 31 | + client = automl.AutoMlClient() |
| 32 | + # Get the full path of the model evaluation. |
| 33 | + model_evaluation_full_id = client.model_evaluation_path( |
| 34 | + project_id, "us-central1", model_id, model_evaluation_id |
| 35 | + ) |
| 36 | + |
| 37 | + # Get complete detail of the model evaluation. |
| 38 | + response = client.get_model_evaluation(model_evaluation_full_id) |
| 39 | + |
| 40 | + print("Model evaluation name: {}".format(response.name)) |
| 41 | + print("Model annotation spec id: {}".format(response.annotation_spec_id)) |
| 42 | + print("Create Time:") |
| 43 | + print("\tseconds: {}".format(response.create_time.seconds)) |
| 44 | + print("\tnanos: {}".format(response.create_time.nanos / 1e9)) |
| 45 | + print( |
| 46 | + "Evaluation example count: {}".format(response.evaluated_example_count) |
| 47 | + ) |
| 48 | + # [END automl_language_sentiment_analysis_get_model_evaluation] |
| 49 | + # [END automl_language_text_classification_get_model_evaluation] |
| 50 | + # [END automl_translate_get_model_evaluation] |
| 51 | + # [END automl_vision_classification_get_model_evaluation] |
| 52 | + # [END automl_vision_object_detection_get_model_evaluation] |
| 53 | + print( |
| 54 | + "Entity extraction model evaluation metrics: {}".format( |
| 55 | + response.text_extraction_evaluation_metrics |
| 56 | + ) |
| 57 | + ) |
| 58 | + # [END automl_language_entity_extraction_get_model_evaluation] |
| 59 | + |
| 60 | + # [START automl_language_sentiment_analysis_get_model_evaluation] |
| 61 | + print( |
| 62 | + "Sentiment analysis model evaluation metrics: {}".format( |
| 63 | + response.text_sentiment_evaluation_metrics |
| 64 | + ) |
| 65 | + ) |
| 66 | + # [END automl_language_sentiment_analysis_get_model_evaluation] |
| 67 | + |
| 68 | + # [START automl_language_text_classification_get_model_evaluation] |
| 69 | + # [START automl_vision_classification_get_model_evaluation] |
| 70 | + print( |
| 71 | + "Classification model evaluation metrics: {}".format( |
| 72 | + response.classification_evaluation_metrics |
| 73 | + ) |
| 74 | + ) |
| 75 | + # [END automl_language_text_classification_get_model_evaluation] |
| 76 | + # [END automl_vision_classification_get_model_evaluation] |
| 77 | + |
| 78 | + # [START automl_translate_get_model_evaluation] |
| 79 | + print( |
| 80 | + "Translation model evaluation metrics: {}".format( |
| 81 | + response.translation_evaluation_metrics |
| 82 | + ) |
| 83 | + ) |
| 84 | + # [END automl_translate_get_model_evaluation] |
| 85 | + |
| 86 | + # [START automl_vision_object_detection_get_model_evaluation] |
| 87 | + print( |
| 88 | + "Object detection model evaluation metrics: {}".format( |
| 89 | + response.image_object_detection_evaluation_metrics |
| 90 | + ) |
| 91 | + ) |
| 92 | + # [END automl_vision_object_detection_get_model_evaluation] |
0 commit comments