introduction_en.ipynb 9.1 KB
Notebook
Newer Older
1 2 3 4 5 6 7 8 9
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. PP-TinyPose Introduction\n",
    "PP-TinyPose is a real-time keypoint detection model optimized by PaddleDetecion for mobile devices, which can smoothly run multi-person pose estimation tasks on mobile devices. With the excellent self-developed lightweight detection model [PicoDet](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/configs/picodet/README.md),\n",
    "\n",
L
LokeZhou 已提交
10 11 12 13 14
    "we also provide a lightweight pedestrian detection model. PP-TinyPose has the following dependency requirements:\n",
    "PaddlePaddle>=2.2\n",
    "\n",
    "If you want to deploy it on the mobile devives, you also need:\n",
    "\n",
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    "Paddle-Lite>=2.11"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "More deployment cases can be referred to[PP-TinyPose](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/configs/keypoint/tiny_pose/README.md)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Model effects and application scenarios\n",
    "### 2.1 Key point detection task:\n",
    "\n",
    "#### 2.1.1 dataset\n",
    "\n",
    "The current Keypoint model supports[COCO](https://cocodataset.org/#keypoints-2017) and [MPII](http://human-pose.mpi-inf.mpg.de/#overview).Please refer to[Key point data preparation](https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.5/docs/tutorials/KeyPointConfigGuide_en.md)\n",
    "\n",
    "#### 2.1.2 Model effects:\n",
    "\n",
    "\n",
    "![](https://user-images.githubusercontent.com/15810355/181733705-d0f84232-c6a2-43dd-be70-4a3a246b8fbc.gif)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. How to use the model\n",
    "\n",
    "### 3.1 model Inference:\n",
    "\n",
    "(When not running on Jupyter Notebook, you need to set \"!\" or \"%\" removed)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "jupyter": {
     "outputs_hidden": false
    },
    "scrolled": true,
    "tags": []
   },
   "outputs": [],
   "source": [
    "%cd ~/work\n",
    "# clone PaddleDetection。\n",
    "!git clone https://gitee.com/paddlepaddle/PaddleDetection"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* install"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [],
   "source": [
    "# \n",
    "%cd ~/work/PaddleDetection/\n",
    "\n",
    "# \n",
    "!pip install pyzmq   \n",
    "!pip install -r requirements.txt\n",
    "\n",
    "#\n",
    "%cd ~/work/PaddleDetection/\n",
    "# \n",
    "%env PYTHONPATH=.:$PYTHONPATH\n",
    "# set GPU\n",
    "%env CUDA_VISIBLE_DEVICES=0\n",
    "\n",
    "# \n",
    "!pip install pycocotools  \n",
    "!pip install cython-bbox      \n",
    "!pip install xmltodict  \n",
    "!pip install terminaltables    \n",
    "!pip intall motmetrics  \n",
    "!pip install lap    \n",
    "!pip install shapely      \n",
    "!pip install pytest-benchmark    \n",
    "!pip install pytest    \n",
    "\n",
    "\n",
    "# PaddleDetection \n",
    "!python setup.py install  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Verify whether the installation is successful. If an error is reported, just perform the previous step"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "\n",
    "!python ppdet/modeling/tests/test_architectures.py"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* quickly start\n",
    "\n",
    "congratulations! You have successfully installed PaddleDetection. Next, we will quickly detect the effect of key points. You can directly download the corresponding predictive deployment model provided in the model base, obtain the predictive deployment models of pedestrian detection model and key point detection model respectively, and decompress them."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [],
   "source": [
L
LokeZhou 已提交
155 156 157 158 159 160 161 162 163 164 165
    "# Download model\n",
    "!mkdir output_inference\n",
    "%cd output_inference\n",
    "# Download pedestrian detection model\n",
    "!wget https://bj.bcebos.com/v1/paddledet/models/keypoint/tinypose_enhance/picodet_s_320_lcnet_pedestrian.zip\n",
    "!unzip picodet_s_320_lcnet_pedestrian.zip\n",
    "# Download key point detection model\n",
    "!wget https://bj.bcebos.com/v1/paddledet/models/keypoint/tinypose_enhance/tinypose_128x96.zip\n",
    "!unzip tinypose_128x96.zip\n",
    "\n",
    "%cd ~/work/PaddleDetection/\n",
166
    "# Predict a image\n",
L
LokeZhou 已提交
167
    "!python3 deploy/python/det_keypoint_unite_infer.py --det_model_dir=output_inference/picodet_s_320_pedestrian --keypoint_model_dir=output_inference/tinypose_128x96 --image_file=demo/hrnet_demo.jpg --device=GPU\n",
168
    "# predict multiple images\n",
L
LokeZhou 已提交
169
    "!python3 deploy/python/det_keypoint_unite_infer.py --det_model_dir=output_inference/picodet_s_320_pedestrian --keypoint_model_dir=output_inference/tinypose_128x96 --image_dir=demo/ --device=GPU\n",
170 171
    "\n",
    "# predict video\n",
L
LokeZhou 已提交
172
    "!python3 deploy/python/det_keypoint_unite_infer.py --det_model_dir=output_inference/picodet_s_320_pedestrian --keypoint_model_dir=output_inference/tinypose_128x96 --video_file={your video file} --device=GPU\n"
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.2 Train:\n",
    "*  clone PaddleDetection refer 3.1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Dataset preparation\n",
    "\n",
    "    The training set of key point detection model and pedestrian detection model include `COCO` and[AI Challenger](https://arxiv.org/abs/1711.06475),The key points of each dataset are defined as follows:\n",
    "    ```\n",
    "    COCO keypoint Description:\n",
    "        0: \"Nose\",\n",
    "        1: \"Left Eye\",\n",
    "        2: \"Right Eye\",\n",
    "        3: \"Left Ear\",\n",
    "        4: \"Right Ear\",\n",
    "        5: \"Left Shoulder,\n",
    "        6: \"Right Shoulder\",\n",
    "        7: \"Left Elbow\",\n",
    "        8: \"Right Elbow\",\n",
    "        9: \"Left Wrist\",\n",
    "        10: \"Right Wrist\",\n",
    "        11: \"Left Hip\",\n",
    "        12: \"Right Hip\",\n",
    "        13: \"Left Knee\",\n",
    "        14: \"Right Knee\",\n",
    "        15: \"Left Ankle\",\n",
    "        16: \"Right Ankle\"\n",
    "\n",
    "    AI Challenger Description:\n",
    "        0: \"Right Shoulder\",\n",
    "        1: \"Right Elbow\",\n",
    "        2: \"Right Wrist\",\n",
    "        3: \"Left Shoulder\",\n",
    "        4: \"Left Elbow\",\n",
    "        5: \"Left Wrist\",\n",
    "        6: \"Right Hip\",\n",
    "        7: \"Right Knee\",\n",
    "        8: \"Right Ankle\",\n",
    "        9: \"Left Hip\",\n",
    "        10: \"Left Knee\",\n",
    "        11: \"Left Ankle\",\n",
    "        12: \"Head top\",\n",
    "        13: \"Neck\"\n",
    "    ```\n",
    "\n",
    "    Since the annatation format of these two datasets are different, we aligned their annotations to `COCO` format. You can download [Training List](https://bj.bcebos.com/v1/paddledet/data/keypoint/aic_coco_train_cocoformat.json) and put it at `dataset/`. To align these two datasets, we mainly did the following works:\n",
    "    - Align the indexes of the `AI Challenger` keypoint to be consistent with `COCO` and unify the flags whether the keypoint is labeled/visible.\n",
    "    - Discard the unique keypoints in `AI Challenger`. For keypoints not in this dataset but in `COCO`, set it to not labeled.\n",
    "    - Rearranged `image_id` and `annotation id`.\n",
    "   \n",
    "    If you need to customize the dataset, you can refer to[Quick Start - Custom Dataset](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/keypoint#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# keypoint detection model\n",
L
LokeZhou 已提交
243
    "!python3 -m paddle.distributed.launch tools/train.py -c configs/keypoint/tiny_pose/tinypose_128x96.yml\n",
244 245
    "\n",
    "# pedestrian detection model\n",
L
LokeZhou 已提交
246
    "!python3 -m paddle.distributed.launch tools/train.py -c configs/picodet/application/pedestrian_detection/picodet_s_320_lcnet_pedestrian.yml"
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. Solution\n",
    "<div align=\"center\">\n",
    "  <img src=\"tinypose_pipeline.png\" width='800'/>\n",
    "</div>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}