前提
GoogleのVision APIを試用しているのですが、速度が遅いです。
チュートリアルのコードをそのまま実行しているだけなのに、30秒弱かかります。
Googleがブラウザ上で提供しているサンプルでは一瞬で解析してくれるので複雑なタスクというわけもなさそうです。
原因や、パフォーマンスの向上につながる施策が何かあれば教えていただきたいです。
参照先
こちらに掲載されているサンプルコードを実行しました。
https://cloud.google.com/vision/docs/object-localizer
該当のソースコード
サンプルコードと同じ画像を使用しています。
時間測定のためのコードを追加していますが、それ以外は変えていません。
main.py
1import time 2 3def localize_objects(path): 4 start = time.time() #時間計測 5 """Localize objects in the local image. 6 7 Args: 8 path: The path to the local file. 9 """ 10 from google.cloud import vision 11 client = vision.ImageAnnotatorClient() 12 13 with open(path, 'rb') as image_file: 14 content = image_file.read() 15 16 image = vision.Image(content=content) 17 18 start2 = time.time() #時間計測 19 objects = client.object_localization( 20 image=image).localized_object_annotations 21 end2 = time.time() #時間計測 22 23 print('Number of objects found: {}'.format(len(objects))) 24 for object_ in objects: 25 print('\n{} (confidence: {})'.format(object_.name, object_.score)) 26 print('Normalized bounding polygon vertices: ') 27 for vertex in object_.bounding_poly.normalized_vertices: 28 print(' - ({}, {})'.format(vertex.x, vertex.y)) 29 30 end = time.time() #時間計測 31 print("総実行時間:{}".format(end - start)) 32 print("annotationsにかかる時間:{}".format(end2 - start2)) 33 34localize_objects("./resources/bicycle_original.jpeg")
実行結果
Number of objects found: 4 Bicycle wheel (confidence: 0.9344853758811951) Normalized bounding polygon vertices: - (0.31457117199897766, 0.7848830223083496) - (0.44048216938972473, 0.7848830223083496) - (0.44048216938972473, 0.9704981446266174) - (0.31457117199897766, 0.9704981446266174) Bicycle wheel (confidence: 0.9330147504806519) Normalized bounding polygon vertices: - (0.5049288272857666, 0.7552310824394226) - (0.627302348613739, 0.7552310824394226) - (0.627302348613739, 0.944308340549469) - (0.5049288272857666, 0.944308340549469) Bicycle (confidence: 0.9041756391525269) Normalized bounding polygon vertices: - (0.31727585196495056, 0.6597068905830383) - (0.6291733980178833, 0.6597068905830383) - (0.6291733980178833, 0.9677099585533142) - (0.31727585196495056, 0.9677099585533142) Picture frame (confidence: 0.6569825410842896) Normalized bounding polygon vertices: - (0.786456823348999, 0.16705626249313354) - (0.9639955163002014, 0.16705626249313354) - (0.9639955163002014, 0.3188837766647339) - (0.786456823348999, 0.3188837766647339) 総実行時間:25.37931489944458 annotationsにかかる時間:25.37454390525818
見ていただいてわかる通り、下記の記述部分でかなり時間がかかっているようです。
objects = client.object_localization( image=image).localized_object_annotations
回答1件
あなたの回答
tips
プレビュー