DEV Community

Cover image for Custom Human Pose Classification using Mediapipe
NASEEM A P
NASEEM A P

Posted on

Custom Human Pose Classification using Mediapipe

Creating a Custom pose classification using Mediapipe with help of OpenCV
GitHub: CustomPose-Classification-Mediapipe

Sample OutPut

Video

Video Output

Image

Image Output

Demo

I am going to create a Custom Human pose classification using Yoga Pose Dataset.

1. Clone the Repository:

git clone https://github.com/naseemap47/CustomPose-Classification-Mediapipe.git
cd CustomPose-Classification-Mediapipe
Enter fullscreen mode Exit fullscreen mode

Install Dependency

pip3 install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Download Dataset:

wget -O yoga_poses.zip http://download.tensorflow.org/data/pose_classification/yoga_poses.zip
Enter fullscreen mode Exit fullscreen mode

About Dataset:

  • 5 Classes: Chair, Cobra, Dog, Tree and Warrior
  • Contain Train and Test data
  • Combine both Train and Test data
├── Dataset
│   ├── Chair
│   │   ├── 1.jpg
│   │   ├── 2.jpg
│   │   ├── ...
│   ├── Cobra
│   │   ├── 1.jpg
│   │   ├── 2.jpg
│   │   ├── ...
.   .
.   .
Enter fullscreen mode Exit fullscreen mode

2. Create Landmark Dataset for each Classes

  • -i , --dataset __ Path to Dataset
  • -o , --save __ Path to save CSV file
python3 poseLandmark_csv.py -i data/ -o data.csv
Enter fullscreen mode Exit fullscreen mode

CSV file will be saved in <path_to_save_csv>

3. Create DeepLearinng Model to predict Human Pose

  • -i , --dataset __ Path to CSV Data
  • -o , --save __ Path to save model.h5 file
python3 poseModel.py -i data.csv -o model.h5
Enter fullscreen mode Exit fullscreen mode

Model will saved in <path_to_save_model> and Model Metrics saved in metrics.png

4. Inference

Show Predicted Pose Class on Test Image or Video or Web-cam

  • -m , --model __ Path to saved model.h5
  • -c , --conf __ Min prediction conf to detect pose class (0<conf<1)
  • -i , --source __ Path to Image or Video, for webcam use Zero(0)
  • --save __ It will save Images (on ImageOutput Dir) or Videos (“output.avi”)
# Image
python3 inference.py --model model.h5 --conf 0.75 --source data/test/image.jpg
# Video
python3 inference.py --model model.h5 --conf 0.75 --source data/test/video.mp4
# web-cam
python3 inference.py --model model.h5 --conf 0.75 --source 0
###### to save ######
# Image
python3 inference.py --model model.h5 --conf 0.75 --source data/test/image.jpg --save
# Video
python3 inference.py --model model.h5 --conf 0.75 --source data/test/video.mp4 --save
# web-cam
python3 inference.py --model model.h5 --conf 0.75 --source 0 --save
Enter fullscreen mode Exit fullscreen mode

To Exit Window — Press Q-key

Custom Pose Classification

Clone this Repository:

git clone https://github.com/naseemap47/CustomPose-Classification-Mediapipe.git
cd CustomPose-Classification-Mediapipe
git checkout custom
Enter fullscreen mode Exit fullscreen mode

1. Take your Custom Pose Dataset

Example:

├── Dataset
│   ├── Pose_1
│   │   ├── 1.jpg
│   │   ├── 2.jpg
│   │   ├── ...
│   ├── Pose_2
│   │   ├── 1.jpg
│   │   ├── 2.jpg
│   │   ├── ...
.   .
.   .
Enter fullscreen mode Exit fullscreen mode

2. Create Landmark Dataset for each Classes

  • -i , --dataset __ Path to Dataset
  • -o , --save __ Path to save CSV file
python3 poseLandmark_csv.py -i <path_to_data_dir> -o <path_to_save_csv>
Enter fullscreen mode Exit fullscreen mode

CSV file will be saved in <path_to_save_csv>

3. Create DeepLearinng Model to predict Human Pose

  • -i , --dataset __ Path to CSV Data
  • -o , --save __ Path to save model.h5 file
python3 poseModel.py -i <path_to_save_csv> -o <path_to_save_model>
Enter fullscreen mode Exit fullscreen mode

Model will saved in <path_to_save_model> and Model Metrics saved in metrics.png

4. Inference

Open inference.py
change Line-43: According to your Class Names, Write Class Order

Show Predicted Pose Class on Test Image or Video or Web-cam

  • -m , --model __ Path to saved model.h5
  • -c , --conf __ Min prediction conf to detect pose class (0<conf<1)
  • -i , --source __ Path to Image or Video, for webcam use Zero(0)
  • --save __ It will save Images (on ImageOutput Dir) or Videos (“output.avi”)
python3 inference.py --model <path_to_model> --conf <model_prediction_confidence> --source <image or video or web-cam>
# to save
python3 inference.py --model <path_to_model> --conf <model_prediction_confidence> --source <image or video or web-cam> --save
Enter fullscreen mode Exit fullscreen mode

Show Predicted Pose Class on Test Image or Video or Web-cam

To Exit Window — Press Q-key

Thank You…

Top comments (0)