処理速度0.014秒 FACE01 GRAPHICS ver.1.2.5

2021年8月8日、FACE01 GRAPHICSはバージョン1.2.5になりました。ここでは改めて処理速度の計測をしてみたいと思います。

FACE01 GRAPHICSを現実的な速度で動作させるにはミドルクラスかそれ以上のGPUカード(GeForce® GTX 1660 Tiなど)が必要です。

下記は検証に用いたマシンプロファイルです

-Computer-
Processor		: AMD Ryzen 5 1400 Quad-Core Processor
Memory			: 16389MB
Machine Type		: Desktop
Operating System	: Ubuntu 18.04.5 LTS
OpenGL Renderer		: NVIDIA GeForce GTX 1660 Ti/PCIe/SSE2

コード

FACE01 GRAPHICSを外部から呼び出すCALL_FACE01GRAPHICS125を作成し、その中にタイマー機能を付与します。CALL_FACE01GRAPHICS125の全コードは以下のとおりです。

CALL_FACE01GRAPHICS125.py
# 変数設定 ========================== tolerance=0.45 jitters=0 upsampling=0 mode='cnn' frame_skip=-1 movie='test_distortion.mp4' rectangle=False target_rectangle=True show_video=False frequency_crop_image=10 set_area='NONE' face_learning_bool=False how_many_face_learning_images=1 output_frame_data_bool=False print_property=False calculate_time=True SET_WIDTH=500 # =================================== import time from concurrent.futures import ProcessPoolExecutor import cv2 import PySimpleGUI as sg import FACE01GRAPHICS125 as fg kaoninshoDir, priset_face_imagesDir = fg.home() known_face_encodings, known_face_names = fg.load_priset_image.load_priset_image( kaoninshoDir, priset_face_imagesDir, jitters = 10, upsampling=0, ) xs = fg.face_attestation( kaoninshoDir, known_face_encodings, known_face_names, tolerance=tolerance, jitters=jitters, upsampling=upsampling, mode=mode, model='small', frame_skip=frame_skip, movie=movie, rectangle=rectangle, target_rectangle=target_rectangle, show_video=show_video, frequency_crop_image=frequency_crop_image, set_area=set_area, face_learning_bool=face_learning_bool, how_many_face_learning_images=how_many_face_learning_images, output_frame_data=output_frame_data_bool, print_property=print_property, calculate_time=calculate_time, SET_WIDTH=SET_WIDTH ) # window実装 layout = [ [sg.Text('GUI実装例')], [sg.Image(filename='', pad=(25,25), key='cam1')] ] window = sg.Window('window1', layout, alpha_channel=1) # 並行処理 def multi(x): return x['img'] pool = ProcessPoolExecutor() for x in xs: # <DEBUG> if x=={}: continue befor_time = time.perf_counter() result = pool.submit(multi, x) event, _ = window.read(timeout=1) if event == sg.WIN_CLOSED: break imgbytes=cv2.imencode(".png", result.result())[1].tobytes() window["cam1"].update(data=imgbytes) after_time=time.perf_counter() print(f'{round((after_time - befor_time) * 1000, 2)}') # window close window.close() print('終了します')

登録人数は約650人で検証しました。

勘所

外部プログラムがFACE01 GRAPHICSにリクエストを投げて処理結果が返ってくるまでを計測しました。下記が該当部分になります。

def multi(x):
    return x['img']

for x in xs:
    ...
    befor_time = time.perf_counter()
    ...
    result = pool.submit(multi, x)
    ...
    after_time=time.perf_counter()
    print(f'{round((after_time - befor_time) * 1000, 2)}')

それでは計測を始めましょう

検証

対象が1人の場合

処理結果を検証します。

経過時間を500サンプルとり、これらの平均・標準偏差を計算しました。

実行中のウィンドウ
  1. 平均値:13.78ミリ秒
  2. 中央値:13.36ミリ秒
  3. 標準偏差:1.49

となりました。約0.014秒となります。

対象が2人の場合

顔認証の対象が2人に増えた場合の処理にかかる時間を計測してみます。

処理実行中のウィンドウ
  1. 平均値:14.45ミリ秒
  2. 中央値:14.18ミリ秒
  3. 標準偏差:1.05

こちらも約14ミリ秒でした。(0.014秒)

まとめ

FACE01 GRAPHICSの古いバージョンでは約0.03秒でした。現在(2021年8月)の最新バージョンでは0.01秒ですからタイムが縮んでよかったです。