gpt4 book ai didi

python - 属性错误 : module 'google.cloud.vision' has no attribute 'types'

转载 作者:行者123 更新时间:2023-12-03 18:43:17 24 4
gpt4 key购买 nike

我通过 Python 进行了使用 Google Vision API 的设置,但它不起作用,我也没有找到任何好的解决方案。不管我做什么,我总是得到"AttributeError: module 'google.cloud.vision' has no attribute 'types'" ...
这是我使用的示例代码(已完成身份验证等)。

from __future__ import print_function
from google.cloud import vision
from google.cloud.vision import types

image_uri = 'gs://cloud-samples-data/vision/using_curl/shanghai.jpeg'

client = vision.ImageAnnotatorClient()
image = types.Image(content=IMAGE_CONTENT)
label_results = client.label_detection(image=image)

response = client.label_detection(image=image)

print('Labels (and confidence score):')
print('=' * 30)

for label in label_results.label_annotations:
print(f'{label.description} - {label.score}')
这是我的点卡住:
appdirs==1.4.3
CacheControl==0.12.6
cachetools==4.1.1
certifi==2019.11.28
chardet==3.0.4
colorama==0.4.3
contextlib2==0.6.0
distlib==0.3.0
distro==1.4.0
google-api-core==1.22.4
google-auth==1.22.1
google-cloud-vision==2.0.0
googleapis-common-protos==1.52.0
grpcio==1.32.0
html5lib==1.0.1
idna==2.8
ipaddr==2.2.0
libcst==0.3.12
lockfile==0.12.2
msgpack==0.6.2
mypy-extensions==0.4.3
packaging==20.3
pep517==0.8.2
pkg-resources==0.0.0
progress==1.5
proto-plus==1.10.0
protobuf==3.13.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pyparsing==2.4.6
pytoml==0.1.21
pytz==2020.1
PyYAML==5.3.1
requests==2.22.0
retrying==1.3.3
rsa==4.6
six==1.14.0
typing-extensions==3.7.4.3
typing-inspect==0.6.0
urllib3==1.25.8
webencodings==0.5.1
任何的想法?

最佳答案

我认为您应该遵循官方文档:
Vision Client Libraries

import io
import os

# Imports the Google Cloud client library
from google.cloud import vision

# Instantiates a client
client = vision.ImageAnnotatorClient()

# The name of the image file to annotate
file_name = os.path.abspath('resources/wakeupcat.jpg')

# Loads the image into memory
with io.open(file_name, 'rb') as image_file:
content = image_file.read()

image = vision.Image(content=content)

# Performs label detection on the image file
response = client.label_detection(image=image)
labels = response.label_annotations

print('Labels:')
for label in labels:
print(label.description)


它用于创建图像 愿景 模块:
image = vision.Image(content=content) 

not

image = types.Image(content=IMAGE_CONTENT)

关于python - 属性错误 : module 'google.cloud.vision' has no attribute 'types' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64226174/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com