質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

解決済

1回答

991閲覧

google cloud visionで顔検出チュートリアル、AttributeError: 'str' object has no attribute 'batch_annotate_images'

ksuhara

総合スコア13

Google Cloud Platform

Google Cloud Platformは、Google社がクラウド上で提供しているサービス郡の総称です。エンドユーザー向けサービスと同様のインフラストラクチャーで運営されており、Webサイト開発から複雑なアプリ開発まで対応可能です。

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2018/09/28 02:08

編集2018/09/28 02:12

google cloud visionの顔検出のチュートリアル(https://cloud.google.com/vision/docs/face-tutorial)を試しているのですが、表題の通りこのようなエラーでつまづいてます。

Traceback (most recent call last): File "google_face_detect.py", line 79, in <module> main(args.input_image, args.output, args.max_results) File "google_face_detect.py", line 55, in main faces = detect_face(image, max_results) File "google_face_detect.py", line 26, in detect_face return client.face_detection(image=image).face_annotations File "/Users/kentasuhara/.pyenv/versions/anaconda3-5.0.0/lib/python3.6/site-packages/google/cloud/vision_helpers/decorators.py", line 111, in inner response = self.annotate_image(request, retry=retry, timeout=timeout) File "/Users/kentasuhara/.pyenv/versions/anaconda3-5.0.0/lib/python3.6/site-packages/google/cloud/vision_helpers/__init__.py", line 67, in annotate_image r = self.batch_annotate_images([request], retry=retry, timeout=timeout) File "/Users/kentasuhara/.pyenv/versions/anaconda3-5.0.0/lib/python3.6/site-packages/google/cloud/vision_v1/gapic/image_annotator_client.py", line 209, in batch_annotate_images self.transport.batch_annotate_images, AttributeError: 'str' object has no attribute 'batch_annotate_images'

どこがstrになっていてどう直せばいいのでしょうか?

コードは以下の通りで、githubのコードをほぼそのままコピペしています。
またターミナルで実行しているコードは $python google_face_detect.py(ファイル名) 画像の絶対パス です。

python

1import argparse 2 3# [START vision_face_detection_tutorial_imports] 4from google.cloud import vision 5from google.cloud.vision import types 6from PIL import Image, ImageDraw 7# [END vision_face_detection_tutorial_imports] 8 9GOOGLE_APPLICATION_CREDENTIALS="絶対パス" 10 11# [START vision_face_detection_tutorial_send_request] 12def detect_face(face_file, max_results=4): 13 """Uses the Vision API to detect faces in the given file. 14 Args: 15 face_file: A file-like object containing an image with faces. 16 Returns: 17 An array of Face objects with information about the picture. 18 """ 19 # [START vision_face_detection_tutorial_client] 20 client = vision.ImageAnnotatorClient(GOOGLE_APPLICATION_CREDENTIALS) 21 # [END vision_face_detection_tutorial_client] 22 23 content = face_file.read() 24 image = types.Image(content=content) 25 26 return client.face_detection(image=image).face_annotations 27# [END vision_face_detection_tutorial_send_request] 28 29 30# [START vision_face_detection_tutorial_process_response] 31def highlight_faces(image, faces, output_filename): 32 """Draws a polygon around the faces, then saves to output_filename. 33 Args: 34 image: a file containing the image with the faces. 35 faces: a list of faces found in the file. This should be in the format 36 returned by the Vision API. 37 output_filename: the name of the image file to be created, where the 38 faces have polygons drawn around them. 39 """ 40 im = Image.open(image) 41 draw = ImageDraw.Draw(im) 42 43 for face in faces: 44 box = [(vertex.x, vertex.y) 45 for vertex in face.bounding_poly.vertices] 46 draw.line(box + [box[0]], width=5, fill='#00ff00') 47 48 im.save(output_filename) 49# [END vision_face_detection_tutorial_process_response] 50 51 52# [START vision_face_detection_tutorial_run_application] 53def main(input_filename, output_filename, max_results): 54 with open(input_filename, 'rb') as image: 55 faces = detect_face(image, max_results) 56 print('Found {} face{}'.format( 57 len(faces), '' if len(faces) == 1 else 's')) 58 59 print('Writing to file {}'.format(output_filename)) 60 # Reset the file pointer, so we can read the file again 61 image.seek(0) 62 highlight_faces(image, faces, output_filename) 63# [END vision_face_detection_tutorial_run_application] 64 65 66if __name__ == '__main__': 67 parser = argparse.ArgumentParser( 68 description='Detects faces in the given image.') 69 parser.add_argument( 70 'input_image', help='the image you\'d like to detect faces in.') 71 parser.add_argument( 72 '--out', dest='output', default='out.jpg', 73 help='the name of the output file.') 74 parser.add_argument( 75 '--max-results', dest='max_results', default=4, 76 help='the max results of face detection.') 77 args = parser.parse_args() 78 79 main(args.input_image, args.output, args.max_results) 80

よろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hayataka2049

2018/09/28 02:09

エラーはtraceback等含めて省略せず全文掲載した方が回答しやすいです
ksuhara

2018/09/28 02:14

ありがとうございます。全文掲載しました。
guest

回答1

0

ベストアンサー

python

1client = vision.ImageAnnotatorClient(GOOGLE_APPLICATION_CREDENTIALS)

が間違っているのでは? 第一引数はtransportになると思いますが、docstringによると

plain

1 transport (Union[~.ImageAnnotatorGrpcTransport, 2 Callable[[~.Credentials, type], ~.ImageAnnotatorGrpcTransport]): A transport 3 instance, responsible for actually making the API calls. 4 The default transport uses the gRPC protocol. 5 This argument may also be a callable which returns a 6 transport instance. Callables will be sent the credentials 7 as the first argument and the default transport class as 8 the second argument.

https://github.com/GoogleCloudPlatform/google-cloud-python/blob/master/vision/google/cloud/vision_v1/gapic/image_annotator_client.py#L85

とのことで、とりあえず絶対パスの文字列ではないようです。

投稿2018/09/28 04:40

hayataka2049

総合スコア30933

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ksuhara

2018/09/29 01:36

おっしゃる通り、ここには何も指定する必要がなく、アプリケーションのデフォルト認証情報を使用するための環境を設定がうまく出来ていなかったことが原因でした。ありがとうございました!!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問