Skip to content

Commit

Permalink
feat: add schema namespace (#140)
Browse files Browse the repository at this point in the history
* feat: add schema namespace
  • Loading branch information
dizcology committed Dec 21, 2020
1 parent 1a302d2 commit 1cbd4a5
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 15 deletions.
4 changes: 3 additions & 1 deletion google/cloud/aiplatform/__init__.py
Expand Up @@ -16,5 +16,7 @@
#

from google.cloud.aiplatform import gapic
from google.cloud.aiplatform import schema

__all__ = (gapic,)

__all__ = (gapic, schema)
25 changes: 25 additions & 0 deletions google/cloud/aiplatform/schema/__init__.py
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-

# Copyright 2020 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.


from google.cloud.aiplatform.v1beta1.schema import predict
from google.cloud.aiplatform.v1beta1.schema import trainingjob


__all__ = (
"predict",
"trainingjob",
)
25 changes: 25 additions & 0 deletions google/cloud/aiplatform/v1beta1/schema/__init__.py
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-

# Copyright 2020 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.


from google.cloud.aiplatform.v1beta1.schema import predict
from google.cloud.aiplatform.v1beta1.schema import trainingjob


__all__ = (
"predict",
"trainingjob",
)
26 changes: 26 additions & 0 deletions google/cloud/aiplatform/v1beta1/schema/predict/__init__.py
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-

# Copyright 2020 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.


from google.cloud.aiplatform.v1beta1.schema.predict import instance
from google.cloud.aiplatform.v1beta1.schema.predict import params
from google.cloud.aiplatform.v1beta1.schema.predict import prediction

__all__ = (
"instance",
"params",
"prediction",
)
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
#
from google.cloud.aiplatform.helpers import _decorators
import google.cloud.aiplatform.v1beta1.schema.predict.instance_v1beta1.types as pkg
from google.cloud.aiplatform.v1beta1.schema.predict.instance_v1beta1 import types as pkg

from google.cloud.aiplatform.v1beta1.schema.predict.instance_v1beta1.types.image_classification import (
ImageClassificationPredictionInstance,
Expand Down
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
#
from google.cloud.aiplatform.helpers import _decorators
import google.cloud.aiplatform.v1beta1.schema.predict.params_v1beta1.types as pkg
from google.cloud.aiplatform.v1beta1.schema.predict.params_v1beta1 import types as pkg

from google.cloud.aiplatform.v1beta1.schema.predict.params_v1beta1.types.image_classification import (
ImageClassificationPredictionParams,
Expand Down
Expand Up @@ -15,7 +15,9 @@
# limitations under the License.
#
from google.cloud.aiplatform.helpers import _decorators
import google.cloud.aiplatform.v1beta1.schema.predict.prediction_v1beta1.types as pkg
from google.cloud.aiplatform.v1beta1.schema.predict.prediction_v1beta1 import (
types as pkg,
)

from google.cloud.aiplatform.v1beta1.schema.predict.prediction_v1beta1.types.classification import (
ClassificationPredictionResult,
Expand Down
20 changes: 20 additions & 0 deletions google/cloud/aiplatform/v1beta1/schema/trainingjob/__init__.py
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-

# Copyright 2020 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.


from google.cloud.aiplatform.v1beta1.schema.trainingjob import definition

__all__ = ("definition",)
Expand Up @@ -15,7 +15,9 @@
# limitations under the License.
#
from google.cloud.aiplatform.helpers import _decorators
import google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types as pkg
from google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1 import (
types as pkg,
)

from google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.automl_forecasting import (
AutoMlForecasting,
Expand Down
Expand Up @@ -14,8 +14,7 @@

# [START aiplatform_create_training_pipeline_image_classification_sample]
from google.cloud import aiplatform
from google.cloud.aiplatform.v1beta1.schema.trainingjob import definition
ModelType = definition.AutoMlImageClassificationInputs().ModelType
from google.cloud.aiplatform.schema import trainingjob


def create_training_pipeline_image_classification_sample(
Expand All @@ -32,9 +31,9 @@ def create_training_pipeline_image_classification_sample(
# This client only needs to be created once, and can be reused for multiple requests.
client = aiplatform.gapic.PipelineServiceClient(client_options=client_options)

icn_training_inputs = definition.AutoMlImageClassificationInputs(
icn_training_inputs = trainingjob.definition.AutoMlImageClassificationInputs(
multi_label=True,
model_type=ModelType.CLOUD,
model_type=trainingjob.definition.AutoMlImageClassificationInputs.ModelType.CLOUD,
budget_milli_node_hours=8000,
disable_early_stopping=False
)
Expand Down
10 changes: 4 additions & 6 deletions samples/snippets/predict_image_classification_sample.py
Expand Up @@ -16,9 +16,7 @@
import base64

from google.cloud import aiplatform
from google.cloud.aiplatform.v1beta1.schema.predict import instance
from google.cloud.aiplatform.v1beta1.schema.predict import params
from google.cloud.aiplatform.v1beta1.schema.predict import prediction
from google.cloud.aiplatform.schema import predict


def predict_image_classification_sample(
Expand All @@ -39,13 +37,13 @@ def predict_image_classification_sample(
# The format of each instance should conform to the deployed model's prediction input schema.
encoded_content = base64.b64encode(file_content).decode("utf-8")

instance_obj = instance.ImageClassificationPredictionInstance(
instance_obj = predict.instance.ImageClassificationPredictionInstance(
content=encoded_content)

instance_val = instance_obj.to_value()
instances = [instance_val]

params_obj = params.ImageClassificationPredictionParams(
params_obj = predict.params.ImageClassificationPredictionParams(
confidence_threshold=0.5, max_predictions=5)

endpoint = client.endpoint_path(
Expand All @@ -59,7 +57,7 @@ def predict_image_classification_sample(
# See gs://google-cloud-aiplatform/schema/predict/prediction/classification.yaml for the format of the predictions.
predictions = response.predictions
for prediction_ in predictions:
prediction_obj = prediction.ClassificationPredictionResult.from_map(prediction_)
prediction_obj = predict.prediction.ClassificationPredictionResult.from_map(prediction_)
print(prediction_obj)


Expand Down

0 comments on commit 1cbd4a5

Please sign in to comment.