Skip to content
Projetos

Kazuhito00/mediapipe-python-sample

Ver no GitHub

Sobre

Exemplos do pacote Python do MediaPipe. Abrange 15 recursos com implementação em Python em 1º de setembro de 2024.

Outros projetos

Como estes números são medidos

Crescimento medido de estrelas

em 24 h
0
em 7 dias
+1
em 15 dias
0
em 1 mês
Coletando histórico

Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.

README.md

Original

[!IMPORTANT] MediaPipe レガシーソリューションのサポートは、2023年3月1日で終了しています。
従来のソリューションのサンプルは _legacyディレクトリに移動しました。
MediaPipeは後方互換を保っており、現パッケージでもレガシーソリューションのサンプルを実行出来ます。

mediapipe-python-sample

google-ai-edge/mediapipeのPythonパッケージのサンプルスクリプト集です。
2024/9/1時点でPython実装のある以下15機能について用意しています。

Requirement

  • mediapipe 0.10.14 or later
  • opencv-python 4.10.0.84 or later
  • tqdm 4.66.5 or later ※重みファイルダウンロードに使用
  • requests 2.32.3 or later ※重みファイルダウンロードに使用
  • scipy 1.14.1 or later ※音分類(Audio Classification)サンプルを実行する場合のみ
  • numpy 1.26.4 ※NumPyは1.x系
pip install -r requirements.txt

Demo

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

物体検出(Object Detection)

python sample_object_detection.py
コマンドライン引数オプション
  • --device
    カメラデバイス番号の指定
    デフォルト:0
  • --video
    動画パスの指定 ※指定時はカメラより優先
    デフォルト:None
  • --width
    カメラキャプチャ時の横幅
    デフォルト:960
  • --height
    カメラキャプチャ時の縦幅
    デフォルト:540
  • --model
    使用モデル[0, 1, 2, 3, 4, 5, 6, 7] ※対象モデルの重みがmodelディレクトリ内に無い場合ダウンロードを実行
    COCOデータセットでトレーニングされた重みで、サポートされているラベルはlabelmap.txt
    デフォルト:0
    • 0:EfficientDet-Lite0(int8)
    • 1:EfficientDet-Lite0(float 16)
    • 2:EfficientDet-Lite0(float 32)
    • 3:EfficientDet-Lite2(int8)
    • 4:EfficientDet-Lite2(float 16)
    • 5:EfficientDet-Lite2float 32)
    • 6:SSDMobileNet-V2(int8)
    • 7:SSDMobileNet-V2(float 32)
  • --score_threshold
    スコア閾値
    デフォルト:0.5

画像分類(Image Classification)

python sample_image_classification.py
コマンドライン引数オプション
  • --device
    カメラデバイス番号の指定
    デフォルト:0
  • --video
    動画パスの指定 ※指定時はカメラより優先
    デフォルト:None
  • --width
    カメラキャプチャ時の横幅
    デフォルト:960
  • --height
    カメラキャプチャ時の縦幅
    デフォルト:540
  • --model
    使用モデル[0, 1, 2, 3] ※対象モデルの重みがmodelディレクトリ内に無い場合ダウンロードを実行
    ImageNetでトレーニングされた重みで、サポートされているラベルはlabels.txt
    デフォルト:0
    • 0:EfficientNet-Lite0(int8)
    • 1:EfficientNet-Lite0(float 32)
    • 2:EfficientNet-Lite2(int8)
    • 3:EfficientNet-Lite2(float 32)
  • --max_results
    結果出力数
    デフォルト:5

画像セグメンテーション(Image Segmentation)

python sample_image_segmentation.py
コマンドライン引数オプション
  • --device
    カメラデバイス番号の指定
    デフォルト:0
  • --video
    動画パスの指定 ※指定時はカメラより優先
    デフォルト:None
  • --width
    カメラキャプチャ時の横幅
    デフォルト:960
  • --height
    カメラキャプチャ時の縦幅
    デフォルト:540
  • --model
    使用モデル[0, 1, 2, 3, 4] ※対象モデルの重みがmodelディレクトリ内に無い場合ダウンロードを実行
    デフォルト:0
    • 0:SelfieSegmenter(square)
    • 1:SelfieSegmenter(landscape)
    • 2:HairSegmenter
    • 3:SelfieMulticlass(256x256)
    • 4:DeepLab-V3

