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
よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー