As I've a requirement to do custom model (Automl) using video classification feature for a streaming video data. I'm looking for a GCP support include preview or beta/alpha feature support. Can anyone help me does GCP supports this currently and can anyone please share any reference document to follow (like API Reference or How to's).
I've been checking GCP documents for the steps to use it and found this page. It has cpp client for live streaming data and python example for a local video content. I've followed steps in those and created automl model and tried both clients and got this error Requested model could not be loaded. Also I've tried github sample and I'm not sure whether videointelligence.googleapis.com is deprecated, so I've tried automl.googleapis.com examples but I could find batch prediction examples.
Can anyone help me on this?
import argparse
import io
import threading
import time
import os
from google.cloud import videointelligence_v1p3beta1 as videointelligence
def send_vi_api_request(stream, client, config_request):
def stream_generator():
yield config_request
for chunk in stream:
yield videointelligence.StreamingAnnotateVideoRequest(input_content=chunk)
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 stream.
responses = client.streaming_annotate_video(requests, timeout=600)
for response in responses:
# Check for errors.
if response.error.message:
print(response)
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,
)
)
def streaming_automl_classification(path, project_id, model_id):
client = videointelligence.StreamingVideoIntelligenceServiceClient()
model_path = "projects/{}/locations/us-central1/models/{}".format(
project_id, model_id
)
# Here we use classification as an example.
automl_config = videointelligence.StreamingAutomlClassificationConfig(
model_name=model_path
)
video_config = videointelligence.StreamingVideoConfig(
feature=videointelligence.StreamingFeature.STREAMING_AUTOML_CLASSIFICATION,
automl_classification_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
# 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.
stream = []
with io.open(path, "rb") as video_file:
while True:
data = video_file.read(chunk_size)
if not data:
if stream:
send_vi_api_request(stream, client, config_request)
stream = []
else:
print("No data received...")
time.sleep(10)
continue
# break
print(len(data))
stream.append(data)
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(
'file_path', help='Local file location for streaming video annotation.')
parser.add_argument("project_id")
parser.add_argument("model_id")
args = parser.parse_args()
streaming_automl_classification(args.file_path, args.project_id, args.model_id)
As suggested in the comments I've added the code sample code which I've used to send streaming data to the google api based on the document mentioned above.