Skip to content
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

automl: move video classification samples out of branch #3042

Merged
merged 15 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions automl/beta/video_classification_create_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
# limitations under the License.


def create_dataset(project_id, display_name):
"""Create a dataset."""
# [START automl_video_classification_create_dataset_beta]
from google.cloud import automl_v1beta1 as automl
# [START automl_video_classification_create_dataset_beta]
from google.cloud import automl_v1beta1 as automl

# TODO(developer): Uncomment and set the following variables
# project_id = "YOUR_PROJECT_ID"
# display_name = "your_datasets_display_name"

def create_dataset(
project_id="YOUR_PROJECT_ID", display_name="your_datasets_display_name"
):
"""Create a automl video classification dataset."""

client = automl.AutoMlClient()

Expand All @@ -37,9 +37,10 @@ def create_dataset(project_id, display_name):

# Display the dataset information
print("Dataset name: {}".format(created_dataset.name))

# To get the dataset id, you have to parse it out of the `name` field.
# As dataset Ids are required for other methods.
# Name Form:
# `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}`
print("Dataset id: {}".format(created_dataset.name.split("/")[-1]))
# [END automl_video_classification_create_dataset_beta]
# [END automl_video_classification_create_dataset_beta]
13 changes: 7 additions & 6 deletions automl/beta/video_classification_create_dataset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import datetime
import os
import uuid

from google.cloud import automl_v1beta1 as automl
import pytest
Expand All @@ -22,7 +22,7 @@


PROJECT_ID = os.environ["AUTOML_PROJECT_ID"]
pytest.DATASET_ID = None
DATASET_ID = None


@pytest.fixture(scope="function", autouse=True)
Expand All @@ -32,20 +32,21 @@ def teardown():
# Delete the created dataset
client = automl.AutoMlClient()
dataset_full_id = client.dataset_path(
PROJECT_ID, "us-central1", pytest.DATASET_ID
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_" + datetime.datetime.now().strftime("%Y%m%d%H%M%S")
dataset_name = "test_{}".format(uuid.uuid4()).replace("-", "")[:32]
video_classification_create_dataset.create_dataset(
PROJECT_ID, dataset_name
)
out, _ = capsys.readouterr()
assert "Dataset id: " in out

# Get the the created dataset id for deletion
pytest.DATASET_ID = out.splitlines()[1].split()[2]
# Get the dataset id for deletion
global DATASET_ID
DATASET_ID = out.splitlines()[1].split()[2]
22 changes: 11 additions & 11 deletions automl/beta/video_classification_create_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# [START automl_video_classification_create_model_beta]
from google.cloud import automl_v1beta1 as automl

def create_model(project_id, dataset_id, display_name):
"""Create a model."""
# [START automl_video_classification_create_model_beta]
from google.cloud import automl_v1beta1 as automl

# TODO(developer): Uncomment and set the following variables
# project_id = "YOUR_PROJECT_ID"
# dataset_id = "YOUR_DATASET_ID"
# display_name = "your_models_display_name"

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 location.
# A resource that represents Google Cloud Platform loacation.
nnegrey marked this conversation as resolved.
Show resolved Hide resolved
project_location = client.location_path(project_id, "us-central1")
# Leave model unset to use the default base model provided by Google
metadata = automl.types.VideoClassificationModelMetadata()
model = automl.types.Model(
display_name=display_name,
Expand All @@ -39,4 +39,4 @@ def create_model(project_id, dataset_id, display_name):

print("Training operation name: {}".format(response.operation.name))
print("Training started...")
# [END automl_video_classification_create_model_beta]
# [END automl_video_classification_create_model_beta]
17 changes: 9 additions & 8 deletions automl/beta/video_classification_create_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import os
import uuid

from google.cloud import automl_v1beta1 as automl
import pytest
Expand All @@ -21,26 +22,26 @@

PROJECT_ID = os.environ["GCLOUD_PROJECT"]
DATASET_ID = "VCN510437278078730240"
pytest.OPERATION_ID = None
OPERATION_ID = None


@pytest.fixture(scope="function", autouse=True)
def teardown():
yield

# Cancel the operation
# Cancel the training operation
client = automl.AutoMlClient()
client.transport._operations_client.cancel_operation(pytest.OPERATION_ID)
client.transport._operations_client.cancel_operation(OPERATION_ID)


def test_video_classification_create_model(capsys):
model_name = "test_{}".format(uuid.uuid4()).replace("-", "")[:32]
video_classification_create_model.create_model(
PROJECT_ID, DATASET_ID, "classification_test_create_model"
PROJECT_ID, DATASET_ID, model_name
)
out, _ = capsys.readouterr()
assert "Training started" in out

# Get the the operation id for cancellation
pytest.OPERATION_ID = out.split("Training operation name: ")[1].split(
"\n"
)[0]
# Cancel the operation
global OPERATION_ID
OPERATION_ID = out.split("Training operation name: ")[1].split("\n")[0]