Code Monkey home page Code Monkey logo

kazuhito00 / naruto-handsigndetection Goto Github PK

View Code? Open in Web Editor NEW
227.0 5.0 24.0 102.24 MB

物体検出を用いてNARUTOの印(子~亥、壬、合掌)を検出するモデルとサンプルプログラムです。このリポジトリでは、YOLOXを使用しています(This is a model and sample program that detects NARUTO's hand sign using object detection. This repository use YOLOX.)

License: MIT License

Python 88.25% Shell 11.75%
tensorflow2 object-detection opencv handsign naruto efficientdet mobilenetv2-ssd deep-learning deep-neural-networks tensorflow-lite naruto-handsigndetection

naruto-handsigndetection's Introduction

[Japanese/English]


NARUTO-HandSignDetection

物体検出を用いてNARUTOの印を検出するモデルとサンプルプログラムです。

 

右図:© NARUTO -ナルト- 9話『写輪眼のカカシ』岸本斉史作/集英社/studioぴえろ
日本の著作権法 第二十条「同一性保持権」1における「改変」に相当する可能性があるため、
 右図にはバウンディングボックスのオーバーレイ表示は行っておりません。


Title

Deep写輪眼:オブジェクト検出 YOLOX を用いた NARUTO の印認識

Abstract

このリポジトリは、NARUTO2 の印を認識するための訓練済みモデルとサンプルプログラムを公開しています。

忍術の発動は、一部の忍術をのぞき手で印を結ぶことが必要です。
また、性質変化は印に特徴が現れるため(火遁→寅の印、土遁→亥の印など)、
印を素早く認識することが出来れば、忍同士の戦闘においてアドバンテージを得ることが出来ます。
印の認識にはディープラーニングの物体検出モデルの一つYOLOX-Nanoを使用することで、
前回バージョンのDeep写輪眼(EfficientDet-D0利用)よりも推論速度を大幅にアップしました。

Requirements

  • onnxruntime 1.10.0 or Later
  • OpenCV 3.4.2 or Later
  • Pillow 6.1.0 or Later (Ninjutsu_demo.pyを動かす場合のみ)
  • Tensorflow 2.3.0 or Later (SSD、EfficientDetを動かす場合、あるいは後処理をONNXへマージするときのみ)

DataSet

データセットについて

データセットは非公開です(訓練済みのモデルは公開します)
日本の著作権法 第四十七条の七「複製権の制限により作成された複製物の譲渡」3に準拠

また、自分で撮影した画像、アニメ画像の他に、naruto-hand-sign-dataset4を利用しています。

お願い事項

データセットはネット上で収集した画像と、自前で撮影した画像で構成されているため、
背景色や服装によっては検出精度が落ちたり、誤検出する可能性があります。
Issueで誤検出した条件を教えていただると助かります。
可能であれば、誤検出する条件の画像(子~亥、壬、合掌)をいただけると大変助かります。
その際、いただいた画像は学習データセットに追加してモデルの再訓練に使用します。

印の種類

14種類(子~亥、壬、合掌)の印に対応しています。

子(Ne/Rat) 丑(Ushi/Ox) 寅(Tora/Tiger) 卯(U/Hare)
辰(Tatsu/Dragon) 巳(Mi/Snake) 午(Uma/Horse) 未(Hitsuji/Ram)
申(Saru/Monkey) 酉(Tori/Bird) 戌(Inu/Dog) 亥(I/Boar)
壬(Mizunoe) 合掌(Gassho/Hand Claps) - -

データセットの枚数

総枚数:10026(内アニメ画像:2651枚)
タグ付き枚数:7098枚
タグ無し枚数:2928枚
アノテーションボックス数:8941個
 

Trained Model

訓練済みモデルをmodelディレクトリ配下で公開しています。 ※旧バージョンのモデルは「_legacy」ディレクトリに移動

  • YOLOX-Nano

Directory

│  simple_demo.py
│  Ninjutsu_demo.py
│
├─model
│  └─yolox
│      │ yolox_nano.onnx
│      └─yolox_onnx.py
│
├─post_process_gen_tools
│      │ convert_script.sh
│      │ make_box_gather_nd.py
│      │ make_boxes_scores.py
│      │ make_cxcywh_y1x1y2x2.py
│      │ make_final_batch_nums_final_class_nums_final_box_nums.py
│      │ make_grids.py
│      │ make_input_output_shape_update.py
│      │ make_nms_outputs_merge.py
│      └─make_score_gather_nd.py
│
├─setting─┬─labels.csv
│         └─jutsu.csv
│
├─utils
│
└─_legacy

simple_demo.py

 シンプルな検出デモです。
 

Ninjutsu_demo.py

 忍術判定のデモです。
 印の履歴から術データ(jutsu.csv)にマッチする術名を表示します。
   

model

 訓練済みモデルを格納しています。

post_process_gen_tools

 ONNXにすべての後処理をマージするスクリプト群を格納しています。

setting

 ラベルデータ(labels.csv)と術名データ(jutsu.csv)を格納しています。

  • labels.csv
    印のラベル名を保持しています。
    • A列:英語の印
    • B列:日本語の印
  • jutsu.csv
    術名と必要印を保持しています。
    • A列:日本語の術種別(火遁等)
    • B列:英語の術種別(火遁等)
    • C列:日本語の術名
    • D列:英語の術名
    • E列以降:術の発動に必要な印

utils

 FPS計測用モジュール(cvfpscalc.py)と文字列描画用モジュール(cvdrawtext.py)を格納しています。
 Ninjutsu_demo.pyのみで使用します。

Usage

デモの実行方法は以下です。

python simple_demo.py
python simple_demo_without_post.py
python Ninjutsu_demo.py

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

オプション指定
  • --device
    カメラデバイス番号の指定
    デフォルト:
    • simple_demo.py:0
    • Ninjutsu_demo.py:0
  • --file
    動画ファイル名の指定 ※指定時はカメラデバイスより優先し動画を読み込む
    デフォルト:
    • simple_demo.py:None
    • Ninjutsu_demo.py:None
  • --fps
    処理FPS ※推論時間がFPSを下回る場合のみ有効
    デフォルト:
    • simple_demo.py:30
    • Ninjutsu_demo.py:30
  • --width
    カメラキャプチャ時の横幅
    デフォルト:
    • simple_demo.py:960
    • Ninjutsu_demo.py:960
  • --height
    カメラキャプチャ時の縦幅
    デフォルト:
    • simple_demo.py:540
    • Ninjutsu_demo.py:540
  • --skip_frame
    カメラ or 動画読み込み時に何枚おきに処理を実行するか
    デフォルト:
    • simple_demo.py:0
    • Ninjutsu_demo.py:0
  • --model
    ロードするモデルの格納パス
    デフォルト:
    • simple_demo.py:model/yolox/yolox_nano.onnx
    • Ninjutsu_demo.py:model/yolox/yolox_nano.onnx
  • --input_shape
    モデルの入力サイズ
    デフォルト:
    • simple_demo.py:416,416
    • Ninjutsu_demo.py:416,416
  • --score_th
    クラス判別の閾値
    デフォルト:
    • simple_demo.py:0.7
    • Ninjutsu_demo.py:0.7
  • --nms_th
    NMSの閾値
    デフォルト:
    • simple_demo.py:0.45
    • Ninjutsu_demo.py:0.45
  • --nms_score_th
    NMSのスコア閾値
    デフォルト:
    • simple_demo.py:0.1
    • Ninjutsu_demo.py:0.1
  • --sign_interval
    前回の印検出時から指定時間(秒)経過すると印の履歴をクリア
    デフォルト:
    • Ninjutsu_demo.py:2.0
  • --jutsu_display_time
    術成立時に術名を表示する時間(秒)
    デフォルト:
    • Ninjutsu_demo.py:5
  • --use_display_score
    印検出スコアを表示するか否か
    デフォルト:
    • Ninjutsu_demo.py:False
  • --erase_bbox
    バウンディングボックスのオーバーレイ表示を消去するか否か
    デフォルト:
    • Ninjutsu_demo.py:False
  • --use_jutsu_lang_en
    術名表示に英語表記を使用するか否か
    デフォルト:
    • Ninjutsu_demo.py:False
  • --chattering_check
    印を何回連続で検出したら印の成立とみなすか(印の検出チラつき対策)
    デフォルト:
    • Ninjutsu_demo.py:1
  • --use_fullscreen
    フルスクリーン表示を利用するか否か(試験的機能)
    デフォルト:
    • Ninjutsu_demo.py:False

Application Example

アプリケーションの応用事例を紹介します。

Acknowledgements

EfficientDetモデルトレーニング時は、からあげさんの説明記事5を参考にいたしました。
また、からあげさんのブログ6にて、Deep写輪眼をご紹介いただきました。
大変ありがとうございます。

YOLOXのトレーニングにはYOLOX-Colaboratory-Training-Sample7を使用しています。

References

  1. ^日本:著作権法 第二十条「同一性保持権」
  2. ^岸本斉史作『NARUTO』集英社、1999年-2014年
  3. ^日本:著作権法 四十七条の七「複製権の制限により作成された複製物の譲渡」
  4. ^Kaggle 公開データセット:naruto-hand-sign-dataset
  5. ^「Object Detection API」で物体検出の自前データを学習する方法(TensorFlow 2.x版)
  6. ^からあげさんのブログ:AIでNARUTO気分!「Deep写輪眼」で遊んでみよう
  7. ^Kazuhito00/YOLOX-Colaboratory-Training-Sample

Authors

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

License

NARUTO-HandSignDetection is under MIT license.

License(Font)

衡山毛筆フォント(https://opentype.jp/kouzanmouhitufont.htm)

naruto-handsigndetection's People

Contributors

karaage0703 avatar kazuhito00 avatar pinto0309 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

naruto-handsigndetection's Issues

Extract score and class_id

Hi @Kazuhito00 , finally I'm able to convert the model to tflite and with python it's working fine,
now I'm trying to do the same with java, so processing new model working fine but I'm not able to process the result

as result I have array like this :

index 0 : [1.4157819747924805, 2.1544673442840576, ...... ] : size = 7098

index 1 : [1.805556058883667, 1.946408987045288, ........ ] : size = 7098

index 2 : [1.0974576473236084, 1.980888843536377, ....... ] : size = 7098
..
...
index 20 : [0.0024664357770234, 0.007526415400207, ...... ] : size = 7098

I have try to convert the python code of method _postprocess to java but it's complex, can you please help to optimize this _postprocess method to only return score and class_id ? no need for bboxes

Thanks for your help !

Can't get it to work

Screenshot 2023-03-22 112454

d:/Documents/Projects/Uzumaki/NARUTO-HandSignDetection/simple_demo.py
Traceback (most recent call last):
File "d:\Documents\Projects\Uzumaki\NARUTO-HandSignDetection\simple_demo.py", line 162, in
main()

File "d:\Documents\Projects\Uzumaki\NARUTO-HandSignDetection\simple_demo.py", line 92, in main
yolox = YoloxONNX(

File "d:\Documents\Projects\Uzumaki\NARUTO-HandSignDetection\model\yolox\yolox_onnx.py", line 32, in init
self.onnx_session = onnxruntime.InferenceSession(

File "C:\Users\Yash\Envs\venv\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 360, in init
self._create_inference_session(providers, provider_options, disabled_optimizers)

File "C:\Users\Yash\Envs\venv\lib\site-packages\onnxruntime\capi\onnxruntime_inference_collection.py", line 397, in _create_inference_session
sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model)

onnxruntime.capi.onnxruntime_pybind11_state.NoSuchFile: [ONNXRuntimeError] : 3 : NO_SUCHFILE : Load model from model/yolox/yolox_nano.onnx failed:Load model model/yolox/yolox_nano.onnx failed. File doesn't exist

tflite model

thanks for this great project !!!
any idea how I can convert this Yolo model to tflite ? I have try some tools but not able to make it work ?

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.