airflow.providers.google.cloud.hooks.automl
¶
This module contains a Google AutoML hook.
Module Contents¶
-
class
airflow.providers.google.cloud.hooks.automl.
CloudAutoMLHook
(gcp_conn_id: str = 'google_cloud_default', delegate_to: Optional[str] = None, impersonation_chain: Optional[Union[str, Sequence[str]]] = None)[source]¶ Bases:
airflow.providers.google.common.hooks.base_google.GoogleBaseHook
Google Cloud AutoML hook.
All the methods in the hook where project_id is used must be called with keyword arguments rather than positional.
-
get_conn
(self)[source]¶ Retrieves connection to AutoML.
- Returns
Google Cloud AutoML client object.
- Return type
google.cloud.automl_v1beta1.AutoMlClient
-
prediction_client
(self)[source]¶ Creates PredictionServiceClient.
- Returns
Google Cloud AutoML PredictionServiceClient client object.
- Return type
google.cloud.automl_v1beta1.PredictionServiceClient
-
create_model
(self, model: Union[dict, Model], location: str, project_id: str, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None, retry: Optional[Retry] = None)[source]¶ Creates a model_id. Returns a Model in the response field when it completes. When you create a model, several model evaluations are created for it: a global evaluation, and one evaluation for each annotation spec.
- Parameters
model (Union[dict, google.cloud.automl_v1beta1.types.Model]) – The model_id to create. If a dict is provided, it must be of the same form as the protobuf message google.cloud.automl_v1beta1.types.Model
project_id (str) – ID of the Google Cloud project where model will be created if None then default project_id is used.
location (str) – The location of the project.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
google.cloud.automl_v1beta1.types._OperationFuture instance
-
batch_predict
(self, model_id: str, input_config: Union[dict, BatchPredictInputConfig], output_config: Union[dict, BatchPredictOutputConfig], location: str, project_id: str, params: Optional[Dict[str, str]] = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]¶ Perform a batch prediction. Unlike the online Predict, batch prediction result won’t be immediately available in the response. Instead, a long running operation object is returned.
- Parameters
model_id (str) – Name of the model_id requested to serve the batch prediction.
input_config (Union[dict, google.cloud.automl_v1beta1.types.BatchPredictInputConfig]) – Required. The input configuration for batch prediction. If a dict is provided, it must be of the same form as the protobuf message google.cloud.automl_v1beta1.types.BatchPredictInputConfig
output_config (Union[dict, google.cloud.automl_v1beta1.types.BatchPredictOutputConfig]) – Required. The Configuration specifying where output predictions should be written. If a dict is provided, it must be of the same form as the protobuf message google.cloud.automl_v1beta1.types.BatchPredictOutputConfig
params (Optional[Dict[str, str]]) – Additional domain-specific parameters for the predictions, any string must be up to 25000 characters long.
project_id (str) – ID of the Google Cloud project where model is located if None then default project_id is used.
location (str) – The location of the project.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
google.cloud.automl_v1beta1.types._OperationFuture instance
-
predict
(self, model_id: str, payload: Union[dict, ExamplePayload], location: str, project_id: str, params: Optional[Dict[str, str]] = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]¶ Perform an online prediction. The prediction result will be directly returned in the response.
- Parameters
model_id (str) – Name of the model_id requested to serve the prediction.
payload (Union[dict, google.cloud.automl_v1beta1.types.ExamplePayload]) – Required. Payload to perform a prediction on. The payload must match the problem type that the model_id was trained to solve. If a dict is provided, it must be of the same form as the protobuf message google.cloud.automl_v1beta1.types.ExamplePayload
params (Optional[Dict[str, str]]) – Additional domain-specific parameters, any string must be up to 25000 characters long.
project_id (str) – ID of the Google Cloud project where model is located if None then default project_id is used.
location (str) – The location of the project.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
google.cloud.automl_v1beta1.types.PredictResponse instance
-
create_dataset
(self, dataset: Union[dict, Dataset], location: str, project_id: str, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]¶ Creates a dataset.
- Parameters
dataset (Union[dict, Dataset]) – The dataset to create. If a dict is provided, it must be of the same form as the protobuf message Dataset.
project_id (str) – ID of the Google Cloud project where dataset is located if None then default project_id is used.
location (str) – The location of the project.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
google.cloud.automl_v1beta1.types.Dataset instance.
-
import_data
(self, dataset_id: str, location: str, input_config: Union[dict, InputConfig], project_id: str, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]¶ Imports data into a dataset. For Tables this method can only be called on an empty Dataset.
- Parameters
dataset_id (str) – Name of the AutoML dataset.
input_config (Union[dict, InputConfig]) – The desired input location and its domain specific semantics, if any. If a dict is provided, it must be of the same form as the protobuf message InputConfig.
project_id (str) – ID of the Google Cloud project where dataset is located if None then default project_id is used.
location (str) – The location of the project.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
google.cloud.automl_v1beta1.types._OperationFuture instance
-
list_column_specs
(self, dataset_id: str, table_spec_id: str, location: str, project_id: str, field_mask: Union[dict, FieldMask] = None, filter_: Optional[str] = None, page_size: Optional[int] = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]¶ Lists column specs in a table spec.
- Parameters
dataset_id (str) – Name of the AutoML dataset.
table_spec_id (str) – table_spec_id for path builder.
field_mask (Union[dict, google.cloud.automl_v1beta1.types.FieldMask]) – Mask specifying which fields to read. If a dict is provided, it must be of the same form as the protobuf message google.cloud.automl_v1beta1.types.FieldMask
filter (str) – Filter expression, see go/filtering.
page_size (int) – The maximum number of resources contained in the underlying API response. If page streaming is performed per resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.
project_id (str) – ID of the Google Cloud project where dataset is located if None then default project_id is used.
location (str) – The location of the project.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
google.cloud.automl_v1beta1.types.ColumnSpec instance.
-
get_model
(self, model_id: str, location: str, project_id: str, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]¶ Gets a AutoML model.
- Parameters
model_id (str) – Name of the model.
project_id (str) – ID of the Google Cloud project where model is located if None then default project_id is used.
location (str) – The location of the project.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
google.cloud.automl_v1beta1.types.Model instance.
-
delete_model
(self, model_id: str, location: str, project_id: str, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]¶ Deletes a AutoML model.
- Parameters
model_id (str) – Name of the model.
project_id (str) – ID of the Google Cloud project where model is located if None then default project_id is used.
location (str) – The location of the project.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
google.cloud.automl_v1beta1.types._OperationFuture instance.
-
update_dataset
(self, dataset: Union[dict, Dataset], update_mask: Union[dict, FieldMask] = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]¶ Updates a dataset.
- Parameters
dataset (Union[dict, Dataset]) – The dataset which replaces the resource on the server. If a dict is provided, it must be of the same form as the protobuf message Dataset.
update_mask (Union[dict, FieldMask]) – The update mask applies to the resource. If a dict is provided, it must be of the same form as the protobuf message FieldMask.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
google.cloud.automl_v1beta1.types.Dataset instance..
-
deploy_model
(self, model_id: str, location: str, project_id: str, image_detection_metadata: Union[ImageObjectDetectionModelDeploymentMetadata, dict] = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]¶ Deploys a model. If a model is already deployed, deploying it with the same parameters has no effect. Deploying with different parameters (as e.g. changing node_number) will reset the deployment state without pausing the model_id’s availability.
Only applicable for Text Classification, Image Object Detection and Tables; all other domains manage deployment automatically.
- Parameters
model_id (str) – Name of the model requested to serve the prediction.
image_detection_metadata (Union[ImageObjectDetectionModelDeploymentMetadata, dict]) – Model deployment metadata specific to Image Object Detection. If a dict is provided, it must be of the same form as the protobuf message ImageObjectDetectionModelDeploymentMetadata
project_id (str) – ID of the Google Cloud project where model will be created if None then default project_id is used.
location (str) – The location of the project.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
google.cloud.automl_v1beta1.types._OperationFuture instance.
-
list_table_specs
(self, dataset_id: str, location: str, project_id: Optional[str] = None, filter_: Optional[str] = None, page_size: Optional[int] = None, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]¶ Lists table specs in a dataset_id.
- Parameters
dataset_id (str) – Name of the dataset.
filter (str) – Filter expression, see go/filtering.
page_size (int) – The maximum number of resources contained in the underlying API response. If page streaming is performed per resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.
project_id (str) – ID of the Google Cloud project where dataset is located if None then default project_id is used.
location (str) – The location of the project.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A google.gax.PageIterator instance. By default, this is an iterable of google.cloud.automl_v1beta1.types.TableSpec instances. This object can also be configured to iterate over the pages of the response through the options parameter.
-
list_datasets
(self, location: str, project_id: str, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]¶ Lists datasets in a project.
- Parameters
project_id (str) – ID of the Google Cloud project where dataset is located if None then default project_id is used.
location (str) – The location of the project.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
A google.gax.PageIterator instance. By default, this is an iterable of google.cloud.automl_v1beta1.types.Dataset instances. This object can also be configured to iterate over the pages of the response through the options parameter.
-
delete_dataset
(self, dataset_id: str, location: str, project_id: str, retry: Optional[Retry] = None, timeout: Optional[float] = None, metadata: Optional[Sequence[Tuple[str, str]]] = None)[source]¶ Deletes a dataset and all of its contents.
- Parameters
dataset_id (str) – ID of dataset to be deleted.
project_id (str) – ID of the Google Cloud project where dataset is located if None then default project_id is used.
location (str) – The location of the project.
retry (Optional[google.api_core.retry.Retry]) – A retry object used to retry requests. If None is specified, requests will not be retried.
timeout (Optional[float]) – The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]) – Additional metadata that is provided to the method.
- Returns
google.cloud.automl_v1beta1.types._OperationFuture instance
-