-
Notifications
You must be signed in to change notification settings - Fork 6.5k
automl: move video object tracking samples out of branch #3043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f318768
automl: move video object tracking samples out of branch
nnegrey bace2a1
fix uuid and create test
nnegrey b639cfd
fix project
nnegrey 2edf3e9
use global var for testing
nnegrey 2833dd4
Update video_object_tracking_create_model_test.py
nnegrey 7b9b785
Merge branch 'master' into move-automl-ot-samples
nnegrey f56f80e
Merge branch 'master' into move-automl-ot-samples
nnegrey c4b8b90
Merge branch 'master' into move-automl-ot-samples
nnegrey eb9d05f
Merge branch 'master' into move-automl-ot-samples
nnegrey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,38 @@ | ||
# 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. | ||
|
||
# [START automl_video_object_tracking_create_dataset_beta] | ||
from google.cloud import automl_v1beta1 as automl | ||
|
||
|
||
def create_dataset( | ||
project_id="YOUR_PROJECT_ID", display_name="your_datasets_display_name" | ||
): | ||
"""Create a automl video object tracking dataset.""" | ||
client = automl.AutoMlClient() | ||
|
||
# A resource that represents Google Cloud Platform location. | ||
project_location = client.location_path(project_id, "us-central1") | ||
metadata = automl.types.VideoObjectTrackingDatasetMetadata() | ||
dataset = automl.types.Dataset( | ||
display_name=display_name, | ||
video_object_tracking_dataset_metadata=metadata, | ||
) | ||
|
||
# Create a dataset with the dataset metadata in the region. | ||
created_dataset = client.create_dataset(project_location, dataset) | ||
# Display the dataset information | ||
print("Dataset name: {}".format(created_dataset.name)) | ||
print("Dataset id: {}".format(created_dataset.name.split("/")[-1])) | ||
# [END automl_video_object_tracking_create_dataset_beta] |
This file contains hidden or 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,51 @@ | ||
# 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. | ||
|
||
import os | ||
import uuid | ||
|
||
from google.cloud import automl_v1beta1 as automl | ||
import pytest | ||
|
||
import video_object_tracking_create_dataset | ||
|
||
PROJECT_ID = os.environ["AUTOML_PROJECT_ID"] | ||
DATASET_ID = None | ||
|
||
|
||
@pytest.fixture(scope="function", autouse=True) | ||
def teardown(): | ||
yield | ||
|
||
# Delete the created dataset | ||
client = automl.AutoMlClient() | ||
dataset_full_id = client.dataset_path( | ||
PROJECT_ID, "us-central1", DATASET_ID | ||
) | ||
response = client.delete_dataset(dataset_full_id) | ||
response.result() | ||
|
||
|
||
def test_video_classification_create_dataset(capsys): | ||
# create dataset | ||
dataset_name = "test_{}".format(uuid.uuid4()).replace("-", "")[:32] | ||
video_object_tracking_create_dataset.create_dataset( | ||
PROJECT_ID, dataset_name | ||
) | ||
out, _ = capsys.readouterr() | ||
assert "Dataset id: " in out | ||
|
||
# Get the dataset id for deletion | ||
global DATASET_ID | ||
DATASET_ID = out.splitlines()[1].split()[2] |
This file contains hidden or 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 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. | ||
|
||
# [START automl_video_object_tracking_create_model_beta] | ||
from google.cloud import automl_v1beta1 as automl | ||
|
||
|
||
def create_model( | ||
project_id="YOUR_PROJECT_ID", | ||
dataset_id="YOUR_DATASET_ID", | ||
display_name="your_models_display_name", | ||
): | ||
"""Create a automl video classification model.""" | ||
client = automl.AutoMlClient() | ||
|
||
# A resource that represents Google Cloud Platform loacation. | ||
project_location = client.location_path(project_id, "us-central1") | ||
# Leave model unset to use the default base model provided by Google | ||
metadata = automl.types.VideoObjectTrackingModelMetadata() | ||
model = automl.types.Model( | ||
display_name=display_name, | ||
dataset_id=dataset_id, | ||
video_object_tracking_model_metadata=metadata, | ||
) | ||
|
||
# Create a model with the model metadata in the region. | ||
response = client.create_model(project_location, model) | ||
|
||
print("Training operation name: {}".format(response.operation.name)) | ||
print("Training started...") | ||
# [END automl_video_object_tracking_create_model_beta] |
This file contains hidden or 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,47 @@ | ||
# 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. | ||
|
||
import os | ||
import uuid | ||
|
||
from google.cloud import automl_v1beta1 as automl | ||
import pytest | ||
|
||
import video_object_tracking_create_model | ||
|
||
PROJECT_ID = os.environ["GCLOUD_PROJECT"] | ||
DATASET_ID = "VOT2823376535338090496" | ||
OPERATION_ID = None | ||
|
||
|
||
@pytest.fixture(scope="function", autouse=True) | ||
def teardown(): | ||
yield | ||
|
||
# Cancel the training operation | ||
client = automl.AutoMlClient() | ||
client.transport._operations_client.cancel_operation(OPERATION_ID) | ||
|
||
|
||
def test_video_classification_create_model(capsys): | ||
model_name = "test_{}".format(uuid.uuid4()).replace("-", "")[:32] | ||
video_object_tracking_create_model.create_model( | ||
PROJECT_ID, DATASET_ID, model_name | ||
) | ||
out, _ = capsys.readouterr() | ||
assert "Training started" in out | ||
|
||
# Cancel the operation | ||
global OPERATION_ID | ||
OPERATION_ID = out.split("Training operation name: ")[1].split("\n")[0] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.