インタラクティブ セグメンテーション(Interactive segmentation)

python sample_interactive_image_segmentation.py
コマンドライン引数オプション
  • --image
    画像パスの指定
    デフォルト:asset/hedgehog01.jpg
  • --model
    使用モデル[0] ※対象モデルの重みがmodelディレクトリ内に無い場合ダウンロードを実行
    デフォルト:0
    • 0:MagicTouch

手検出(Hand Landmark detection)

python sample_hand_landmarks_detection.py
コマンドライン引数オプション
  • --device
    カメラデバイス番号の指定
    デフォルト:0
  • --video
    動画パスの指定 ※指定時はカメラより優先
    デフォルト:None
  • --width
    カメラキャプチャ時の横幅
    デフォルト:960
  • --height
    カメラキャプチャ時の縦幅
    デフォルト:540
  • --unuse_mirror
    ミラー表示不使用
    デフォルト:指定なし
  • --model
    使用モデル[0] ※対象モデルの重みがmodelディレクトリ内に無い場合ダウンロードを実行
    デフォルト:0
    • 0:HandLandmarker (full)
  • --num_hands
    検出数
    デフォルト:2
  • --use_world_landmark
    ワールド座標表示
    デフォルト:指定なし

手のジェスチャー認識(Gesture Recognition)

python sample_hand_gesture_recognition.py
コマンドライン引数オプション
  • --device
    カメラデバイス番号の指定
    デフォルト:0
  • --video
    動画パスの指定 ※指定時はカメラより優先
    デフォルト:None
  • --width
    カメラキャプチャ時の横幅
    デフォルト:960
  • --height
    カメラキャプチャ時の縦幅
    デフォルト:540
  • --unuse_mirror
    ミラー表示不使用
    デフォルト:指定なし
  • --model
    使用モデル[0] ※対象モデルの重みがmodelディレクトリ内に無い場合ダウンロードを実行
    認識ジェスチャーは「Closed fist」「Open palm」「Pointing up」「Thumbs down」「Thumbs up」「Victory」「Love」「Unknown」
    デフォルト:0
    • 0:HandGestureClassifier

画像の埋め込み表現(Image Embedding)

python sample_image_embedding.py
コマンドライン引数オプション
  • --image01
    画像パス1の指定
    デフォルト:asset/hedgehog01.jpg
  • --image02
    画像パス2の指定
    デフォルト:asset/hedgehog02.jpg
  • --model
    使用モデル[0, 1] ※対象モデルの重みがmodelディレクトリ内に無い場合ダウンロードを実行
    デフォルト:0
    • 0:MobileNet-V3 (small)
    • 1:MobileNet-V3 (large)
  • --unuse_l2_normalize
    特徴ベクトルを L2 ノルムで正規化しない
    デフォルト:指定なし
  • --unuse_quantize
    特徴ベクトルを スカラー量子化によってバイトに量子化しない
    デフォルト:指定なし




顔検出(Face Detection)

python sample_face_detection.py
コマンドライン引数オプション
  • --device
    カメラデバイス番号の指定
    デフォルト:0
  • --video
    動画パスの指定 ※指定時はカメラより優先
    デフォルト:None
  • --width
    カメラキャプチャ時の横幅
    デフォルト:960
  • --height
    カメラキャプチャ時の縦幅
    デフォルト:540
  • --model
    使用モデル[0] ※対象モデルの重みがmodelディレクトリ内に無い場合ダウンロードを実行
    デフォルト:0
    • 0:BlazeFace (short-range)

顔のランドマーク検出(Face Landmark Detection)

python sample_face_landmark_detection.py
コマンドライン引数オプション
  • --device
    カメラデバイス番号の指定
    デフォルト:0
  • --video
    動画パスの指定 ※指定時はカメラより優先
    デフォルト:None
  • --width
    カメラキャプチャ時の横幅
    デフォルト:960
  • --height
    カメラキャプチャ時の縦幅
    デフォルト:540
  • --model
    使用モデル[0] ※対象モデルの重みがmodelディレクトリ内に無い場合ダウンロードを実行
    デフォルト:0
    • 0:FaceLandscapeer
  • --num_faces
    検出数
    デフォルト:1
  • --unuse_output_face_blendshapes
    顔のブレンドシェイプを出力しない
    デフォルト:指定なし
  • --unuse_output_facial_transformation_matrixes
    顔変換行列を出力しない
    デフォルト:指定なし

