From 077e15dfd19d8bd6fb5e83e4abcaad6c9146762d Mon Sep 17 00:00:00 2001 From: Morgan Du Date: Wed, 14 Apr 2021 10:40:48 -0700 Subject: [PATCH] resolve conflict --- samples/model-builder/conftest.py | 15 ++++--- .../create_and_import_dataset_video_sample.py | 43 ++++++++++++++++++ ...te_and_import_dataset_video_sample_test.py | 41 +++++++++++++++++ ...rt_data_video_action_recognition_sample.py | 44 ++++++++++++++++++ ...ta_video_action_recognition_sample_test.py | 40 +++++++++++++++++ ...import_data_video_classification_sample.py | 45 +++++++++++++++++++ ...t_data_video_classification_sample_test.py | 40 +++++++++++++++++ ...mport_data_video_object_tracking_sample.py | 44 ++++++++++++++++++ ..._data_video_object_tracking_sample_test.py | 39 ++++++++++++++++ 9 files changed, 346 insertions(+), 5 deletions(-) create mode 100644 samples/model-builder/create_and_import_dataset_video_sample.py create mode 100644 samples/model-builder/create_and_import_dataset_video_sample_test.py create mode 100644 samples/model-builder/import_data_video_action_recognition_sample.py create mode 100644 samples/model-builder/import_data_video_action_recognition_sample_test.py create mode 100644 samples/model-builder/import_data_video_classification_sample.py create mode 100644 samples/model-builder/import_data_video_classification_sample_test.py create mode 100644 samples/model-builder/import_data_video_object_tracking_sample.py create mode 100644 samples/model-builder/import_data_video_object_tracking_sample_test.py diff --git a/samples/model-builder/conftest.py b/samples/model-builder/conftest.py index 580c6a962d..5fdc0f93ea 100644 --- a/samples/model-builder/conftest.py +++ b/samples/model-builder/conftest.py @@ -130,11 +130,16 @@ def mock_import_text_dataset(mock_text_dataset): yield mock -""" ----------------------------------------------------------------------------- -TrainingJob Fixtures ----------------------------------------------------------------------------- -""" +@pytest.fixture +def mock_import_data(mock_dataset): + with patch.object(mock_dataset, "import_data") as mock: + mock.return_value = mock_dataset + yield mock + + +# ---------------------------------------------------------------------------- +# TrainingJob Fixtures +# ---------------------------------------------------------------------------- @pytest.fixture diff --git a/samples/model-builder/create_and_import_dataset_video_sample.py b/samples/model-builder/create_and_import_dataset_video_sample.py new file mode 100644 index 0000000000..32cad3170c --- /dev/null +++ b/samples/model-builder/create_and_import_dataset_video_sample.py @@ -0,0 +1,43 @@ +# Copyright 2021 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 +# +# https://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 typing import List, Union + +from google.cloud import aiplatform + +# [START aiplatform_sdk_create_and_import_dataset_video_sample] +def create_and_import_dataset_video_sample( + project: str, + location: str, + display_name: str, + src_uris: Union[str, List[str]], + sync: bool = True, +): + aiplatform.init(project=project, location=location) + + ds = aiplatform.VideoDataset.create( + display_name=display_name, + gcs_source=src_uris, + import_schema_uri=aiplatform.schema.dataset.ioformat.video.classification, + sync=sync, + ) + + ds.wait() + + print(ds.display_name) + print(ds.resource_name) + return ds + + +# [END aiplatform_sdk_create_and_import_dataset_video_sample] diff --git a/samples/model-builder/create_and_import_dataset_video_sample_test.py b/samples/model-builder/create_and_import_dataset_video_sample_test.py new file mode 100644 index 0000000000..dd2cd4dee9 --- /dev/null +++ b/samples/model-builder/create_and_import_dataset_video_sample_test.py @@ -0,0 +1,41 @@ +# Copyright 2021 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 +# +# https://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. + + +import test_constants as constants +import create_and_import_dataset_video_sample + +from google.cloud.aiplatform import schema + + +def test_create_and_import_dataset_video_sample( + mock_sdk_init, mock_create_video_dataset +): + + create_and_import_dataset_video_sample.create_and_import_dataset_video_sample( + project=constants.PROJECT, + location=constants.LOCATION, + src_uris=constants.GCS_SOURCES, + display_name=constants.DISPLAY_NAME, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + mock_create_video_dataset.assert_called_once_with( + display_name=constants.DISPLAY_NAME, + gcs_source=constants.GCS_SOURCES, + import_schema_uri=schema.dataset.ioformat.video.classification, + sync=True, + ) diff --git a/samples/model-builder/import_data_video_action_recognition_sample.py b/samples/model-builder/import_data_video_action_recognition_sample.py new file mode 100644 index 0000000000..826a8aa013 --- /dev/null +++ b/samples/model-builder/import_data_video_action_recognition_sample.py @@ -0,0 +1,44 @@ +# Copyright 2021 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 +# +# https://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 typing import List, Union + +from google.cloud import aiplatform + +# [START aiplatform_sdk_import_data_video_action_recognition_sample] +def import_data_video_action_recognition_sample( + project: str, + location: str, + dataset_name: str, + src_uris: Union[str, List[str]], + sync: bool = True, +): + aiplatform.init(project=project, location=location) + + ds = aiplatform.VideoDataset(dataset_name=dataset_name) + + ds.import_data( + gcs_source=src_uris, + import_schema_uri=aiplatform.schema.dataset.ioformat.video.action_recognition, + sync=sync, + ) + + ds.wait() + + print(ds.display_name) + print(ds.resource_name) + return ds + + +# [END aiplatform_sdk_import_data_video_action_recognition_sample] diff --git a/samples/model-builder/import_data_video_action_recognition_sample_test.py b/samples/model-builder/import_data_video_action_recognition_sample_test.py new file mode 100644 index 0000000000..a8ad4d58ef --- /dev/null +++ b/samples/model-builder/import_data_video_action_recognition_sample_test.py @@ -0,0 +1,40 @@ +# Copyright 2021 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 +# +# https://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. + +import pytest +import test_constants as constants +import import_data_video_action_recognition_sample + +from google.cloud.aiplatform import schema + + +@pytest.mark.usefixtures("mock_init_dataset") +def test_import_data_video_action_recognition_sample(mock_sdk_init, mock_import_data): + + import_data_video_action_recognition_sample.import_data_video_action_recognition_sample( + project=constants.PROJECT, + location=constants.LOCATION, + dataset_name=constants.DATASET_NAME, + src_uris=constants.GCS_SOURCES, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + + mock_import_data.assert_called_once_with( + gcs_source=constants.GCS_SOURCES, + import_schema_uri=schema.dataset.ioformat.video.action_recognition, + sync=True, + ) diff --git a/samples/model-builder/import_data_video_classification_sample.py b/samples/model-builder/import_data_video_classification_sample.py new file mode 100644 index 0000000000..4546dacd28 --- /dev/null +++ b/samples/model-builder/import_data_video_classification_sample.py @@ -0,0 +1,45 @@ +# Copyright 2021 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 +# +# https://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 typing import List, Union + +from google.cloud import aiplatform + +# [START aiplatform_sdk_import_data_video_classification_sample] +def import_data_video_classification_sample( + project: str, + location: str, + dataset_name: str, + src_uris: Union[str, List[str]], + sync: bool = True, +): + aiplatform.init(project=project, location=location) + + ds = aiplatform.VideoDataset(dataset_name=dataset_name) + + print(ds.display_name) + print(ds.resource_name) + + ds.import_data( + gcs_source=src_uris, + import_schema_uri=aiplatform.schema.dataset.ioformat.video.classification, + sync=sync, + ) + + ds.wait() + + return ds + + +# [END aiplatform_sdk_import_data_video_classification_sample] diff --git a/samples/model-builder/import_data_video_classification_sample_test.py b/samples/model-builder/import_data_video_classification_sample_test.py new file mode 100644 index 0000000000..32c85d9c2d --- /dev/null +++ b/samples/model-builder/import_data_video_classification_sample_test.py @@ -0,0 +1,40 @@ +# Copyright 2021 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 +# +# https://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. + +import pytest +import test_constants as constants +import import_data_video_classification_sample + +from google.cloud.aiplatform import schema + + +@pytest.mark.usefixtures("mock_init_dataset") +def test_import_data_video_classification_sample(mock_sdk_init, mock_import_data): + + import_data_video_classification_sample.import_data_video_classification_sample( + project=constants.PROJECT, + location=constants.LOCATION, + dataset_name=constants.DATASET_NAME, + src_uris=constants.GCS_SOURCES, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + + mock_import_data.assert_called_once_with( + gcs_source=constants.GCS_SOURCES, + import_schema_uri=schema.dataset.ioformat.video.classification, + sync=True, + ) diff --git a/samples/model-builder/import_data_video_object_tracking_sample.py b/samples/model-builder/import_data_video_object_tracking_sample.py new file mode 100644 index 0000000000..435e3d3347 --- /dev/null +++ b/samples/model-builder/import_data_video_object_tracking_sample.py @@ -0,0 +1,44 @@ +# Copyright 2021 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 +# +# https://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 typing import List, Union + +from google.cloud import aiplatform + +# [START aiplatform_sdk_import_data_video_object_tracking_sample] +def import_data_video_object_tracking_sample( + project: str, + location: str, + dataset_name: str, + src_uris: Union[str, List[str]], + sync: bool = True, +): + aiplatform.init(project=project, location=location) + + ds = aiplatform.VideoDataset(dataset_name=dataset_name) + + ds.import_data( + gcs_source=src_uris, + import_schema_uri=aiplatform.schema.dataset.ioformat.video.object_tracking, + sync=sync, + ) + + ds.wait() + + print(ds.display_name) + print(ds.resource_name) + return ds + + +# [END aiplatform_sdk_import_data_video_object_tracking_sample] diff --git a/samples/model-builder/import_data_video_object_tracking_sample_test.py b/samples/model-builder/import_data_video_object_tracking_sample_test.py new file mode 100644 index 0000000000..2e5ed69a53 --- /dev/null +++ b/samples/model-builder/import_data_video_object_tracking_sample_test.py @@ -0,0 +1,39 @@ +# Copyright 2021 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 +# +# https://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. + +import pytest +import test_constants as constants +import import_data_video_object_tracking_sample + +from google.cloud.aiplatform import schema + +@pytest.mark.usefixtures("mock_init_dataset") +def test_import_data_video_object_tracking_sample(mock_sdk_init, mock_import_data): + + import_data_video_object_tracking_sample.import_data_video_object_tracking_sample( + project=constants.PROJECT, + location=constants.LOCATION, + dataset_name=constants.DATASET_NAME, + src_uris=constants.GCS_SOURCES, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + + mock_import_data.assert_called_once_with( + gcs_source=constants.GCS_SOURCES, + import_schema_uri=schema.dataset.ioformat.video.object_tracking, + sync=True, + )