GeezerVison is showing github.com — Feat: add mbsdk video dataset samples (#307) · aditdn/python-aiplatform@24d6920
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: samples/model-builder/conftest.py +9-5Lines changed: 9 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -130,11 +130,15 @@ def mock_import_text_dataset(mock_text_dataset): | 130 | 130 | yield mock | 131 | 131 |
| 132 | 132 |
| 133 | | -""" | 134 | | ----------------------------------------------------------------------------- | 135 | | -TrainingJob Fixtures | 136 | | ----------------------------------------------------------------------------- | 137 | | -""" | | 133 | +@pytest.fixture | | 134 | +def mock_import_video_data(mock_video_dataset): | | 135 | + with patch.object(mock_video_dataset, "import_data") as mock: | | 136 | + yield mock | | 137 | + | | 138 | + | | 139 | +# ---------------------------------------------------------------------------- | | 140 | +# TrainingJob Fixtures | | 141 | +# ---------------------------------------------------------------------------- | 138 | 142 |
| 139 | 143 |
| 140 | 144 | @pytest.fixture | |
Collapse file Copy file name to clipboard +44Lines changed: 44 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Copyright 2021 Google LLC | | 2 | +# | | 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | +# you may not use this file except in compliance with the License. | | 5 | +# You may obtain a copy of the License at | | 6 | +# | | 7 | +# https://www.apache.org/licenses/LICENSE-2.0 | | 8 | +# | | 9 | +# Unless required by applicable law or agreed to in writing, software | | 10 | +# distributed under the License is distributed on an "AS IS" BASIS, | | 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 12 | +# See the License for the specific language governing permissions and | | 13 | +# limitations under the License. | | 14 | + | | 15 | +from typing import List, Union | | 16 | + | | 17 | +from google.cloud import aiplatform | | 18 | + | | 19 | + | | 20 | +# [START aiplatform_sdk_create_and_import_dataset_video_sample] | | 21 | +def create_and_import_dataset_video_sample( | | 22 | + project: str, | | 23 | + location: str, | | 24 | + display_name: str, | | 25 | + src_uris: Union[str, List[str]], | | 26 | + sync: bool = True, | | 27 | +): | | 28 | + aiplatform.init(project=project, location=location) | | 29 | + | | 30 | + ds = aiplatform.VideoDataset.create( | | 31 | + display_name=display_name, | | 32 | + gcs_source=src_uris, | | 33 | + import_schema_uri=aiplatform.schema.dataset.ioformat.video.classification, | | 34 | + sync=sync, | | 35 | + ) | | 36 | + | | 37 | + ds.wait() | | 38 | + | | 39 | + print(ds.display_name) | | 40 | + print(ds.resource_name) | | 41 | + return ds | | 42 | + | | 43 | + | | 44 | +# [END aiplatform_sdk_create_and_import_dataset_video_sample] |
Collapse file Copy file name to clipboard +42Lines changed: 42 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Copyright 2021 Google LLC | | 2 | +# | | 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | +# you may not use this file except in compliance with the License. | | 5 | +# You may obtain a copy of the License at | | 6 | +# | | 7 | +# https://www.apache.org/licenses/LICENSE-2.0 | | 8 | +# | | 9 | +# Unless required by applicable law or agreed to in writing, software | | 10 | +# distributed under the License is distributed on an "AS IS" BASIS, | | 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 12 | +# See the License for the specific language governing permissions and | | 13 | +# limitations under the License. | | 14 | + | | 15 | + | | 16 | +from google.cloud.aiplatform import schema | | 17 | + | | 18 | +import create_and_import_dataset_video_sample | | 19 | + | | 20 | +import test_constants as constants | | 21 | + | | 22 | + | | 23 | +def test_create_and_import_dataset_video_sample( | | 24 | + mock_sdk_init, mock_create_video_dataset | | 25 | +): | | 26 | + | | 27 | + create_and_import_dataset_video_sample.create_and_import_dataset_video_sample( | | 28 | + project=constants.PROJECT, | | 29 | + location=constants.LOCATION, | | 30 | + src_uris=constants.GCS_SOURCES, | | 31 | + display_name=constants.DISPLAY_NAME, | | 32 | + ) | | 33 | + | | 34 | + mock_sdk_init.assert_called_once_with( | | 35 | + project=constants.PROJECT, location=constants.LOCATION | | 36 | + ) | | 37 | + mock_create_video_dataset.assert_called_once_with( | | 38 | + display_name=constants.DISPLAY_NAME, | | 39 | + gcs_source=constants.GCS_SOURCES, | | 40 | + import_schema_uri=schema.dataset.ioformat.video.classification, | | 41 | + sync=True, | | 42 | + ) |
Collapse file Copy file name to clipboard +45Lines changed: 45 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Copyright 2021 Google LLC | | 2 | +# | | 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | +# you may not use this file except in compliance with the License. | | 5 | +# You may obtain a copy of the License at | | 6 | +# | | 7 | +# https://www.apache.org/licenses/LICENSE-2.0 | | 8 | +# | | 9 | +# Unless required by applicable law or agreed to in writing, software | | 10 | +# distributed under the License is distributed on an "AS IS" BASIS, | | 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 12 | +# See the License for the specific language governing permissions and | | 13 | +# limitations under the License. | | 14 | + | | 15 | +from typing import List, Union | | 16 | + | | 17 | +from google.cloud import aiplatform | | 18 | + | | 19 | + | | 20 | +# [START aiplatform_sdk_import_data_video_action_recognition_sample] | | 21 | +def import_data_video_action_recognition_sample( | | 22 | + project: str, | | 23 | + location: str, | | 24 | + dataset_name: str, | | 25 | + src_uris: Union[str, List[str]], | | 26 | + sync: bool = True, | | 27 | +): | | 28 | + aiplatform.init(project=project, location=location) | | 29 | + | | 30 | + ds = aiplatform.VideoDataset(dataset_name=dataset_name) | | 31 | + | | 32 | + ds.import_data( | | 33 | + gcs_source=src_uris, | | 34 | + import_schema_uri=aiplatform.schema.dataset.ioformat.video.action_recognition, | | 35 | + sync=sync, | | 36 | + ) | | 37 | + | | 38 | + ds.wait() | | 39 | + | | 40 | + print(ds.display_name) | | 41 | + print(ds.resource_name) | | 42 | + return ds | | 43 | + | | 44 | + | | 45 | +# [END aiplatform_sdk_import_data_video_action_recognition_sample] |
Collapse file Copy file name to clipboard +44Lines changed: 44 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Copyright 2021 Google LLC | | 2 | +# | | 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | +# you may not use this file except in compliance with the License. | | 5 | +# You may obtain a copy of the License at | | 6 | +# | | 7 | +# https://www.apache.org/licenses/LICENSE-2.0 | | 8 | +# | | 9 | +# Unless required by applicable law or agreed to in writing, software | | 10 | +# distributed under the License is distributed on an "AS IS" BASIS, | | 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 12 | +# See the License for the specific language governing permissions and | | 13 | +# limitations under the License. | | 14 | + | | 15 | +from google.cloud.aiplatform import schema | | 16 | + | | 17 | +import pytest | | 18 | + | | 19 | +import import_data_video_action_recognition_sample | | 20 | + | | 21 | +import test_constants as constants | | 22 | + | | 23 | + | | 24 | +@pytest.mark.usefixtures("mock_get_video_dataset") | | 25 | +def test_import_data_video_action_recognition_sample( | | 26 | + mock_sdk_init, mock_import_video_data | | 27 | +): | | 28 | + | | 29 | + import_data_video_action_recognition_sample.import_data_video_action_recognition_sample( | | 30 | + project=constants.PROJECT, | | 31 | + location=constants.LOCATION, | | 32 | + dataset_name=constants.DATASET_NAME, | | 33 | + src_uris=constants.GCS_SOURCES, | | 34 | + ) | | 35 | + | | 36 | + mock_sdk_init.assert_called_once_with( | | 37 | + project=constants.PROJECT, location=constants.LOCATION | | 38 | + ) | | 39 | + | | 40 | + mock_import_video_data.assert_called_once_with( | | 41 | + gcs_source=constants.GCS_SOURCES, | | 42 | + import_schema_uri=schema.dataset.ioformat.video.action_recognition, | | 43 | + sync=True, | | 44 | + ) |
Collapse file Copy file name to clipboard +46Lines changed: 46 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Copyright 2021 Google LLC | | 2 | +# | | 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | +# you may not use this file except in compliance with the License. | | 5 | +# You may obtain a copy of the License at | | 6 | +# | | 7 | +# https://www.apache.org/licenses/LICENSE-2.0 | | 8 | +# | | 9 | +# Unless required by applicable law or agreed to in writing, software | | 10 | +# distributed under the License is distributed on an "AS IS" BASIS, | | 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 12 | +# See the License for the specific language governing permissions and | | 13 | +# limitations under the License. | | 14 | + | | 15 | +from typing import List, Union | | 16 | + | | 17 | +from google.cloud import aiplatform | | 18 | + | | 19 | + | | 20 | +# [START aiplatform_sdk_import_data_video_classification_sample] | | 21 | +def import_data_video_classification_sample( | | 22 | + project: str, | | 23 | + location: str, | | 24 | + dataset_name: str, | | 25 | + src_uris: Union[str, List[str]], | | 26 | + sync: bool = True, | | 27 | +): | | 28 | + aiplatform.init(project=project, location=location) | | 29 | + | | 30 | + ds = aiplatform.VideoDataset(dataset_name=dataset_name) | | 31 | + | | 32 | + print(ds.display_name) | | 33 | + print(ds.resource_name) | | 34 | + | | 35 | + ds.import_data( | | 36 | + gcs_source=src_uris, | | 37 | + import_schema_uri=aiplatform.schema.dataset.ioformat.video.classification, | | 38 | + sync=sync, | | 39 | + ) | | 40 | + | | 41 | + ds.wait() | | 42 | + | | 43 | + return ds | | 44 | + | | 45 | + | | 46 | +# [END aiplatform_sdk_import_data_video_classification_sample] |
Collapse file Copy file name to clipboard +42Lines changed: 42 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Copyright 2021 Google LLC | | 2 | +# | | 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | +# you may not use this file except in compliance with the License. | | 5 | +# You may obtain a copy of the License at | | 6 | +# | | 7 | +# https://www.apache.org/licenses/LICENSE-2.0 | | 8 | +# | | 9 | +# Unless required by applicable law or agreed to in writing, software | | 10 | +# distributed under the License is distributed on an "AS IS" BASIS, | | 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 12 | +# See the License for the specific language governing permissions and | | 13 | +# limitations under the License. | | 14 | + | | 15 | +from google.cloud.aiplatform import schema | | 16 | + | | 17 | +import pytest | | 18 | + | | 19 | +import import_data_video_classification_sample | | 20 | + | | 21 | +import test_constants as constants | | 22 | + | | 23 | + | | 24 | +@pytest.mark.usefixtures("mock_get_video_dataset") | | 25 | +def test_import_data_video_classification_sample(mock_sdk_init, mock_import_video_data): | | 26 | + | | 27 | + import_data_video_classification_sample.import_data_video_classification_sample( | | 28 | + project=constants.PROJECT, | | 29 | + location=constants.LOCATION, | | 30 | + dataset_name=constants.DATASET_NAME, | | 31 | + src_uris=constants.GCS_SOURCES, | | 32 | + ) | | 33 | + | | 34 | + mock_sdk_init.assert_called_once_with( | | 35 | + project=constants.PROJECT, location=constants.LOCATION | | 36 | + ) | | 37 | + | | 38 | + mock_import_video_data.assert_called_once_with( | | 39 | + gcs_source=constants.GCS_SOURCES, | | 40 | + import_schema_uri=schema.dataset.ioformat.video.classification, | | 41 | + sync=True, | | 42 | + ) |
Collapse file Copy file name to clipboard +45Lines changed: 45 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Copyright 2021 Google LLC | | 2 | +# | | 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | +# you may not use this file except in compliance with the License. | | 5 | +# You may obtain a copy of the License at | | 6 | +# | | 7 | +# https://www.apache.org/licenses/LICENSE-2.0 | | 8 | +# | | 9 | +# Unless required by applicable law or agreed to in writing, software | | 10 | +# distributed under the License is distributed on an "AS IS" BASIS, | | 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 12 | +# See the License for the specific language governing permissions and | | 13 | +# limitations under the License. | | 14 | + | | 15 | +from typing import List, Union | | 16 | + | | 17 | +from google.cloud import aiplatform | | 18 | + | | 19 | + | | 20 | +# [START aiplatform_sdk_import_data_video_object_tracking_sample] | | 21 | +def import_data_video_object_tracking_sample( | | 22 | + project: str, | | 23 | + location: str, | | 24 | + dataset_name: str, | | 25 | + src_uris: Union[str, List[str]], | | 26 | + sync: bool = True, | | 27 | +): | | 28 | + aiplatform.init(project=project, location=location) | | 29 | + | | 30 | + ds = aiplatform.VideoDataset(dataset_name=dataset_name) | | 31 | + | | 32 | + ds.import_data( | | 33 | + gcs_source=src_uris, | | 34 | + import_schema_uri=aiplatform.schema.dataset.ioformat.video.object_tracking, | | 35 | + sync=sync, | | 36 | + ) | | 37 | + | | 38 | + ds.wait() | | 39 | + | | 40 | + print(ds.display_name) | | 41 | + print(ds.resource_name) | | 42 | + return ds | | 43 | + | | 44 | + | | 45 | +# [END aiplatform_sdk_import_data_video_object_tracking_sample] |
Collapse file Copy file name to clipboard +44Lines changed: 44 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +# Copyright 2021 Google LLC | | 2 | +# | | 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); | | 4 | +# you may not use this file except in compliance with the License. | | 5 | +# You may obtain a copy of the License at | | 6 | +# | | 7 | +# https://www.apache.org/licenses/LICENSE-2.0 | | 8 | +# | | 9 | +# Unless required by applicable law or agreed to in writing, software | | 10 | +# distributed under the License is distributed on an "AS IS" BASIS, | | 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | | 12 | +# See the License for the specific language governing permissions and | | 13 | +# limitations under the License. | | 14 | + | | 15 | +from google.cloud.aiplatform import schema | | 16 | + | | 17 | +import pytest | | 18 | + | | 19 | +import import_data_video_object_tracking_sample | | 20 | + | | 21 | +import test_constants as constants | | 22 | + | | 23 | + | | 24 | +@pytest.mark.usefixtures("mock_get_video_dataset") | | 25 | +def test_import_data_video_object_tracking_sample( | | 26 | + mock_sdk_init, mock_import_video_data | | 27 | +): | | 28 | + | | 29 | + import_data_video_object_tracking_sample.import_data_video_object_tracking_sample( | | 30 | + project=constants.PROJECT, | | 31 | + location=constants.LOCATION, | | 32 | + dataset_name=constants.DATASET_NAME, | | 33 | + src_uris=constants.GCS_SOURCES, | | 34 | + ) | | 35 | + | | 36 | + mock_sdk_init.assert_called_once_with( | | 37 | + project=constants.PROJECT, location=constants.LOCATION | | 38 | + ) | | 39 | + | | 40 | + mock_import_video_data.assert_called_once_with( | | 41 | + gcs_source=constants.GCS_SOURCES, | | 42 | + import_schema_uri=schema.dataset.ioformat.video.object_tracking, | | 43 | + sync=True, | | 44 | + ) |
|