顔のスタイル変換(Face Stylization)

python sample_face_stylization.py
コマンドライン引数オプション
  • --device
    カメラデバイス番号の指定
    デフォルト:0
  • --video
    動画パスの指定 ※指定時はカメラより優先
    デフォルト:None
  • --width
    カメラキャプチャ時の横幅
    デフォルト:960
  • --height
    カメラキャプチャ時の縦幅
    デフォルト:540
  • --model
    使用モデル[0, 1, 2] ※対象モデルの重みがmodelディレクトリ内に無い場合ダウンロードを実行
    デフォルト:0
    • 0:Color sketch
    • 1:Color ink
    • 2:Oil painting

姿勢推定(Pose Landmark Detection)

python sample_pose_landmark_detection.py
コマンドライン引数オプション
  • --device
    カメラデバイス番号の指定
    デフォルト:0
  • --video
    動画パスの指定 ※指定時はカメラより優先
    デフォルト:None
  • --width
    カメラキャプチャ時の横幅
    デフォルト:960
  • --height
    カメラキャプチャ時の縦幅
    デフォルト:540
  • --unuse_mirror
    ミラー表示不使用
    デフォルト:指定なし
  • --model
    使用モデル[0, 1, 2] ※対象モデルの重みがmodelディレクトリ内に無い場合ダウンロードを実行
    デフォルト:0
    • 0:Pose landmarker(lite)
    • 1:Pose landmarker(Full)
    • 2:Pose landmarker(Heavy)
  • --use_output_segmentation_masks
    セグメンテーションを実施
    デフォルト:指定なし
  • --use_world_landmark
    ワールド座標表示を実施
    デフォルト:指定なし

テキスト分類(Text Classification)

python sample_text_classification.py
コマンドライン引数オプション
  • --input_text
    入力テキスト
    デフォルト:I'm looking forward to what will come next.
  • --model
    使用モデル[0, 1] ※対象モデルの重みがmodelディレクトリ内に無い場合ダウンロードを実行
    デフォルト:0
    • 0:BERT-classifier
    • 1:Average word embedding

テキストの埋め込み表現(Text Embedding)

python sample_text_embedding.py
コマンドライン引数オプション
  • --input_text01
    入力テキスト1
    デフォルト:I'm feeling so good
  • --input_text02
    入力テキスト2
    デフォルト:I'm okay I guess
  • --model
    使用モデル[0] ※対象モデルの重みがmodelディレクトリ内に無い場合ダウンロードを実行
    デフォルト:0
    • 0:Universal Sentence Encoder
  • --unuse_l2_normalize
    特徴ベクトルを L2 ノルムで正規化しない
    デフォルト:指定なし
  • --use_quantize
    特徴ベクトルを スカラー量子化によってバイトに量子化する
    デフォルト:指定なし

テキスト言語分類(Language Detector)

python sample_text_language_detection.py
コマンドライン引数オプション
  • --input_text
    入力テキスト
    デフォルト:分久必合合久必分
  • --model
    使用モデル[0, 1] ※対象モデルの重みがmodelディレクトリ内に無い場合ダウンロードを実行
    デフォルト:0
    • 0:Language Detector

音分類(Audio Classification)

python sample_audio_classification.py
コマンドライン引数オプション
  • --input_audio
    入力音声ファイルのパス
    デフォルト:asset/hyakuninisshu_02.wav
  • --model
    使用モデル[0] ※対象モデルの重みがmodelディレクトリ内に無い場合ダウンロードを実行
    デフォルト:0
    • 0:YamNet
  • --max_results
    結果出力数
    デフォルト:5

Reference

Author

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

License

mediapipe-python-sample is under Apache-2.0 License.

License(Image, Video, Audio)

サンプル実行用に格納している画像などは以下を利用しています。

Explore projetos relacionados

Carregando…