Ejemplo n.º 1
0
def batch_predict(project_id, model_id, input_uri, output_uri):
    """Batch predict"""
    # [START automl_batch_predict]
    from google.cloud import automl

    # TODO(developer): Uncomment and set the following variables
    # project_id = "YOUR_PROJECT_ID"
    # model_id = "YOUR_MODEL_ID"
    # input_uri = "gs://YOUR_BUCKET_ID/path/to/your/input/csv_or_jsonl"
    # output_uri = "gs://YOUR_BUCKET_ID/path/to/save/results/"

    prediction_client = automl.PredictionServiceClient()

    # Get the full path of the model.
    model_full_id = f"projects/{project_id}/locations/us-central1/models/{model_id}"

    gcs_source = automl.GcsSource(input_uris=[input_uri])

    input_config = automl.BatchPredictInputConfig(gcs_source=gcs_source)
    gcs_destination = automl.GcsDestination(output_uri_prefix=output_uri)
    output_config = automl.BatchPredictOutputConfig(
        gcs_destination=gcs_destination)

    response = prediction_client.batch_predict(name=model_full_id,
                                               input_config=input_config,
                                               output_config=output_config)

    print("Waiting for operation to complete...")
    print(
        f"Batch Prediction results saved to Cloud Storage bucket. {response.result()}"
    )
Ejemplo n.º 2
0
def import_dataset(project_id, dataset_id, path):
    """Import a dataset."""
    # [START automl_import_data]
    from google.cloud import automl

    # TODO(developer): Uncomment and set the following variables
    # project_id = "YOUR_PROJECT_ID"
    # dataset_id = "YOUR_DATASET_ID"
    # path = "gs://YOUR_BUCKET_ID/path/to/data.csv"

    client = automl.AutoMlClient()
    # Get the full path of the dataset.
    dataset_full_id = client.dataset_path(project_id, "us-central1",
                                          dataset_id)
    # Get the multiple Google Cloud Storage URIs
    input_uris = path.split(",")
    gcs_source = automl.GcsSource(input_uris=input_uris)
    input_config = automl.InputConfig(gcs_source=gcs_source)
    # 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()))
Ejemplo n.º 3
0
    pos_train_images_gc = add_images_to_gc(data['pos_train_images'])
    neg_train_images_gc = add_images_to_gc(data['neg_train_images'])

    labels_csv = ''
    labels_csv += '\n'.join(['%s,positive'%item for item in pos_train_images_gc])
    labels_csv += '\n'.join(['%s,negative'%item for item in neg_train_images_gc])

    blob = bucket.blob(f'csv/{display_name}.csv')
    blob.upload_from_string(labels_csv)

    csv_path = blob.public_url.replace('https://storage.googleapis.com/', 'gs://')

    dataset_id = created_dataset.name.split("/")[-1]
    dataset_full_id = client.dataset_path(project_id, "us-central1", dataset_id)

    gcs_source = automl.GcsSource(input_uris=[csv_path])
    input_config = automl.InputConfig(gcs_source=gcs_source)

    # 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
Ejemplo n.º 4
0
from google.cloud import automl

# TODO: fix vars as needed
project_id = "covid_mask_identifier"
dataset_id = "covid_id_dataset"
path = "gs://YOUR_BUCKET_ID/path/to/data.csv"

client = automl.AutoMlClient()
# Get the full path of the dataset.
dataset_full_id = client.dataset_path(
    project_id, "us-central1", dataset_id
)
# Get the multiple Google Cloud Storage URIs
input_uris = path.split(",")
gcs_source = automl.GcsSource(input_uris=input_uris)
input_config = automl.InputConfig(gcs_source=gcs_source)
# 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()))