Skip to content

Commit 1cbd4a5

Browse files
authored
feat: add schema namespace (#140)
* feat: add schema namespace
1 parent 1a302d2 commit 1cbd4a5

File tree

11 files changed

+114
-15
lines changed

11 files changed

+114
-15
lines changed

google/cloud/aiplatform/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@
1616
#
1717

1818
from google.cloud.aiplatform import gapic
19+
from google.cloud.aiplatform import schema
1920

20-
__all__ = (gapic,)
21+
22+
__all__ = (gapic, schema)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright 2020 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
from google.cloud.aiplatform.v1beta1.schema import predict
19+
from google.cloud.aiplatform.v1beta1.schema import trainingjob
20+
21+
22+
__all__ = (
23+
"predict",
24+
"trainingjob",
25+
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright 2020 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
from google.cloud.aiplatform.v1beta1.schema import predict
19+
from google.cloud.aiplatform.v1beta1.schema import trainingjob
20+
21+
22+
__all__ = (
23+
"predict",
24+
"trainingjob",
25+
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright 2020 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
from google.cloud.aiplatform.v1beta1.schema.predict import instance
19+
from google.cloud.aiplatform.v1beta1.schema.predict import params
20+
from google.cloud.aiplatform.v1beta1.schema.predict import prediction
21+
22+
__all__ = (
23+
"instance",
24+
"params",
25+
"prediction",
26+
)

google/cloud/aiplatform/v1beta1/schema/predict/instance/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616
#
1717
from google.cloud.aiplatform.helpers import _decorators
18-
import google.cloud.aiplatform.v1beta1.schema.predict.instance_v1beta1.types as pkg
18+
from google.cloud.aiplatform.v1beta1.schema.predict.instance_v1beta1 import types as pkg
1919

2020
from google.cloud.aiplatform.v1beta1.schema.predict.instance_v1beta1.types.image_classification import (
2121
ImageClassificationPredictionInstance,

google/cloud/aiplatform/v1beta1/schema/predict/params/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616
#
1717
from google.cloud.aiplatform.helpers import _decorators
18-
import google.cloud.aiplatform.v1beta1.schema.predict.params_v1beta1.types as pkg
18+
from google.cloud.aiplatform.v1beta1.schema.predict.params_v1beta1 import types as pkg
1919

2020
from google.cloud.aiplatform.v1beta1.schema.predict.params_v1beta1.types.image_classification import (
2121
ImageClassificationPredictionParams,

google/cloud/aiplatform/v1beta1/schema/predict/prediction/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
# limitations under the License.
1616
#
1717
from google.cloud.aiplatform.helpers import _decorators
18-
import google.cloud.aiplatform.v1beta1.schema.predict.prediction_v1beta1.types as pkg
18+
from google.cloud.aiplatform.v1beta1.schema.predict.prediction_v1beta1 import (
19+
types as pkg,
20+
)
1921

2022
from google.cloud.aiplatform.v1beta1.schema.predict.prediction_v1beta1.types.classification import (
2123
ClassificationPredictionResult,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright 2020 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
from google.cloud.aiplatform.v1beta1.schema.trainingjob import definition
19+
20+
__all__ = ("definition",)

google/cloud/aiplatform/v1beta1/schema/trainingjob/definition/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
# limitations under the License.
1616
#
1717
from google.cloud.aiplatform.helpers import _decorators
18-
import google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types as pkg
18+
from google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1 import (
19+
types as pkg,
20+
)
1921

2022
from google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.automl_forecasting import (
2123
AutoMlForecasting,

samples/snippets/create_training_pipeline_image_classification_sample.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
# [START aiplatform_create_training_pipeline_image_classification_sample]
1616
from google.cloud import aiplatform
17-
from google.cloud.aiplatform.v1beta1.schema.trainingjob import definition
18-
ModelType = definition.AutoMlImageClassificationInputs().ModelType
17+
from google.cloud.aiplatform.schema import trainingjob
1918

2019

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

35-
icn_training_inputs = definition.AutoMlImageClassificationInputs(
34+
icn_training_inputs = trainingjob.definition.AutoMlImageClassificationInputs(
3635
multi_label=True,
37-
model_type=ModelType.CLOUD,
36+
model_type=trainingjob.definition.AutoMlImageClassificationInputs.ModelType.CLOUD,
3837
budget_milli_node_hours=8000,
3938
disable_early_stopping=False
4039
)

samples/snippets/predict_image_classification_sample.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
import base64
1717

1818
from google.cloud import aiplatform
19-
from google.cloud.aiplatform.v1beta1.schema.predict import instance
20-
from google.cloud.aiplatform.v1beta1.schema.predict import params
21-
from google.cloud.aiplatform.v1beta1.schema.predict import prediction
19+
from google.cloud.aiplatform.schema import predict
2220

2321

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

42-
instance_obj = instance.ImageClassificationPredictionInstance(
40+
instance_obj = predict.instance.ImageClassificationPredictionInstance(
4341
content=encoded_content)
4442

4543
instance_val = instance_obj.to_value()
4644
instances = [instance_val]
4745

48-
params_obj = params.ImageClassificationPredictionParams(
46+
params_obj = predict.params.ImageClassificationPredictionParams(
4947
confidence_threshold=0.5, max_predictions=5)
5048

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

6563

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy