|
| 1 | +# Copyright 2020 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 create_dataset(project_id, display_name): |
| 17 | + """Create a dataset.""" |
| 18 | + # [START automl_vision_classification_create_dataset] |
| 19 | + from google.cloud import automl |
| 20 | + |
| 21 | + # TODO(developer): Uncomment and set the following variables |
| 22 | + # project_id = "YOUR_PROJECT_ID" |
| 23 | + # display_name = "your_datasets_display_name" |
| 24 | + |
| 25 | + client = automl.AutoMlClient() |
| 26 | + |
| 27 | + # A resource that represents Google Cloud Platform location. |
| 28 | + project_location = client.location_path(project_id, "us-central1") |
| 29 | + # Specify the classification type |
| 30 | + # Types: |
| 31 | + # MultiLabel: Multiple labels are allowed for one example. |
| 32 | + # MultiClass: At most one label is allowed per example. |
| 33 | + metadata = automl.types.ImageClassificationDatasetMetadata( |
| 34 | + classification_type=automl.enums.ClassificationType.MULTILABEL |
| 35 | + ) |
| 36 | + dataset = automl.types.Dataset( |
| 37 | + display_name=display_name, |
| 38 | + image_classification_dataset_metadata=metadata, |
| 39 | + ) |
| 40 | + |
| 41 | + # Create a dataset with the dataset metadata in the region. |
| 42 | + response = client.create_dataset(project_location, dataset) |
| 43 | + |
| 44 | + created_dataset = response.result() |
| 45 | + |
| 46 | + # Display the dataset information |
| 47 | + print("Dataset name: {}".format(created_dataset.name)) |
| 48 | + print("Dataset id: {}".format(created_dataset.name.split("/")[-1])) |
| 49 | + # [END automl_vision_classification_create_dataset] |
0 commit comments