-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: add mbsdk video dataset samples (#307)
* fix: rebase and resolve conflict * fix: lint
- Loading branch information
Showing
9 changed files
with
361 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
samples/model-builder/create_and_import_dataset_video_sample.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_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] |
42 changes: 42 additions & 0 deletions
42
samples/model-builder/create_and_import_dataset_video_sample_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# 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 google.cloud.aiplatform import schema | ||
|
||
import create_and_import_dataset_video_sample | ||
|
||
import test_constants as constants | ||
|
||
|
||
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, | ||
) |
45 changes: 45 additions & 0 deletions
45
samples/model-builder/import_data_video_action_recognition_sample.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_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] |
44 changes: 44 additions & 0 deletions
44
samples/model-builder/import_data_video_action_recognition_sample_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 google.cloud.aiplatform import schema | ||
|
||
import pytest | ||
|
||
import import_data_video_action_recognition_sample | ||
|
||
import test_constants as constants | ||
|
||
|
||
@pytest.mark.usefixtures("mock_get_video_dataset") | ||
def test_import_data_video_action_recognition_sample( | ||
mock_sdk_init, mock_import_video_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_video_data.assert_called_once_with( | ||
gcs_source=constants.GCS_SOURCES, | ||
import_schema_uri=schema.dataset.ioformat.video.action_recognition, | ||
sync=True, | ||
) |
46 changes: 46 additions & 0 deletions
46
samples/model-builder/import_data_video_classification_sample.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# 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] |
42 changes: 42 additions & 0 deletions
42
samples/model-builder/import_data_video_classification_sample_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# 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 google.cloud.aiplatform import schema | ||
|
||
import pytest | ||
|
||
import import_data_video_classification_sample | ||
|
||
import test_constants as constants | ||
|
||
|
||
@pytest.mark.usefixtures("mock_get_video_dataset") | ||
def test_import_data_video_classification_sample(mock_sdk_init, mock_import_video_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_video_data.assert_called_once_with( | ||
gcs_source=constants.GCS_SOURCES, | ||
import_schema_uri=schema.dataset.ioformat.video.classification, | ||
sync=True, | ||
) |
45 changes: 45 additions & 0 deletions
45
samples/model-builder/import_data_video_object_tracking_sample.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_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] |
44 changes: 44 additions & 0 deletions
44
samples/model-builder/import_data_video_object_tracking_sample_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 google.cloud.aiplatform import schema | ||
|
||
import pytest | ||
|
||
import import_data_video_object_tracking_sample | ||
|
||
import test_constants as constants | ||
|
||
|
||
@pytest.mark.usefixtures("mock_get_video_dataset") | ||
def test_import_data_video_object_tracking_sample( | ||
mock_sdk_init, mock_import_video_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_video_data.assert_called_once_with( | ||
gcs_source=constants.GCS_SOURCES, | ||
import_schema_uri=schema.dataset.ioformat.video.object_tracking, | ||
sync=True, | ||
) |