-
Notifications
You must be signed in to change notification settings - Fork 255
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from tryolabs/demos/update-openpose
Demos/update openpose
- Loading branch information
Showing
4 changed files
with
115 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
# Speed OpenPose inference using tracking | ||
|
||
Demo for extrapolating detections through skipped frames. Based on [OpenPose](https://github.com/CMU-Perceptual-Computing-Lab/openpose) version 1.4. | ||
Demo for extrapolating detections through skipped frames. Based on [OpenPose](https://github.com/CMU-Perceptual-Computing-Lab/openpose) version 1.7. | ||
|
||
## Instructions | ||
|
||
1. Install Norfair with `pip install norfair[video]`. | ||
2. Install [OpenPose version 1.4](https://github.com/CMU-Perceptual-Computing-Lab/openpose/releases/tag/v1.4.0). | ||
3. Run `python openpose_extrapolation.py`. | ||
2. Install [OpenPose version 1.7](https://github.com/CMU-Perceptual-Computing-Lab/openpose/releases/tag/v1.7.0). You can follow [these](./openpose_extrapolation.ipynb) instructions to install and compile OpenPose. | ||
3. Run `python openpose_extrapolation.py <video file> --skip-frame 5`. | ||
4. Use additional arguments `--skip-frame`, `--select-gpu` as you wish. | ||
|
||
Alternatively the example can be executed entirely within `openpose_extrapolation.ipynb`. | ||
|
||
## Explanation | ||
|
||
If you just want to speed up inference on a detector, you can make your detector skip frames, and use Norfair to extrapolate the detections through these skipped frames. | ||
|
||
In this example, we are skipping 2 out of every 3 frames, which should make the video process 3 times faster. This is because the time added by running the Norfair itself is negligible when compared to not having to run 2 inferences on a deep neural network. | ||
In this example, we are skipping 4 out of every 5 frames, which should make the video process 5 times faster. This is because the time added by running the Norfair itself is negligible when compared to not having to run 4 inferences on a deep neural network. | ||
|
||
This is how the results look like (original videos can be found at [Kaggle](https://www.kaggle.com/datasets/ashayajbani/oxford-town-centre?select=TownCentreXVID.mp4)): | ||
|
||
This is how the results look like: | ||
 | ||
|
||
 | ||
 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"cells":[{"cell_type":"markdown","metadata":{"id":"gBiZPFydJozY"},"source":["# OpenPose Demo"]},{"cell_type":"markdown","metadata":{},"source":["## Install Norfair"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["!pip install norfair[video]"]},{"cell_type":"markdown","metadata":{},"source":["## Build OpenPose"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"jLe_ckKB0gKJ"},"outputs":[],"source":["# cmake ~ 30min\n","! wget -c \"https://github.com/Kitware/CMake/releases/download/v3.13.4/cmake-3.13.4.tar.gz\"\n","! tar xf cmake-3.13.4.tar.gz\n","! cd cmake-3.13.4 && ./configure && make && sudo make install"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"vsgRGv2A0rS9"},"outputs":[],"source":["# Basic ~ 2min\n","! sudo apt-get --assume-yes update\n","! sudo apt-get --assume-yes install build-essential\n","# OpenCV\n","! sudo apt-get --assume-yes install libopencv-dev\n","# General dependencies\n","! sudo apt-get --assume-yes install libatlas-base-dev libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler\n","! sudo apt-get --assume-yes install --no-install-recommends libboost-all-dev\n","# Remaining dependencies, 14.04\n","! sudo apt-get --assume-yes install libgflags-dev libgoogle-glog-dev liblmdb-dev\n","# Python2 libs\n","! sudo apt-get --assume-yes install python-setuptools python-dev build-essential\n","! sudo easy_install pip\n","! sudo -H pip install --upgrade numpy protobuf opencv-python\n","# Python3 libs\n","! sudo apt-get --assume-yes install python3-setuptools python3-dev build-essential\n","! sudo apt-get --assume-yes install python3-pip\n","! sudo -H pip3 install --upgrade numpy protobuf opencv-python\n","# OpenCV 2.4 -> Added as option\n","# # sudo apt-get --assume-yes install libopencv-dev\n","# OpenCL Generic\n","! sudo apt-get --assume-yes install opencl-headers ocl-icd-opencl-dev\n","! sudo apt-get --assume-yes install libviennacl-dev\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"b7R8mCWqG-_J"},"outputs":[],"source":["# Clone Openpose\n","! git clone --depth 1 https://github.com/CMU-Perceptual-Computing-Lab/openpose.git "]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ITisAwVgudc1"},"outputs":[],"source":["# Get Openpose model data ~ 2min\n","! cd openpose/models && chmod +r ./getModels.sh && sh getModels.sh"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"sUBlbMMCu7n0"},"outputs":[],"source":["# Build Openpose ~20min\n","! sed -i 's/execute_process(COMMAND git checkout master WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}\\/3rdparty\\/caffe)/execute_process(COMMAND git checkout f019d0dfe86f49d1140961f8c7dec22130c83154 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}\\/3rdparty\\/caffe)/g' openpose/CMakeLists.txt\n","! cd openpose && rm -r build || true && mkdir build && cd build && cmake -DBUILD_PYTHON=ON .. && make -j`nproc`"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"fY6ntxWZyoMJ"},"outputs":[],"source":["# example demo usage ~1min\n","! cd openpose && ./build/examples/openpose/openpose.bin --video examples/media/video.avi --write_json ./output1/ --display 0 --write_video ./output1/openpose.avi"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ApZyAjuEXiyk"},"outputs":[],"source":["# python example demo usage ~1min\n","! cd ./openpose/build/examples/tutorial_api_python && python3 01_body_from_image.py"]},{"cell_type":"markdown","metadata":{},"source":["## Run Demo"]},{"cell_type":"markdown","metadata":{},"source":["Get example code and videos:"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["!wget \"https://raw.githubusercontent.com/tryolabs/norfair/master/demos/openpose/openpose_extrapolation.py\" -O openpose_extrapolation.py\n","!wget \"https://user-images.githubusercontent.com/92468171/172700205-2fdcab9b-3820-477e-9c12-141762024c04.mp4\" -O oxford_openpose_raw_1.mp4"]},{"cell_type":"markdown","metadata":{},"source":["Before running the following cell you should modify `openpose_extrapolation.py` with the path to your openpose instalation folder."]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["!python openpose_extrapolation.py oxford_openpose_raw_1.mp4 --skip-frame 5"]},{"cell_type":"markdown","metadata":{},"source":["### Display"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["!ffmpeg -i ./oxford_openpose_raw_1_out.mp4 -vcodec vp9 ./oxford_openpose_raw_1_out.webm"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["import io\n","from base64 import b64encode\n","from IPython.display import HTML\n","\n","with io.open('oxford_openpose_raw_1_out.webm','r+b') as f:\n"," mp4 = f.read()\n","data_url = \"data:video/webm;base64,\" + b64encode(mp4).decode()\n","HTML(\"\"\"\n","<video width=800 controls>\n"," <source src=\"%s\" type=\"video/webm\">\n","</video>\n","\"\"\" % data_url)"]}],"metadata":{"accelerator":"GPU","colab":{"collapsed_sections":[],"name":"install_openpose.ipynb","provenance":[]},"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters