[PYTHON] I tried running the DNN part of OpenPose with Chainer CPU

This article is reprinted from Our blog.

Introduction

This time, I will run OpenPose on Mac using chainer. (It will be a part of the function to generate the detection heatmap instead of the whole)

    1. Download Caffe's trained model
  1. Load Caffe's model from Chainer
    1. Apply images to Chainer's network

It has been reported that OpenPose, a skeleton estimation algorithm using a monocular camera announced at CVPR2017, will realize real-time processing on Ubuntu and Windows. However, since GPU is required or Mac does not support it, I thought that it could be run on Mac or CPU somehow, so I will load Caffe's model with Chainer and execute only the DNN part of the first half.

Execution environment (should work on Linux)

Mac book Pro (2.7 GHz Intel Core i5,16 GB 1867 MHz DDR3) Python2.7 (Chainer, Numpy)

work

    1. Download Caffe's trained model

Download the executable binary for Windows at here. It contains the Caffe parameter file. (If you are interested in direct links, download and unzip the portable OpenPose demo 1.0. In the middle of https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/installation.md. Please drop from 1.)

  1. Load Caffe's model from Chainer

This time, we will use a COCO model that estimates 18 skeletons. (MPI model can be done by the same procedure) The Caffe model is stored in the following directory.

OpenPose_demo_1.0.1/models/pose/coco/pose_iter_440000.caffemodel

Read this from chainer.

from chainer.functions import caffe
func = caffe.CaffeFunction('pose_iter_440000.caffemodel')
    1. Apply images to Chainer's network

OpenPose_demo_1.0.1/models/pose/coco/pose_deploy_linevec.prototxt If you read, the network configuration is written, and if you look at the last output layer

layer {
   name: "concat_stage7"
   type: "Concat"
   bottom: "Mconv7_stage6_L2"
   bottom: "Mconv7_stage6_L1"
   # top: "concat_stage7"
   top: "net_output"
   concat_param {
     axis: 1
   }
 }

The first output node is defined with the name Mconv7_stage6_L2. (Mconv7_stage6_L1 is more like a bone)

So, by specifying this in the output layer of func, you can get the output map of (1,19, h, w).

x = chainer.Variable([Image numpy array])
y, = func(inputs={'data': x}, outputs=['Mconv7_stage6_L2'])
print y.data.shape #(1,19,h,w)

The numpy array of images is 0.0 to 1.0 in size (1, 4, height, width) and values instead of 0 to 255. Also note that the dtype must be np.float32. (I don't know if RGBA is supposed to be used instead of RGB, but I'm typing in the 4th with 0s filled in)

↓ This image I tried paku2-200x300.jpg

testout-768x228.png

    POSE_COCO_BODY_PARTS {
        {0,  "Nose"},
        {1,  "Neck"},
        {2,  "RShoulder"},
        {3,  "RElbow"},
        {4,  "RWrist"},
        {5,  "LShoulder"},
        {6,  "LElbow"},
        {7,  "LWrist"},
        {8,  "RHip"},
        {9,  "RKnee"},
        {10, "RAnkle"},
        {11, "LHip"},
        {12, "LKnee"},
        {13, "LAnkle"},
        {14, "REye"},
        {15, "LEye"},
        {16, "REar"},
        {17, "LEar"},
        {18, "Bkg"},
    }

The heatmap shows the probability of existence of each part of the body written in the structure above. It takes about 10 seconds per sheet, but it works on the CPU, so it seems to be more versatile.

Recommended Posts

I tried running the DNN part of OpenPose with Chainer CPU
I tried to learn the sin function with chainer
I tried running the TensorFlow tutorial with comments (text classification of movie reviews)
I tried to erase the negative part of Meros
I tried running the sample code of the Ansible module
I tried to visualize the running data of the racing game (Assetto Corsa) with Plotly
I tried to find the entropy of the image with python
I tried "gamma correction" of the image with Python + OpenCV
I tried to find the average of the sequence with TensorFlow
I tried running Movidius NCS with python of Raspberry Pi3
I tried to implement ListNet of rank learning with Chainer
I tried running prolog with python 3.8.2.
I tried scraping the ranking of Qiita Advent Calendar with Python
[AWS / Tello] I tried operating the drone with my voice Part2
I tried to automate the watering of the planter with Raspberry Pi
I studied with Kaggle Start Book on the subject of kaggle [Part 1]
I wrote the basic operation of Pandas with Jupyter Lab (Part 1)
[AWS / Tello] I tried operating the drone with my voice Part1
I tried to expand the size of the logical volume with LVM
I tried to improve the efficiency of daily work with Python
I wrote the basic operation of Pandas with Jupyter Lab (Part 2)
I tried running the TensorFlow tutorial with comments (_TensorFlow_2_0_Introduction for beginners)
I tried the asynchronous server of Django 3.0
I tried implementing DeepPose with PyTorch PartⅡ
I tried playing with the image with Pillow
765 I tried to identify the three professional families by CNN (with Chainer 2.0.0)
I tried to get the authentication code of Qiita API with Python.
I tried to automatically extract the movements of PES players with software
I tried to learn the angle from sin and cos with chainer
I tried to analyze the negativeness of Nono Morikubo. [Compare with Posipa]
I tried to streamline the standard role of new employees with Python
I tried to visualize the text of the novel "Weathering with You" with WordCloud
I tried to get the movie information of TMDb API with Python
I tried to predict the behavior of the new coronavirus with the SEIR model.
I tried handwriting recognition of runes with scikit-learn
I tried "smoothing" the image with Python + OpenCV
I tried hundreds of millions of SQLite with python
I tried the pivot table function of pandas
I tried cluster analysis of the weather map
I tried image recognition of CIFAR-10 with Keras-Learning-
I tried "differentiating" the image with Python + OpenCV
I tried image recognition of CIFAR-10 with Keras-Image recognition-
I tried to save the data with discord
I tried Flask with Remote-Containers of VS Code
I tried to touch the API of ebay
I tried super easy linear separation with Chainer
I tried to correct the keystone of the image
I tried "binarizing" the image with Python + OpenCV
I tried running faiss with python, Go, Rust
I tried running Deep Floor Plan with Python 3.6.10.
I tried using the image filter of OpenCV
I tried playing with the calculator on tkinter
I tried to predict the price of ETF
I tried to vectorize the lyrics of Hinatazaka46!
I tried to easily visualize the tweets of JAWS DAYS 2017 with Python + ELK
I tried object detection with YOLO v3 (TensorFlow 2.1) on the GPU of windows!
The story of making soracom_exporter (I tried to monitor SORACOM Air with Prometheus)
I tried to create a model with the sample of Amazon SageMaker Autopilot
I tried to automatically send the literature of the new coronavirus to LINE with Python
I tried to make something like a chatbot with the Seq2Seq model of TensorFlow
I tried to extract features with SIFT of OpenCV