Keras Realtime Multi-Person Pose Estimation - Keras version of Realtime Multi-Person Pose Estimation project

Overview

This repository has become incompatible with the latest and recommended version of Tensorflow 2.0 Instead of refactoring this code painfully, I created a new fresh repository with some additional features like:

  • Training code for smaller model based on MobilenetV2.

  • Visualisation of predictions (heatmaps, pafs) in Tensorboard.

  • Additional scripts to convert and test models for Tensorflow Lite.

Here is the link to the new repo: tensorflow_Realtime_Multi-Person_Pose_Estimation


Realtime Multi-Person Pose Estimation (DEPRECATED)

This is a keras version of Realtime Multi-Person Pose Estimation project

Introduction

Code repo for reproducing 2017 CVPR paper using keras.

This is a new improved version. The main objective was to remove dependency on separate c++ server which besides the complexity of compiling also contained some bugs... and was very slow. The old version utilizing rmpe_dataset_server is still available under the tag v0.1 if you really would like to take a look.

Results

 

Contents

  1. Converting caffe model
  2. Testing
  3. Training
  4. Changes

Require

  1. Keras
  2. Caffe - docker required if you would like to convert caffe model to keras model. You don't have to compile/install caffe on your local machine.

Converting Caffe model to Keras model

Authors of original implementation released already trained caffe model which you can use to extract weights data.

  • Download caffe model cd model; sh get_caffe_model.sh
  • Dump caffe layers to numpy data cd ..; docker run -v [absolute path to your keras_Realtime_Multi-Person_Pose_Estimation folder]:/workspace -it bvlc/caffe:cpu python dump_caffe_layers.py Note that docker accepts only absolute paths so you have to set the full path to the folder containing this project.
  • Convert caffe model (from numpy data) to keras model python caffe_to_keras.py

Testing steps

  • Convert caffe model to keras model or download already converted keras model https://www.dropbox.com/s/llpxd14is7gyj0z/model.h5
  • Run the notebook demo.ipynb.
  • python demo_image.py --image sample_images/ski.jpg to run the picture demo. Result will be stored in the file result.png. You can use any image file as an input.

Training steps

  • Install gsutil curl https://sdk.cloud.google.com | bash. This is a really helpful tool for downloading large datasets.
  • Download the data set (~25 GB) cd dataset; sh get_dataset.sh,
  • Download COCO official toolbox in dataset/coco/ .
  • cd coco/PythonAPI; sudo python setup.py install to install pycocotools.
  • Go to the "training" folder cd ../../../training.
  • Optionally, you can set the number of processes used to generate samples in parallel dataset.py -> find the line df = PrefetchDataZMQ(df, nr_proc=4)
  • Run the command in terminal python train_pose.py

Changes

25/06/2018

  • Performance improvement thanks to replacing c++ server rmpe_dataset_server with tensorpack dataflow. Tensorpack is a very efficient library for preprocessing and data loading for tensorflow models. Dataflow object behaves like a normal Python iterator but it can generate samples using many processes. This significantly reduces latency when GPU waits for the next sample to be processed.

  • Masks generated on the fly - no need to run separate scripts to generate masks. In fact most of the mask were only positive (nothing to mask out)

  • Masking out the discarded persons who are too close to the main person in the picture, so that the network never sees unlabelled people. Previously we filtered out keypoints of such smaller persons but they were still visible in the picture.

  • Incorrect handling of masks has been fixed. The rmpe_dataset_server sometimes assigned a wrong mask to the image, misleading the network.

26/10/2017

Fixed problem with the training procedure. Here are my results after training for 5 epochs = 25000 iterations (1 epoch is ~5000 batches) The loss values are quite similar as in the original training - output.txt

Results of running demo_image --image sample_images/ski.jpg --model training/weights.best.h5 with model trained only 25000 iterations. Not too bad !!! Training on my single 1070 GPU took around 10 hours.

22/10/2017

Augmented samples are fetched from the server. The network never sees the same image twice which was a problem in previous approach (tool rmpe_dataset_transformer) This allows you to run augmentation locally or on separate node. You can start 2 instances, one serving training set and a second one serving validation set (on different port if locally)

Related repository

Citation

Please cite the paper in your publications if it helps your research:

@InProceedings{cao2017realtime,
  title = {Realtime Multi-Person 2D Pose Estimation using Part Affinity Fields},
  author = {Zhe Cao and Tomas Simon and Shih-En Wei and Yaser Sheikh},
  booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
  year = {2017}
  }
