[Japanese/ English ] Note キ?ポイント分類について、モデルを集めたリポジトリを作成しました。 → Kazuhito00/hand-keypoint-classification-model-zoo hand-gesture-recognition-using-mediapipe MediaPipe(Python版)を用いて手の姿勢推定を行い、?出したキ?ポイントを用いて、 簡易なMLPでハンドサインとフィンガ?ジェスチャ?を認識するサンプルプログラムです。 本リポジトリは以下の?容を含みます。 サンプルプログラム ハンドサイン認識モデル(TFLite) フィンガ?ジェスチャ?認識モデル(TFLite) ハンドサイン認識用?習デ?タ、および、?習用ノ?トブック フィンガ?ジェスチャ?認識用?習デ?タ、および、?習用ノ?トブック Requirements mediapipe 0.8.4 OpenCV 4.6.0.66 or Later Tensorflow 2.9.0 or Later protobuf <3.20,>=3.9.2 scikit-learn 1.0.2 or Later (?習時に混同行列を表示したい場合のみ) matplotlib 3.5.1 or Later (?習時に混同行列を表示したい場合のみ) Demo Webカメラを使ったデモの?行方法は以下です。 python app.py DockerとWebカメラを使ったデモの?行方法は以下です。 docker build -t hand_gesture . xhost +local: && \ docker run --rm -it \ --device /dev/video0:/dev/video0 \ -v ` pwd ` :/home/user/workdir \ -v /tmp/.X11-unix/:/tmp/.X11-unix:rw \ -e DISPLAY= $DISPLAY \ hand_gesture:latest python app.py デモ?行時には、以下のオプションが指定可能です。 --device カメラデバイス番?の指定 (デフォルト:0) --width カメラキャプチャ時の?幅 (デフォルト:960) --height カメラキャプチャ時の?幅 (デフォルト:540) --use_static_image_mode MediaPipeの推論にstatic_image_modeを利用するか否か (デフォルト:未指定) --min_detection_confidence ?出信?値の?値 (デフォルト:0.5) --min_tracking_confidence トラッキング信?値の?値 (デフォルト:0.5) Directory │ app.py │ keypoint_classification.ipynb │ point_history_classification.ipynb │ ├─model │ ├─keypoint_classifier │ │ │ keypoint.csv │ │ │ keypoint_classifier.hdf5 │ │ │ keypoint_classifier.py │ │ │ keypoint_classifier.tflite │ │ └─ keypoint_classifier_label.csv │ │ │ └─point_history_classifier │ │ point_history.csv │ │ point_history_classifier.hdf5 │ │ point_history_classifier.py │ │ point_history_classifier.tflite │ └─ point_history_classifier_label.csv │ └─utils └─cvfpscalc.py app.py 推論用のサンプルプログラムです。 また、ハンドサイン認識用の?習デ?タ(キ?ポイント)、 フィンガ?ジェスチャ?認識用の?習デ?タ(人差指の座標履?)を?集することもできます。 keypoint_classification.ipynb ハンドサイン認識用のモデル訓練用スクリプトです。 point_history_classification.ipynb フィンガ?ジェスチャ?認識用のモデル訓練用スクリプトです。 model/keypoint_classifier ハンドサイン認識に?わるファイルを格納するディレクトリです。 以下のファイルが格納されます。 ?習用デ?タ(keypoint.csv) ?習?モデル(keypoint_classifier.tflite) ラベルデ?タ(keypoint_classifier_label.csv) 推論用クラス(keypoint_classifier.py) model/point_history_classifier フィンガ?ジェスチャ?認識に?わるファイルを格納するディレクトリです。 以下のファイルが格納されます。 ?習用デ?タ(point_history.csv) ?習?モデル(point_history_classifier.tflite) ラベルデ?タ(point_history_classifier_label.csv) 推論用クラス(point_history_classifier.py) utils/cvfpscalc.py FPS計測用のモジュ?ルです。 Training ハンドサイン認識、フィンガ?ジェスチャ?認識は、 ?習デ?タの追加、?更、モデルの再トレ?ニングが出?ます。 ハンドサイン認識トレ?ニング方法 1.?習デ?タ?集 「k」を押すと、キ?ポイントの保存するモ?ドになります(「MODE:Logging Key Point」と表示される) 「0」~「9」を押すと「model/keypoint_classifier/keypoint.csv」に以下のようにキ?ポイントが追記されます。 1列目:押下した?字(クラスIDとして使用)、2列目以降:キ?ポイント座標 キ?ポイント座標は以下の前?理を④まで?施したものを保存します。 初期?態では、パ?(クラスID:0)、グ?(クラスID:1)、指差し(クラスID:2)の3種類の?習デ?タが入っています。 必要に?じて3以降を追加したり、csvの?存デ?タを削除して、?習デ?タを用意してください。 2.モデル訓練 「 keypoint_classification.ipynb 」をJupyter Notebookで開いて上から順に?行してください。 ?習デ?タのクラス?を?更する場合は「NUM_CLASSES = 3」の値を?更し、 「model/keypoint_classifier/keypoint_classifier_label.csv」のラベルを適宜修正してください。 X.モデル構造 「 keypoint_classification.ipynb 」で用意しているモデルのイメ?ジは以下です。 フィンガ?ジェスチャ?認識トレ?ニング方法 1.?習デ?タ?集 「h」を押すと、指先座標の履?を保存するモ?ドになります(「MODE:Logging Point History」と表示される) 「0」~「9」を押すと「model/point_history_classifier/point_history.csv」に以下のようにキ?ポイントが追記されます。 1列目:押下した?字(クラスIDとして使用)、2列目以降:座標履? キ?ポイント座標は以下の前?理を④まで?施したものを保存します。 初期?態では、?止(クラスID:0)、時計回り(クラスID:1)、反時計回り(クラスID:2)、移動(クラスID:4)の 4種類の?習デ?タが入っています。 必要に?じて5以降を追加したり、csvの?存デ?タを削除して、?習デ?タを用意してください。 2.モデル訓練 「 point_history_classification.ipynb 」をJupyter Notebookで開いて上から順に?行してください。 ?習デ?タのクラス?を?更する場合は「NUM_CLASSES = 4」の値を?更し、 「model/point_history_classifier/point_history_classifier_label.csv」のラベルを適宜修正してください。 X.モデル構造 「 point_history_classification.ipynb 」で用意しているモデルのイメ?ジは以下です。 「LSTM」を用いたモデルは以下です。 使用する際には「use_lstm = False」を「True」に?更してください(要tf-nightly(2020/12/16時点)) Application example 以下に?用事例を紹介します。 Control DJI Tello drone with Hand gestures Classifying American Sign Language Alphabets on the OAK-D Reference MediaPipe Kazuhito00/mediapipe-python-sample Author 高橋かずひと( https://twitter.com/KzhtTkhs ) License hand-gesture-recognition-using-mediapipe is under Apache v2 license .