使用Google Vision web_detection时遇AttributeError:模块无'Image'属性
Google Vision
Image 报错的解决方法 这个报错是因为Google Cloud Vision Python SDK版本更新后,Image类的导入路径发生了变化,旧版本中直接从google.cloud.vision根模块可访问的Image,现在需要调整导入方式:
解决方法一:使用v1版本的模块导入
from google.cloud import vision_v1 client = vision_v1.ImageAnnotatorClient() image = vision_v1.Image()
解决方法二:从vision子模块直接导入Image
from google.cloud.vision import Image client = vision.ImageAnnotatorClient() image = Image()
设置图片URL的逻辑和之前一致,比如:
image.source.image_uri = "你的目标图片URL" # 执行网页检测 response = client.web_detection(image=image)
SDK版本迭代后调整了类的层级结构,只要按上述方式调整导入语句,就能正常使用web_detection功能。
内容的提问来源于stack exchange,提问作者Selva Prakash
相关产品推荐
相关产品推荐

