๋™์ž‘ ์ธ์‹

๋™์ž‘ ์ธ์‹์€ ๊ฑท๊ธฐ ๋˜๋Š” ์ถค์ถ”๊ธฐ์™€ ๊ฐ™์€ ๋™์˜์ƒ ํด๋ฆฝ์˜ ๋‹ค์–‘ํ•œ ์ž‘์—…์„ ์‹๋ณ„ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ ์ž‘์—…์€ ๋™์˜์ƒ์˜ ์ „์ฒด ์žฌ์ƒ ์‹œ๊ฐ„ ๋™์•ˆ ์ˆ˜ํ–‰๋˜๊ฑฐ๋‚˜ ์ˆ˜ํ–‰๋˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

AutoML ๋ชจ๋ธ ์‚ฌ์šฉ

์‹œ์ž‘ํ•˜๊ธฐ ์ „์—

AutoML ๋ชจ๋ธ ์ƒ์„ฑ์— ๋Œ€ํ•œ ๋ฐฐ๊ฒฝ ์ •๋ณด๋Š” Vertex AI ์ดˆ๋ณด์ž ๊ฐ€์ด๋“œ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”. AutoML ๋ชจ๋ธ์„ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ Vertex AI ๋ฌธ์„œ์˜ 'ML ๋ชจ๋ธ ๊ฐœ๋ฐœ ๋ฐ ์‚ฌ์šฉ'์—์„œ ๋™์˜์ƒ ๋ฐ์ดํ„ฐ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

AutoML ๋ชจ๋ธ ์‚ฌ์šฉ

๋‹ค์Œ ์ฝ”๋“œ ์ƒ˜ํ”Œ์€ ์ŠคํŠธ๋ฆฌ๋ฐ ํด๋ผ์ด์–ธํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ž‘์—… ์ธ์‹์— AutoML ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

Python

Video Intelligence์— ์ธ์ฆํ•˜๋ ค๋ฉด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ธฐ๋ณธ ์‚ฌ์šฉ์ž ์ธ์ฆ ์ •๋ณด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ๋กœ์ปฌ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์˜ ์ธ์ฆ ์„ค์ •์„ ์ฐธ์กฐํ•˜์„ธ์š”.

import io

from google.cloud import videointelligence_v1p3beta1 as videointelligence

# path = 'path_to_file'
# project_id = 'project_id'
# model_id = 'automl_action_recognition_model_id'

client = videointelligence.StreamingVideoIntelligenceServiceClient()

model_path = "projects/{}/locations/us-central1/models/{}".format(
    project_id, model_id
)

automl_config = videointelligence.StreamingAutomlActionRecognitionConfig(
    model_name=model_path
)

video_config = videointelligence.StreamingVideoConfig(
    feature=videointelligence.StreamingFeature.STREAMING_AUTOML_ACTION_RECOGNITION,
    automl_action_recognition_config=automl_config,
)

# config_request should be the first in the stream of requests.
config_request = videointelligence.StreamingAnnotateVideoRequest(
    video_config=video_config
)

# Set the chunk size to 5MB (recommended less than 10MB).
chunk_size = 5 * 1024 * 1024

def stream_generator():
    yield config_request
    # Load file content.
    # Note: Input videos must have supported video codecs. See
    # https://cloud.google.com/video-intelligence/docs/streaming/streaming#supported_video_codecs
    # for more details.
    with io.open(path, "rb") as video_file:
        while True:
            data = video_file.read(chunk_size)
            if not data:
                break
            yield videointelligence.StreamingAnnotateVideoRequest(
                input_content=data
            )

requests = stream_generator()

# streaming_annotate_video returns a generator.
# The default timeout is about 300 seconds.
# To process longer videos it should be set to
# larger than the length (in seconds) of the video.
responses = client.streaming_annotate_video(requests, timeout=900)

# Each response corresponds to about 1 second of video.
for response in responses:
    # Check for errors.
    if response.error.message:
        print(response.error.message)
        break

    for label in response.annotation_results.label_annotations:
        for frame in label.frames:
            print(
                "At {:3d}s segment, {:5.1%} {}".format(
                    frame.time_offset.seconds,
                    frame.confidence,
                    label.entity.entity_id,
                )
            )