diff --git a/vision/automl/automl_vision_dataset.py b/vision/automl/automl_vision_dataset.py deleted file mode 100755 index 1af60cd46f0..00000000000 --- a/vision/automl/automl_vision_dataset.py +++ /dev/null @@ -1,291 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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. - -"""This application demonstrates how to perform basic operations on dataset -with the Google AutoML Vision API. - -For more information, the documentation at -https://cloud.google.com/vision/automl/docs. -""" - -import argparse -import os - - -def create_dataset(project_id, compute_region, dataset_name, multilabel=False): - """Create a dataset.""" - # [START automl_vision_create_dataset] - # TODO(developer): Uncomment and set the following variables - # project_id = 'PROJECT_ID_HERE' - # compute_region = 'COMPUTE_REGION_HERE' - # dataset_name = 'DATASET_NAME_HERE' - # multilabel = True for multilabel or False for multiclass - - from google.cloud import automl_v1beta1 as automl - - client = automl.AutoMlClient() - - # A resource that represents Google Cloud Platform location. - project_location = client.location_path(project_id, compute_region) - - # Classification type is assigned based on multilabel value. - classification_type = "MULTICLASS" - if multilabel: - classification_type = "MULTILABEL" - - # Specify the image classification type for the dataset. - dataset_metadata = {"classification_type": classification_type} - # Set dataset name and metadata of the dataset. - my_dataset = { - "display_name": dataset_name, - "image_classification_dataset_metadata": dataset_metadata, - } - - # Create a dataset with the dataset metadata in the region. - dataset = client.create_dataset(project_location, my_dataset) - - # Display the dataset information. - print("Dataset name: {}".format(dataset.name)) - print("Dataset id: {}".format(dataset.name.split("/")[-1])) - print("Dataset display name: {}".format(dataset.display_name)) - print("Image classification dataset metadata:") - print("\t{}".format(dataset.image_classification_dataset_metadata)) - print("Dataset example count: {}".format(dataset.example_count)) - print("Dataset create time:") - print("\tseconds: {}".format(dataset.create_time.seconds)) - print("\tnanos: {}".format(dataset.create_time.nanos)) - - # [END automl_vision_create_dataset] - - -def list_datasets(project_id, compute_region, filter_): - """List all datasets.""" - # [START automl_vision_list_datasets] - # TODO(developer): Uncomment and set the following variables - # project_id = 'PROJECT_ID_HERE' - # compute_region = 'COMPUTE_REGION_HERE' - # filter_ = 'filter expression here' - - from google.cloud import automl_v1beta1 as automl - - client = automl.AutoMlClient() - - # A resource that represents Google Cloud Platform location. - project_location = client.location_path(project_id, compute_region) - - # List all the datasets available in the region by applying filter. - response = client.list_datasets(project_location, filter_) - - print("List of datasets:") - for dataset in response: - # Display the dataset information. - print("Dataset name: {}".format(dataset.name)) - print("Dataset id: {}".format(dataset.name.split("/")[-1])) - print("Dataset display name: {}".format(dataset.display_name)) - print("Image classification dataset metadata:") - print("\t{}".format(dataset.image_classification_dataset_metadata)) - print("Dataset example count: {}".format(dataset.example_count)) - print("Dataset create time:") - print("\tseconds: {}".format(dataset.create_time.seconds)) - print("\tnanos: {}".format(dataset.create_time.nanos)) - - # [END automl_vision_list_datasets] - - -def get_dataset(project_id, compute_region, dataset_id): - """Get the dataset.""" - # [START automl_vision_get_dataset] - # TODO(developer): Uncomment and set the following variables - # project_id = 'PROJECT_ID_HERE' - # compute_region = 'COMPUTE_REGION_HERE' - # dataset_id = 'DATASET_ID_HERE' - - from google.cloud import automl_v1beta1 as automl - - client = automl.AutoMlClient() - - # Get the full path of the dataset. - dataset_full_id = client.dataset_path( - project_id, compute_region, dataset_id - ) - - # Get complete detail of the dataset. - dataset = client.get_dataset(dataset_full_id) - - # Display the dataset information. - print("Dataset name: {}".format(dataset.name)) - print("Dataset id: {}".format(dataset.name.split("/")[-1])) - print("Dataset display name: {}".format(dataset.display_name)) - print("Image classification dataset metadata:") - print("\t{}".format(dataset.image_classification_dataset_metadata)) - print("Dataset example count: {}".format(dataset.example_count)) - print("Dataset create time:") - print("\tseconds: {}".format(dataset.create_time.seconds)) - print("\tnanos: {}".format(dataset.create_time.nanos)) - - # [START automl_vision_get_dataset] - - -def import_data(project_id, compute_region, dataset_id, path): - """Import labeled images.""" - # [START automl_vision_import_data] - # TODO(developer): Uncomment and set the following variables - # project_id = 'PROJECT_ID_HERE' - # compute_region = 'COMPUTE_REGION_HERE' - # dataset_id = 'DATASET_ID_HERE' - # path = 'gs://path/to/file.csv' - - from google.cloud import automl_v1beta1 as automl - - client = automl.AutoMlClient() - - # Get the full path of the dataset. - dataset_full_id = client.dataset_path( - project_id, compute_region, dataset_id - ) - - # Get the multiple Google Cloud Storage URIs. - input_uris = path.split(",") - input_config = {"gcs_source": {"input_uris": input_uris}} - - # Import data from the input URI. - response = client.import_data(dataset_full_id, input_config) - - print("Processing import...") - # synchronous check of operation status. - print("Data imported. {}".format(response.result())) - - # [END automl_vision_import_data] - - -def export_data(project_id, compute_region, dataset_id, gcs_uri): - """Export a dataset to a Google Cloud Storage bucket.""" - # [START automl_vision_export_data] - # TODO(developer): Uncomment and set the following variables - # project_id = 'PROJECT_ID_HERE' - # compute_region = 'COMPUTE_REGION_HERE' - # dataset_id = 'DATASET_ID_HERE' - # output_uri: 'gs://location/to/export/data' - - from google.cloud import automl_v1beta1 as automl - - client = automl.AutoMlClient() - - # Get the full path of the dataset. - dataset_full_id = client.dataset_path( - project_id, compute_region, dataset_id - ) - - # Set the output URI - output_config = {"gcs_destination": {"output_uri_prefix": gcs_uri}} - - # Export the dataset to the output URI. - response = client.export_data(dataset_full_id, output_config) - - print("Processing export...") - # synchronous check of operation status. - print("Data exported. {}".format(response.result())) - - # [END automl_vision_export_data] - - -def delete_dataset(project_id, compute_region, dataset_id): - """Delete a dataset""" - # [START automl_vision_delete_dataset] - # TODO(developer): Uncomment and set the following variables - # project_id = 'PROJECT_ID_HERE' - # compute_region = 'COMPUTE_REGION_HERE' - # dataset_id = 'DATASET_ID_HERE' - - from google.cloud import automl_v1beta1 as automl - - client = automl.AutoMlClient() - - # Get the full path of the dataset. - dataset_full_id = client.dataset_path( - project_id, compute_region, dataset_id - ) - - # Delete a dataset. - response = client.delete_dataset(dataset_full_id) - - # synchronous check of operation status. - print("Dataset deleted. {}".format(response.result())) - # [END automl_vision_delete_dataset] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter, - ) - subparsers = parser.add_subparsers(dest="command") - - create_dataset_parser = subparsers.add_parser( - "create_dataset", help=create_dataset.__doc__ - ) - create_dataset_parser.add_argument("dataset_name") - create_dataset_parser.add_argument( - "multilabel", nargs="?", choices=["False", "True"], default="False" - ) - - list_datasets_parser = subparsers.add_parser( - "list_datasets", help=list_datasets.__doc__ - ) - list_datasets_parser.add_argument("filter_") - - get_dataset_parser = subparsers.add_parser( - "get_dataset", help=get_dataset.__doc__ - ) - get_dataset_parser.add_argument("dataset_id") - - import_data_parser = subparsers.add_parser( - "import_data", help=import_data.__doc__ - ) - import_data_parser.add_argument("dataset_id") - import_data_parser.add_argument("path") - - export_data_parser = subparsers.add_parser( - "export_data", help=export_data.__doc__ - ) - export_data_parser.add_argument("dataset_id") - export_data_parser.add_argument("gcs_uri") - - delete_dataset_parser = subparsers.add_parser( - "delete_dataset", help=delete_dataset.__doc__ - ) - delete_dataset_parser.add_argument("dataset_id") - - project_id = os.environ["PROJECT_ID"] - compute_region = os.environ["REGION_NAME"] - - args = parser.parse_args() - - if args.command == "create_dataset": - multilabel = True if args.multilabel == "True" else False - create_dataset( - project_id, compute_region, args.dataset_name, multilabel - ) - if args.command == "list_datasets": - list_datasets(project_id, compute_region, args.filter_) - if args.command == "get_dataset": - get_dataset(project_id, compute_region, args.dataset_id) - if args.command == "import_data": - import_data(project_id, compute_region, args.dataset_id, args.path) - if args.command == "export_data": - export_data(project_id, compute_region, args.dataset_id, args.gcs_uri) - if args.command == "delete_dataset": - delete_dataset(project_id, compute_region, args.dataset_id) diff --git a/vision/automl/automl_vision_model.py b/vision/automl/automl_vision_model.py index 0c1f621d8b3..04aa4c9476e 100755 --- a/vision/automl/automl_vision_model.py +++ b/vision/automl/automl_vision_model.py @@ -62,298 +62,6 @@ def create_model( # [END automl_vision_create_model] -def get_operation_status(operation_full_id): - """Get operation status.""" - # [START automl_vision_get_operation_status] - # TODO(developer): Uncomment and set the following variables - # operation_full_id = - # 'projects//locations//operations/' - - from google.cloud import automl_v1beta1 as automl - - client = automl.AutoMlClient() - - # Get the latest state of a long-running operation. - response = client.transport._operations_client.get_operation( - operation_full_id - ) - - print("Operation status: {}".format(response)) - - # [END automl_vision_get_operation_status] - - -def list_models(project_id, compute_region, filter_): - """List all models.""" - # [START automl_vision_list_models] - # TODO(developer): Uncomment and set the following variables - # project_id = 'PROJECT_ID_HERE' - # compute_region = 'COMPUTE_REGION_HERE' - # filter_ = 'DATASET_ID_HERE' - - from google.cloud import automl_v1beta1 as automl - from google.cloud.automl_v1beta1 import enums - - client = automl.AutoMlClient() - - # A resource that represents Google Cloud Platform location. - project_location = client.location_path(project_id, compute_region) - - # List all the models available in the region by applying filter. - response = client.list_models(project_location, filter_) - - print("List of models:") - for model in response: - # Retrieve deployment state. - if model.deployment_state == enums.Model.DeploymentState.DEPLOYED: - deployment_state = "deployed" - else: - deployment_state = "undeployed" - - # Display the model information. - print("Model name: {}".format(model.name)) - print("Model id: {}".format(model.name.split("/")[-1])) - print("Model display name: {}".format(model.display_name)) - print("Image classification model metadata:") - print( - "Training budget: {}".format( - model.image_classification_model_metadata.train_budget - ) - ) - print( - "Training cost: {}".format( - model.image_classification_model_metadata.train_cost - ) - ) - print( - "Stop reason: {}".format( - model.image_classification_model_metadata.stop_reason - ) - ) - print( - "Base model id: {}".format( - model.image_classification_model_metadata.base_model_id - ) - ) - print("Model create time:") - print("\tseconds: {}".format(model.create_time.seconds)) - print("\tnanos: {}".format(model.create_time.nanos)) - print("Model deployment state: {}".format(deployment_state)) - - # [END automl_vision_list_models] - - -def get_model(project_id, compute_region, model_id): - """Get model details.""" - # [START automl_vision_get_model] - # TODO(developer): Uncomment and set the following variables - # project_id = 'PROJECT_ID_HERE' - # compute_region = 'COMPUTE_REGION_HERE' - # model_id = 'MODEL_ID_HERE' - - from google.cloud import automl_v1beta1 as automl - from google.cloud.automl_v1beta1 import enums - - client = automl.AutoMlClient() - - # Get the full path of the model. - model_full_id = client.model_path(project_id, compute_region, model_id) - - # Get complete detail of the model. - model = client.get_model(model_full_id) - - # Retrieve deployment state. - if model.deployment_state == enums.Model.DeploymentState.DEPLOYED: - deployment_state = "deployed" - else: - deployment_state = "undeployed" - - # Display the model information. - print("Model name: {}".format(model.name)) - print("Model id: {}".format(model.name.split("/")[-1])) - print("Model display name: {}".format(model.display_name)) - print("Image classification model metadata:") - print( - "Training budget: {}".format( - model.image_classification_model_metadata.train_budget - ) - ) - print( - "Training cost: {}".format( - model.image_classification_model_metadata.train_cost - ) - ) - print( - "Stop reason: {}".format( - model.image_classification_model_metadata.stop_reason - ) - ) - print( - "Base model id: {}".format( - model.image_classification_model_metadata.base_model_id - ) - ) - print("Model create time:") - print("\tseconds: {}".format(model.create_time.seconds)) - print("\tnanos: {}".format(model.create_time.nanos)) - print("Model deployment state: {}".format(deployment_state)) - - # [END automl_vision_get_model] - - -def list_model_evaluations(project_id, compute_region, model_id, filter_): - """List model evaluations.""" - # [START automl_vision_list_model_evaluations] - # TODO(developer): Uncomment and set the following variables - # project_id = 'PROJECT_ID_HERE' - # compute_region = 'COMPUTE_REGION_HERE' - # model_id = 'MODEL_ID_HERE' - # filter_ = 'filter expression here' - - from google.cloud import automl_v1beta1 as automl - - client = automl.AutoMlClient() - - # Get the full path of the model. - model_full_id = client.model_path(project_id, compute_region, model_id) - - # List all the model evaluations in the model by applying filter. - response = client.list_model_evaluations(model_full_id, filter_) - - print("List of model evaluations:") - for element in response: - print(element) - - # [END automl_vision_list_model_evaluations] - - -def get_model_evaluation( - project_id, compute_region, model_id, model_evaluation_id -): - """Get model evaluation.""" - # [START automl_vision_get_model_evaluation] - # TODO(developer): Uncomment and set the following variables - # project_id = 'PROJECT_ID_HERE' - # compute_region = 'COMPUTE_REGION_HERE' - # model_id = 'MODEL_ID_HERE' - # model_evaluation_id = 'MODEL_EVALUATION_ID_HERE' - - from google.cloud import automl_v1beta1 as automl - - client = automl.AutoMlClient() - - # Get the full path of the model evaluation. - model_evaluation_full_id = client.model_evaluation_path( - project_id, compute_region, model_id, model_evaluation_id - ) - - # Get complete detail of the model evaluation. - response = client.get_model_evaluation(model_evaluation_full_id) - - print(response) - - # [END automl_vision_get_model_evaluation] - - -def display_evaluation(project_id, compute_region, model_id, filter_): - """Display evaluation.""" - # [START automl_vision_display_evaluation] - # TODO(developer): Uncomment and set the following variables - # project_id = 'PROJECT_ID_HERE' - # compute_region = 'COMPUTE_REGION_HERE' - # model_id = 'MODEL_ID_HERE' - # filter_ = 'filter expression here' - - from google.cloud import automl_v1beta1 as automl - - client = automl.AutoMlClient() - - # Get the full path of the model. - model_full_id = client.model_path(project_id, compute_region, model_id) - - # List all the model evaluations in the model by applying filter. - response = client.list_model_evaluations(model_full_id, filter_) - - # Iterate through the results. - for element in response: - # There is evaluation for each class in a model and for overall model. - # Get only the evaluation of overall model. - if not element.annotation_spec_id: - model_evaluation_id = element.name.split("/")[-1] - - # Resource name for the model evaluation. - model_evaluation_full_id = client.model_evaluation_path( - project_id, compute_region, model_id, model_evaluation_id - ) - - # Get a model evaluation. - model_evaluation = client.get_model_evaluation(model_evaluation_full_id) - - class_metrics = model_evaluation.classification_evaluation_metrics - confidence_metrics_entries = class_metrics.confidence_metrics_entry - - # Showing model score based on threshold of 0.5 - for confidence_metrics_entry in confidence_metrics_entries: - if confidence_metrics_entry.confidence_threshold == 0.5: - print("Precision and recall are based on a score threshold of 0.5") - print( - "Model Precision: {}%".format( - round(confidence_metrics_entry.precision * 100, 2) - ) - ) - print( - "Model Recall: {}%".format( - round(confidence_metrics_entry.recall * 100, 2) - ) - ) - print( - "Model F1 score: {}%".format( - round(confidence_metrics_entry.f1_score * 100, 2) - ) - ) - print( - "Model Precision@1: {}%".format( - round(confidence_metrics_entry.precision_at1 * 100, 2) - ) - ) - print( - "Model Recall@1: {}%".format( - round(confidence_metrics_entry.recall_at1 * 100, 2) - ) - ) - print( - "Model F1 score@1: {}%".format( - round(confidence_metrics_entry.f1_score_at1 * 100, 2) - ) - ) - - # [END automl_vision_display_evaluation] - - -def delete_model(project_id, compute_region, model_id): - """Delete a model.""" - # [START automl_vision_delete_model] - # TODO(developer): Uncomment and set the following variables - # project_id = 'PROJECT_ID_HERE' - # compute_region = 'COMPUTE_REGION_HERE' - # model_id = 'MODEL_ID_HERE' - - from google.cloud import automl_v1beta1 as automl - - client = automl.AutoMlClient() - - # Get the full path of the model. - model_full_id = client.model_path(project_id, compute_region, model_id) - - # Delete a model. - response = client.delete_model(model_full_id) - - # synchronous check of operation status. - print("Model deleted. {}".format(response.result())) - - # [END automl_vision_delete_model] - - if __name__ == "__main__": parser = argparse.ArgumentParser( description=__doc__, @@ -370,46 +78,6 @@ def delete_model(project_id, compute_region, model_id): "train_budget", type=int, nargs="?", default=0 ) - get_operation_status_parser = subparsers.add_parser( - "get_operation_status", help=get_operation_status.__doc__ - ) - get_operation_status_parser.add_argument("operation_full_id") - - list_models_parser = subparsers.add_parser( - "list_models", help=list_models.__doc__ - ) - list_models_parser.add_argument("filter_") - - get_model_parser = subparsers.add_parser( - "get_model", help=get_model.__doc__ - ) - get_model_parser.add_argument("model_id") - - list_model_evaluations_parser = subparsers.add_parser( - "list_model_evaluations", help=list_model_evaluations.__doc__ - ) - list_model_evaluations_parser.add_argument("model_id") - list_model_evaluations_parser.add_argument( - "filter_", nargs="?", default="" - ) - - get_model_evaluation_parser = subparsers.add_parser( - "get_model_evaluation", help=get_model_evaluation.__doc__ - ) - get_model_evaluation_parser.add_argument("model_id") - get_model_evaluation_parser.add_argument("model_evaluation_id") - - display_evaluation_parser = subparsers.add_parser( - "display_evaluation", help=display_evaluation.__doc__ - ) - display_evaluation_parser.add_argument("model_id") - display_evaluation_parser.add_argument("filter_", nargs="?", default="") - - delete_model_parser = subparsers.add_parser( - "delete_model", help=delete_model.__doc__ - ) - delete_model_parser.add_argument("model_id") - project_id = os.environ["PROJECT_ID"] compute_region = os.environ["REGION_NAME"] @@ -423,23 +91,3 @@ def delete_model(project_id, compute_region, model_id): args.model_name, args.train_budget, ) - if args.command == "get_operation_status": - get_operation_status(args.operation_full_id) - if args.command == "list_models": - list_models(project_id, compute_region, args.filter_) - if args.command == "get_model": - get_model(project_id, compute_region, args.model_id) - if args.command == "list_model_evaluations": - list_model_evaluations( - project_id, compute_region, args.model_id, args.filter_ - ) - if args.command == "get_model_evaluation": - get_model_evaluation( - project_id, compute_region, args.model_id, args.model_evaluation_id - ) - if args.command == "display_evaluation": - display_evaluation( - project_id, compute_region, args.model_id, args.filter_ - ) - if args.command == "delete_model": - delete_model(project_id, compute_region, args.model_id) diff --git a/vision/automl/automl_vision_predict.py b/vision/automl/automl_vision_predict.py deleted file mode 100755 index 0478c5c2feb..00000000000 --- a/vision/automl/automl_vision_predict.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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. - -"""This application demonstrates how to perform basic operations on prediction -with the Google AutoML Vision API. - -For more information, the documentation at -https://cloud.google.com/vision/automl/docs. -""" - -import argparse -import os - - -def predict( - project_id, compute_region, model_id, file_path, score_threshold="" -): - """Make a prediction for an image.""" - # [START automl_vision_predict] - # TODO(developer): Uncomment and set the following variables - # project_id = 'PROJECT_ID_HERE' - # compute_region = 'COMPUTE_REGION_HERE' - # model_id = 'MODEL_ID_HERE' - # file_path = '/local/path/to/file' - # score_threshold = 'value from 0.0 to 0.5' - - from google.cloud import automl_v1beta1 as automl - - automl_client = automl.AutoMlClient() - - # Get the full path of the model. - model_full_id = automl_client.model_path( - project_id, compute_region, model_id - ) - - # Create client for prediction service. - prediction_client = automl.PredictionServiceClient() - - # Read the image and assign to payload. - with open(file_path, "rb") as image_file: - content = image_file.read() - payload = {"image": {"image_bytes": content}} - - # params is additional domain-specific parameters. - # score_threshold is used to filter the result - # Initialize params - params = {} - if score_threshold: - params = {"score_threshold": score_threshold} - - response = prediction_client.predict(model_full_id, payload, params) - print("Prediction results:") - for result in response.payload: - print("Predicted class name: {}".format(result.display_name)) - print("Predicted class score: {}".format(result.classification.score)) - - # [END automl_vision_predict] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter, - ) - subparsers = parser.add_subparsers(dest="command") - - predict_parser = subparsers.add_parser("predict", help=predict.__doc__) - predict_parser.add_argument("model_id") - predict_parser.add_argument("file_path") - predict_parser.add_argument("score_threshold", nargs="?", default="") - - project_id = os.environ["PROJECT_ID"] - compute_region = os.environ["REGION_NAME"] - - args = parser.parse_args() - - if args.command == "predict": - predict( - project_id, - compute_region, - args.model_id, - args.file_path, - args.score_threshold, - ) diff --git a/vision/automl/dataset_test.py b/vision/automl/dataset_test.py deleted file mode 100644 index 1da0433b53a..00000000000 --- a/vision/automl/dataset_test.py +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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. - -import datetime -import os - -import pytest - -import automl_vision_dataset - -project_id = os.environ["GCLOUD_PROJECT"] -compute_region = "us-central1" - - -@pytest.mark.slow -def test_dataset_create_import_delete(capsys): - # create dataset - dataset_name = "test_" + datetime.datetime.now().strftime("%Y%m%d%H%M%S") - automl_vision_dataset.create_dataset( - project_id, compute_region, dataset_name - ) - out, _ = capsys.readouterr() - create_dataset_output = out.splitlines() - assert "Dataset id: " in create_dataset_output[1] - - # import data - dataset_id = create_dataset_output[1].split()[2] - data = "gs://{}-vcm/flower_traindata.csv".format(project_id) - automl_vision_dataset.import_data( - project_id, compute_region, dataset_id, data - ) - out, _ = capsys.readouterr() - assert "Data imported." in out - - # delete dataset - automl_vision_dataset.delete_dataset( - project_id, compute_region, dataset_id - ) - out, _ = capsys.readouterr() - assert "Dataset deleted." in out - - -def test_dataset_list_get(capsys): - # list datasets - automl_vision_dataset.list_datasets(project_id, compute_region, "") - out, _ = capsys.readouterr() - list_dataset_output = out.splitlines() - assert "Dataset id: " in list_dataset_output[2] - - # get dataset - dataset_id = list_dataset_output[2].split()[2] - automl_vision_dataset.get_dataset(project_id, compute_region, dataset_id) - out, _ = capsys.readouterr() - assert "Dataset name: " in out diff --git a/vision/automl/model_test.py b/vision/automl/model_test.py index 9792c341682..a272ce92334 100644 --- a/vision/automl/model_test.py +++ b/vision/automl/model_test.py @@ -20,8 +20,6 @@ from google.cloud import automl_v1beta1 as automl import pytest -import automl_vision_model - project_id = os.environ["GCLOUD_PROJECT"] compute_region = "us-central1" @@ -41,40 +39,5 @@ def test_model_create_status_delete(capsys): operation_name = response.operation.name assert operation_name - # get operation status - automl_vision_model.get_operation_status(operation_name) - out, _ = capsys.readouterr() - assert "Operation status: " in out - # cancel operation response.cancel() - - -def test_model_list_get_evaluate(capsys): - # list models - automl_vision_model.list_models(project_id, compute_region, "") - out, _ = capsys.readouterr() - list_models_output = out.splitlines() - assert "Model id: " in list_models_output[2] - - # get model - model_id = list_models_output[2].split()[2] - automl_vision_model.get_model(project_id, compute_region, model_id) - out, _ = capsys.readouterr() - assert "Model name: " in out - - # list model evaluations - automl_vision_model.list_model_evaluations( - project_id, compute_region, model_id, "" - ) - out, _ = capsys.readouterr() - list_evals_output = out.splitlines() - assert "name: " in list_evals_output[1] - - # get model evaluation - model_evaluation_id = list_evals_output[1].split("/")[-1][:-1] - automl_vision_model.get_model_evaluation( - project_id, compute_region, model_id, model_evaluation_id - ) - out, _ = capsys.readouterr() - assert "evaluation_metric" in out diff --git a/vision/automl/predict_test.py b/vision/automl/predict_test.py deleted file mode 100644 index a0e3eba833b..00000000000 --- a/vision/automl/predict_test.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2018 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. - -import os - -import automl_vision_predict - -project_id = os.environ["GCLOUD_PROJECT"] -compute_region = "us-central1" - - -def test_predict(capsys): - model_id = "ICN7383667271543079510" - automl_vision_predict.predict( - project_id, compute_region, model_id, "resources/test.png" - ) - out, _ = capsys.readouterr() - assert "maize" in out