GithubHelp home page GithubHelp logo

kazuhito00 / single-hand-localization Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 1.0 62.17 MB

単一の手の位置推定を行う試験的なモデルです。手のXY座標とクラス分類結果(無し、パー、グー)の出力を行います。

License: Apache License 2.0

Python 2.32% Jupyter Notebook 97.68%
tensorflow onnx tensorflow-lite keras hand localization raspberry-pi mobilenet efficientnet

single-hand-localization's Introduction

Single-Hand-Localization

単一の手の位置推定を行う試験的なモデルです。
→Raspberry PiやUnity Barracuda上で動作する軽量なモデルを目指しています
手のXY座標とクラス分類結果(無し、パー、グー)の出力を行います。

 
左図:PC実行 EfficientNet版 ONNXモデル
右図:Raspberry pi4実行 MobileNet v1版 TensorFlow-Liteモデル

MobileNet v1版はUnity Barracuda上でも動作します。
興味のある方はUnity-Barracuda-SingleHandLocalization-WebGLを確認ください。

Requrement

  • mediapipe 0.8.1 or later ※01_create_dataset.pyを利用する場合のみ
  • Tensorflow 2.4.0 or later
  • OpenCV 3.4.2 or Later
  • onnxruntime 1.5.2 or later ※03_onnx_inference_sample.pyを利用する場合のみ

Demo

Webカメラを使ったデモの実行方法は以下です。
TensorFlow Kerasモデル、TensorFlow-Liteモデル、ONNXモデルそれぞれのサンプルがあります。
背景が無地のほうが検出しやすいです。

python 03_tf_keras_inference_sample.py
python 03_tflite_inference_sample.py
python 03_onnx_inference_sample.py

デモ実行時には、以下のオプションが指定可能です。

  • --device
    カメラデバイス番号の指定 (デフォルト:0)
  • --width
    カメラキャプチャ時の横幅 (デフォルト:960)
  • --height
    カメラキャプチャ時の縦幅 (デフォルト:540)
  • --model
    ロード対象のモデル
    03_tf_keras_inference_sample.py:'02_model/EfficientNetB0/SingleHandLocalization_224.hdf5'
    03_tflite_inference_sample.py:'02_model/EfficientNetB0/SingleHandLocalization_224.tflite'
    03_onnx_inference_sample.py:'02_model/EfficientNetB0/SingleHandLocalization_224.onnx'
  • --input_shape
    モデル入力画像の一辺のサイズ (デフォルト:224)

Directory

│  01_create_dataset.py
│  02_train_model(MobileNetV1).ipynb
│  03_tf_keras_inference_sample.py
│  03_tflite_inference_sample.py
│  03_onnx_inference_sample.py
│  
├─01_dataset
│  
├─02_model
│  ├─EfficientNetB0
│  │  │  SingleHandLocalization_224.hdf5
│  │  │  SingleHandLocalization_224.onnx
│  │  └─ SingleHandLocalization_224.tflite
│  │          
│  └─MobileNetV1
│      │  SingleHandLocalization_1.0_128.hdf5
│      │  SingleHandLocalization_1.0_128.onnx
│      └─ SingleHandLocalization_1.0_128.tflite
│          
└─utils
    └─cvfpscalc.py
ディレクトリ内容

01_create_dataset.py

データセット作成用のスクリプトです。
データセットは01_datasetディレクトリに保存します。

02_train_model(MobileNetV1).ipynb

モデル訓練用のスクリプトです。
Google Colaboratory上での実行を想定しています。

03_tf_keras_inference_sample.py, 03_tflite_inference_sample.py, 03_onnx_inference_sample.py

推論サンプルです。

01_dataset

01_create_dataset.pyによって作成したデータセットを格納するディレクトリです。
顔出しNGの方のデータがあるため、今回モデル訓練に使用したデータセットは非公開です。

02_model

訓練済みのモデルを格納しているディレクトリです。
EfficientNet-B0ベース(入力サイズ224224)とMobileNet v1ベース(128128)のモデルを格納しています。

utils

FPS計測用のモジュールを格納しています。

Dataset

顔出しNGの方の写真も利用しているため、データセットは非公開です。
今回訓練に使用したデータ総数は以下の通りです。
 総数:65405枚
 クラスID 0(手無し):7824
 クラスID 1(パー):28605
 クラスID 2(グー):28976

mediapipeを利用したデータセットを収集するスクリプト(01_create_dataset.py)は公開しています。

Model

モデル構造は以下の通りです。

ToDo

  • FlattenをGlobal Average Poolingに差し替える

Author

高橋かずひと(https://twitter.com/KzhtTkhs)

License

Single-Hand-Localization is under Apache v2 License.

single-hand-localization's People

Contributors

kazuhito00 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

zhuomingliang

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.