def create_model(project_id, dataset_id, display_name):
    """Create a model."""
    # [START automl_vision_classification_create_model]
    from google.cloud import automl

    # TODO(developer): Uncomment and set the following variables
    # project_id = "YOUR_PROJECT_ID"
    # dataset_id = "YOUR_DATASET_ID"
    # display_name = "your_models_display_name"

    client = automl.AutoMlClient()

    # A resource that represents Google Cloud Platform location.
    project_location = f"projects/{project_id}/locations/us-central1"
    # Leave model unset to use the default base model provided by Google
    # train_budget_milli_node_hours: The actual train_cost will be equal or
    # less than this value.
    # https://cloud.google.com/automl/docs/reference/rpc/google.cloud.automl.v1#imageclassificationmodelmetadata
    metadata = automl.ImageClassificationModelMetadata(
        train_budget_milli_node_hours=24000)
    model = automl.Model(
        display_name=display_name,
        dataset_id=dataset_id,
        image_classification_model_metadata=metadata,
    )

    # Create a model with the model metadata in the region.
    response = client.create_model(parent=project_location, model=model)

    print("Training operation name: {}".format(response.operation.name))
    print("Training started...")
    # [END automl_vision_classification_create_model]
    return response
Esempio n. 2
0
    def train_image_classification_model(
            self,
            display_name: (str, 'the display name for the dataset and model'),
            input_paths:
        (str,
         'the paths to csv files describing the input data for a new dataset'
         ) = '',
            dataset_id: (str, 'the id of an existing dataset to reuse') = '',
            classification_type: (automl.ClassificationType,
                                  'MULTICLASS or MULTILABEL'
                                  ) = automl.ClassificationType.MULTICLASS,
            train_budget_milli_node_hours: int = 24000) -> Operation:

        dataset = None
        if len(dataset_id) == 0:
            # Specify the classification type
            # Types:
            # MultiLabel: Multiple labels are allowed for one example.
            # MultiClass: At most one label is allowed per example.
            # https://cloud.google.com/automl/docs/reference/rpc/google.cloud.automl.v1#classificationtype
            metadata = automl.ImageClassificationDatasetMetadata(
                classification_type=classification_type)
            dataset = automl.Dataset(
                display_name=display_name,
                image_classification_dataset_metadata=metadata,
            )

        # Leave model unset to use the default base model provided by Google
        # train_budget_milli_node_hours: The actual train_cost will be equal or
        # less than this value.
        # https://cloud.google.com/automl/docs/reference/rpc/google.cloud.automl.v1#imageclassificationmodelmetadata
        metadata = automl.ImageClassificationModelMetadata(
            train_budget_milli_node_hours=train_budget_milli_node_hours)
        model = automl.Model(
            display_name=display_name,
            dataset_id=dataset_id,
            image_classification_model_metadata=metadata,
        )

        long_running_operation = self.train_automl_model(
            model=model,
            dataset=dataset,
            dataset_id=dataset_id,
            input_paths=input_paths)

        return long_running_operation
Esempio n. 3
0
    # Import data from the input URI
    response = client.import_data(name=dataset_full_id, input_config=input_config)

    print("Processing import...")
    print("Data imported. {}".format(response.result()))

    start_training_time = time.time()
    
    project_location = f"projects/{project_id}/locations/us-central1"
    # Leave model unset to use the default base model provided by Google
    # train_budget_milli_node_hours: The actual train_cost will be equal or
    # less than this value.
    # https://cloud.google.com/automl/docs/reference/rpc/google.cloud.automl.v1#imageclassificationmodelmetadata
    metadata = automl.ImageClassificationModelMetadata(
        train_budget_milli_node_hours=8000
    )
    model = automl.Model(
        display_name=display_name,
        dataset_id=dataset_id,
        image_classification_model_metadata=metadata,
    )

    # Create a model with the model metadata in the region.
    response = client.create_model(parent=project_location, model=model)

    print("Training operation name: {}".format(response.operation.name))
    print("Training started...")

    model_id = response.result().name.split('/')[-1]