Comments
  • Cannot create group in read only mode while loading model

    Cannot create group in read only mode while loading model

    I'm trying to load the model using load_model but it's giving me the following error in google colab.

    code

    from keras.models import load_model
    model = load_model('keras/model.h5')
    
    

    error

    ValueError                                Traceback (most recent call last)
    <ipython-input-48-a10a91d5d77d> in <module>()
          1 from keras.models import load_model
    ----> 2 model = load_model('keras/model.h5')
    
    /usr/local/lib/python3.6/dist-packages/keras/engine/saving.py in load_model(filepath, custom_objects, compile)
        417     f = h5dict(filepath, 'r')
        418     try:
    --> 419         model = _deserialize_model(f, custom_objects, compile)
        420     finally:
        421         if opened_new_file:
    
    /usr/local/lib/python3.6/dist-packages/keras/engine/saving.py in _deserialize_model(f, custom_objects, compile)
        219         return obj
        220 
    --> 221     model_config = f['model_config']
        222     if model_config is None:
        223         raise ValueError('No model found in config.')
    
    /usr/local/lib/python3.6/dist-packages/keras/utils/io_utils.py in __getitem__(self, attr)
        300             else:
        301                 if self.read_only:
    --> 302                     raise ValueError('Cannot create group in read only mode.')
        303                 val = H5Dict(self.data.create_group(attr))
        304         return val
    
    ValueError: Cannot create group in read only mode.
    

    Can someone please help me in understanding what is happening? How do I load this model?

    opened by cdebadri 11
  • ValueError: The channel dimension of the inputs should be defined. Found `None`.

    ValueError: The channel dimension of the inputs should be defined. Found `None`.

    Traceback (most recent call last):
      File "./demo_image.py", line 247, in <module>
        model = get_testing_model()
      File "/home/xy/share/reidPrj/keras_Realtime_Multi-Person_Pose_Estimation/model.py", line 184, in get_testing_model
        stage0_out = vgg_block(img_normalized, None)
      File "/home/xy/share/reidPrj/keras_Realtime_Multi-Person_Pose_Estimation/model.py", line 29, in vgg_block
        x = conv(x, 64, 3, "conv1_1", (weight_decay, 0))
      File "/home/xy/share/reidPrj/keras_Realtime_Multi-Person_Pose_Estimation/model.py", line 20, in conv
        bias_initializer=constant(0.0))(x)
      File "/home/wuyong/anaconda3/envs/tensorflow/lib/python3.5/site-packages/keras/engine/topology.py", line 528, in __call__
        self.build(input_shapes[0])
      File "/home/wuyong/anaconda3/envs/tensorflow/lib/python3.5/site-packages/keras/layers/convolutional.py", line 125, in build
        raise ValueError('The channel dimension of the inputs '
    ValueError: The channel dimension of the inputs should be defined. Found `None`.
    

    Seem like something wrong with img_input_shape. So I chance 177 line of model.py to this:

    img_input_shape = (None, None, 3) ==>
       img_input_shape = (674, 712, 3)
    

    Then new error occur:

    Traceback (most recent call last):
      File "./demo_image.py", line 247, in <module>
        model = get_testing_model()
      File "/home/xy/share/reidPrj/keras_Realtime_Multi-Person_Pose_Estimation/model.py", line 184, in get_testing_model
        stage0_out = vgg_block(img_normalized, None)
      File "/home/xy/share/reidPrj/keras_Realtime_Multi-Person_Pose_Estimation/model.py", line 40, in vgg_block
        x = pooling(x, 2, 2, "pool2_1")
      File "/home/xy/share/reidPrj/keras_Realtime_Multi-Person_Pose_Estimation/model.py", line 24, in pooling
        x = MaxPooling2D((ks, ks), strides=(st, st), name=name)(x)
      raise ValueError(err.message)
    ValueError: Negative dimension size caused by subtracting 2 from 1 for 'pool2_1/MaxPool' (op: 'MaxPool') with input shapes: [?,356,1,128].
    

    What's wrong with that? What shape img_input_shape should be ?

    opened by GerrieWell 8
  • py_rmpe_server is in working condition

    py_rmpe_server is in working condition

    I've finished python version of rmpe_server. It is 4.5 times faster than C++ version(140 pic/s vs 30 pics/sec on my server) code is approx. 2 times shorter and it is python, not c++

    I made pull request not to immediately join it to main repo, at this point I want somebody except me looks on my code, test it, try to train model, etc.

    update: during training loss is becoming NaN, need to find a bug update2: fixed

    opened by anatolix 6
  • Training with local data

    Training with local data

    Hi @michalfaber, thanks for the fantastic work. I was trying to see if I can still train with local data only, without augmentation. Apparently it says that "use_client_gen = False" is deprecated in the code, and a brief try shows that the format in locally generated h5 file is not compatible with what specified in DataIterator. So my question is that, was there once a working version of for training with local data that you can upload, or maybe you can shed some light on how I should modify the code if I want to train with local data without augmentation? Thanks!

    opened by DingGit 4
  • Does this works on CPU?

    Does this works on CPU?

    I tried to estimate the pose of the subjects in an image. After running the program with arguments. It seems like it is running for forever. It never gives output. I tried it on i5 6th gen CPU.

    opened by sainimohit23 3
  • Masking the Input Image

    Masking the Input Image

    https://github.com/michalfaber/keras_Realtime_Multi-Person_Pose_Estimation/blob/ff482e118ace9c9e6e3d0291fb4f2cca385d0ae7/training/dataset.py#L129

    Hi,

    Great repo! But is this correct? you're applying the mask to the input image, when the paper says to only apply it to the PAF and heatmap outputs during training.

    I couldn't find a similar snippet in https://github.com/ZheC/Realtime_Multi-Person_Pose_Estimation

    If this is intentional, why is it needed and what effect did it have?

    opened by WillBrennan 3
  • KeyError:

    KeyError: "Unable to open object (Object 'label' doesn't exist)" of h5["label"]

    When I try to run the inspect_dataset.ipynb file with the hdf5 file val_generated_dataset.h5, which I create with the generate_hdf5.py script. I ran into this error. KeyError: "Unable to open object (Object 'label' doesn't exist)"

    In generate_hdf5.py, I see there is only create one group "dataum".
    grp = h5.create_group("datum")

    So seems the group "label" not been created when creating the val_generated_dataset.h5. if the inspect_dataset.ipynb file not been updated after the code change of generate_hdf5.py ?

    opened by binliu-base 3
  • Can't find configobj

    Can't find configobj

    I downloaded the zip directly and run the "demo_image.py", which returned:

    Traceback (most recent call last): File "D:/Python/keras_Realtime_Multi-Person_Pose_Estimation-master/keras_Realtime_Multi-Person_Pose_Estimation-master/demo_image.py", line 7, in <module> from config_reader import config_reader File "D:\Python\keras_Realtime_Multi-Person_Pose_Estimation-master\keras_Realtime_Multi-Person_Pose_Estimation-master\config_reader.py", line 1, in <module> from configobj import ConfigObj ModuleNotFoundError: No module named 'configobj'

    opened by andrehuang 3
  • Obtain labels for keypoints

    Obtain labels for keypoints

    I followed the demo.ipynb notebook to obtain the key points. I am trying to label each key point detected in the image. But, I am not able to figure out how to do that from the data in all_peaks.

    The all_peaks list is something like,

    [[(417, 162, 0.23725834488868713, 0)], [(438, 264, 0.22009609639644623, 1)], [(360, 260, 0.22483864426612854, 2)], [(310, 435, 0.22168569266796112, 3)], [(302, 596, 0.23836150765419006, 4)], [(511, 270, 0.2024109661579132, 5)], [], [], [(388, 580, 0.18829642236232758, 6)], [(381, 824, 0.2216421663761139, 7)], [], [(503, 577, 0.19702039659023285, 8)], [(528, 828, 0.21746164560317993, 9)], [], [(406, 140, 0.2475488781929016, 10)], [(444, 141, 0.23833531141281128, 11)], [], [(487, 159, 0.22596435248851776, 12)]]
    

    From what I have understood, the last element in each item of the list is the label index for the keypoint. But when a certain feature is not detected, the item is empty. So I am not able to figure out how to label the keypoints.

    Can anyone help me out with this?

    opened by aakaashjois 2
  • My python crash when i run generate_marks.py.

    My python crash when i run generate_marks.py.

    I ran this project on windows platform. I sync coco data follow instruction, but when I executed generate_marks.py. It's crash. How to fix that. Please suggest me.

    image

    opened by beebrain 2
  • Image is never resized in augmentation

    Image is never resized in augmentation

    While testing my py_rmpe_server, I noticed rmpe_dataset_server is never randomly resizes images. I.e. main person on image always fixed size.

    params.scale_prob=1;
    
      float dice = Rand(RAND_MAX) / static_cast <float> (RAND_MAX);
      float scale_multiplier;
    
      //actually with scale_prob==1 condition is always true -- anatolix
      if(dice > param_.scale_prob) {
        img_temp = img_src.clone();
        scale_multiplier = 1;
      }
      else {
        float dice2 = Rand(RAND_MAX) / static_cast <float> (RAND_MAX);
        scale_multiplier = (param_.scale_max - param_.scale_min) * dice2 + param_.scale_min; //linear shear into [scale_min, scale_max]
      }
    
    
    opened by anatolix 2
  • Converted Body_25 Model?

    Converted Body_25 Model?

    I see that you successfully converted the classic COCO model from the openpose repo, but have never seen the Body_25 model? Have you had any luck with this in particular with converting the PReLU layers as that seems to be the point that would cause issues....

    opened by mmaGroupGitHub 0
  • Question about batch_dataflow function

    Question about batch_dataflow function

    Thanks for your effort. I have some question about batch_dataflow function.

    1. There is 'x'. what is the meaning of the x?
    2. There are [0, 1, 2], [3, 4, 3, 4, 3, 4...]. I wonder why are you grouping [0, 1, 2] and [ 3, 4...] respectively.
    3. Why [3, 4, 3, 4 ... ] is repeatedly??
    opened by sonyapark 0
  • What is the activation layer for output?

    What is the activation layer for output?

    Hi all, I have surveyed this repo. There are many relu layer for activation, but I donot find activation layer for output.

    The output heatmap and pafmap should be in 0~1. If there is no activation layer for output, how can we ensure the values scaled into this range?

    opened by busyyang 0
  • Train on my own dataset , got an error: assert batch_size <= ds.size()

    Train on my own dataset , got an error: assert batch_size <= ds.size()

    loading annotations into memory... Done (t=0.00s) creating index... index created! loading annotations into memory... Done (t=0.00s) creating index... index created! Loading dataset /content/keras_Realtime_Multi-Person_Pose_Estimation/dataset/train ... Loading image annot 0/12 Loading dataset /content/keras_Realtime_Multi-Person_Pose_Estimation/dataset/val ... Loading image annot 0/2 Traceback (most recent call last): File "train_pose.py", line 208, in batch_df = batch_dataflow(df, batch_size) File "/content/keras_Realtime_Multi-Person_Pose_Estimation/training/dataset.py", line 212, in batch_dataflow df = BatchData(df, batch_size, use_list=True) File "/usr/local/lib/python3.6/dist-packages/tensorpack/dataflow/common.py", line 95, in init assert batch

    opened by zhaoleo1111 0
Owner
M Faber
Software/Data Engineer
M Faber
Keras implementation of PersonLab for Multi-Person Pose Estimation and Instance Segmentation.

PersonLab This is a Keras implementation of PersonLab for Multi-Person Pose Estimation and Instance Segmentation. The model predicts heatmaps and vari

OCTI 160 Dec 21, 2022
Simple Pose: Rethinking and Improving a Bottom-up Approach for Multi-Person Pose Estimation

SimplePose Code and pre-trained models for our paper, “Simple Pose: Rethinking and Improving a Bottom-up Approach for Multi-Person Pose Estimation”, a

Jia Li 256 Dec 24, 2022
Code for "Multi-View Multi-Person 3D Pose Estimation with Plane Sweep Stereo"

Multi-View Multi-Person 3D Pose Estimation with Plane Sweep Stereo This repository includes the source code for our CVPR 2021 paper on multi-view mult

Jiahao Lin 66 Jan 4, 2023
3D Multi-Person Pose Estimation by Integrating Top-Down and Bottom-Up Networks

3D Multi-Person Pose Estimation by Integrating Top-Down and Bottom-Up Networks Introduction This repository contains the code and models for the follo

null 124 Jan 6, 2023
Official PyTorch implementation of "Camera Distance-aware Top-down Approach for 3D Multi-person Pose Estimation from a Single RGB Image", ICCV 2019

PoseNet of "Camera Distance-aware Top-down Approach for 3D Multi-person Pose Estimation from a Single RGB Image" Introduction This repo is official Py

Gyeongsik Moon 677 Dec 25, 2022
PoseViz – Multi-person, multi-camera 3D human pose visualization tool built using Mayavi.

PoseViz – 3D Human Pose Visualizer Multi-person, multi-camera 3D human pose visualization tool built using Mayavi. As used in MeTRAbs visualizations.

István Sárándi 79 Dec 30, 2022
SE3 Pose Interp - Interpolate camera pose or trajectory in SE3, pose interpolation, trajectory interpolation

SE3 Pose Interpolation Pose estimated from SLAM system are always discrete, and

Ran Cheng 4 Dec 15, 2022
Realtime Face Anti Spoofing with Face Detector based on Deep Learning using Tensorflow/Keras and OpenCV

Realtime Face Anti-Spoofing Detection ?? Realtime Face Anti Spoofing Detection with Face Detector to detect real and fake faces Please star this repo

Prem Kumar 86 Aug 3, 2022
Human head pose estimation using Keras over TensorFlow.

RealHePoNet: a robust single-stage ConvNet for head pose estimation in the wild.

Rafael Berral Soler 71 Jan 5, 2023
Repository for the paper "PoseAug: A Differentiable Pose Augmentation Framework for 3D Human Pose Estimation", CVPR 2021.

PoseAug: A Differentiable Pose Augmentation Framework for 3D Human Pose Estimation Code repository for the paper: PoseAug: A Differentiable Pose Augme

Pyjcsx 328 Dec 17, 2022
This repository contains codes of ICCV2021 paper: SO-Pose: Exploiting Self-Occlusion for Direct 6D Pose Estimation

SO-Pose This repository contains codes of ICCV2021 paper: SO-Pose: Exploiting Self-Occlusion for Direct 6D Pose Estimation This paper is basically an

shangbuhuan 52 Nov 25, 2022
Python scripts for performing 3D human pose estimation using the Mobile Human Pose model in ONNX.

Python scripts for performing 3D human pose estimation using the Mobile Human Pose model in ONNX.

Ibai Gorordo 99 Dec 31, 2022
OpenPose: Real-time multi-person keypoint detection library for body, face, hands, and foot estimation

Build Type Linux MacOS Windows Build Status OpenPose has represented the first real-time multi-person system to jointly detect human body, hand, facia

null 25.7k Jan 9, 2023
Web service for facial landmark detection, head pose estimation, facial action unit recognition, and eye-gaze estimation based on OpenFace 2.0

OpenGaze: Web Service for OpenFace Facial Behaviour Analysis Toolkit Overview OpenFace is a fantastic tool intended for computer vision and machine le

Sayom Shakib 4 Nov 3, 2022
OpenFace – a state-of-the art tool intended for facial landmark detection, head pose estimation, facial action unit recognition, and eye-gaze estimation.

OpenFace 2.2.0: a facial behavior analysis toolkit Over the past few years, there has been an increased interest in automatic facial behavior analysis

Tadas Baltrusaitis 5.8k Dec 31, 2022
Re-implementation of the Noise Contrastive Estimation algorithm for pyTorch, following "Noise-contrastive estimation: A new estimation principle for unnormalized statistical models." (Gutmann and Hyvarinen, AISTATS 2010)

Noise Contrastive Estimation for pyTorch Overview This repository contains a re-implementation of the Noise Contrastive Estimation algorithm, implemen

Denis Emelin 42 Nov 24, 2022
The project is an official implementation of our CVPR2019 paper "Deep High-Resolution Representation Learning for Human Pose Estimation"

Deep High-Resolution Representation Learning for Human Pose Estimation (CVPR 2019) News [2020/07/05] A very nice blog from Towards Data Science introd

Leo Xiao 3.9k Jan 5, 2023
The project is an official implementation of our paper "3D Human Pose Estimation with Spatial and Temporal Transformers".

3D Human Pose Estimation with Spatial and Temporal Transformers This repo is the official implementation for 3D Human Pose Estimation with Spatial and

Ce Zheng 363 Dec 28, 2022
Official project website for the CVPR 2021 paper "Exploring intermediate representation for monocular vehicle pose estimation"

EgoNet Official project website for the CVPR 2021 paper "Exploring intermediate representation for monocular vehicle pose estimation". This repo inclu

Shichao Li 138 Dec 9, 2022