在JupyterLab上使用以下代码来运行Google Video Intelligence软件包:
from google.cloud import videointelligence
import os
client = videointelligence.VideoIntelligenceServiceClient('VidIntelligence.JSON')
job = client.annotate_video(
input_uri='gs://vidintelligencebucket/The Simpsons - Monopoly Night.mp4',
features=['LABEL_DETECTION', 'SHOT_CHANGE_DETECTION'],
)
result = job.result()
当我运行它时,出现以下错误:
AttributeError: 'str' object has no attribute 'annotate_video'
有什么建议吗?
发生这种情况是因为ex4指出了变量client
的类型为str
,并且只包含一条错误消息。
发生错误,因为您试图以一种不正确的方式进行身份验证。传递给客户端的credentials
参数的参数不能为str
类型,而应为Credentials client
中所述的description对象。
您可以在overview上检查所有用于验证客户端的有效方法。
由于您有一个带有凭据的json
文件,您只需要使用一个名为GOOGLE_APPLICATION_CREDENTIALS
的环境变量指向该文件:
$ export GOOGLE_APPLICATION_CREDENTIALS="/path/to/VidIntelligence.json"
然后您将可以在不传递任何参数的情况下初始化客户端:
client = videointelligence.VideoIntelligenceServiceClient()
希望有帮助!