diff options
| author | adamhrv <adam@ahprojects.com> | 2018-12-05 12:00:15 +0100 |
|---|---|---|
| committer | adamhrv <adam@ahprojects.com> | 2018-12-05 12:00:15 +0100 |
| commit | 90abf459d1df1f21960c1d653a1f936d1ec30256 (patch) | |
| tree | facab8e9bac6c56e69c369c2140cdbea218a01df /megapixels/notebooks/datasets/mpii_pose/pose_mpi_clean_data.ipynb | |
| parent | 0529d4cd1618016319e995c37aa118bf8c2d501b (diff) | |
.
Diffstat (limited to 'megapixels/notebooks/datasets/mpii_pose/pose_mpi_clean_data.ipynb')
| -rw-r--r-- | megapixels/notebooks/datasets/mpii_pose/pose_mpi_clean_data.ipynb | 399 |
1 files changed, 399 insertions, 0 deletions
diff --git a/megapixels/notebooks/datasets/mpii_pose/pose_mpi_clean_data.ipynb b/megapixels/notebooks/datasets/mpii_pose/pose_mpi_clean_data.ipynb new file mode 100644 index 00000000..d8d7b77d --- /dev/null +++ b/megapixels/notebooks/datasets/mpii_pose/pose_mpi_clean_data.ipynb @@ -0,0 +1,399 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Clean Human Pose MPI Dataset\n", + "\n", + "Fix data\n", + "\n", + "Data structure:\n", + "- `data[2]` = 2 x 7 x 100 array\n", + "- `data[2][0]` = x locations\n", + "- `data[2][0]` = y locations\n", + "- ordering is `0 Head, 1 Right wrist, 2 Left wrist, 3 Right elbow, 4 Left elbow, 5 Right shoulder and 6 Left shoulder`" + ] + }, + { + "cell_type": "code", + "execution_count": 175, + "metadata": {}, + "outputs": [], + "source": [ + "%reload_ext autoreload\n", + "%autoreload 2\n", + "\n", + "import os\n", + "from os.path import join\n", + "import math\n", + "from glob import glob\n", + "from random import randint\n", + "\n", + "import cv2 as cv\n", + "import numpy as np\n", + "import pandas as pd\n", + "from PIL import Image, ImageDraw\n", + "%matplotlib inline\n", + "import matplotlib.pyplot as plt\n", + "import scipy.io\n", + "from pathlib import Path\n", + "from sklearn import preprocessing\n", + "\n", + "import sys\n", + "sys.path.append('/work/megapixels_dev/megapixels/')\n", + "from app.settings import app_cfg as cfg\n", + "from app.utils import file_utils" + ] + }, + { + "cell_type": "code", + "execution_count": 176, + "metadata": {}, + "outputs": [], + "source": [ + "DATA_STORE = '/data_store_nas/'\n", + "fp_dataset = join(DATA_STORE, 'datasets/people/youtube_poses')\n", + "dir_fp_frames = join(fp_dataset, 'YouTube_Pose_dataset_1.0/GT_frames')" + ] + }, + { + "cell_type": "code", + "execution_count": 177, + "metadata": {}, + "outputs": [], + "source": [ + "dirs_frames = glob(join(dir_fp_frames, '*'))\n", + "fps_frames = {}\n", + "for dir_frames in dirs_frames:\n", + " fps_frames[dir_frames] = join(dir_frames, '*')" + ] + }, + { + "cell_type": "code", + "execution_count": 178, + "metadata": {}, + "outputs": [], + "source": [ + "fp_pose_data = join(fp_dataset, 'YouTube_Pose_dataset_1.0/YouTube_Pose_dataset.mat')\n", + "fp_out = join(fp_dataset, 'poses.csv')\n", + "pose_data = scipy.io.loadmat(fp_pose_data)['data'][0]" + ] + }, + { + "cell_type": "code", + "execution_count": 182, + "metadata": {}, + "outputs": [], + "source": [ + "# convert data to pandas DF for sanity\n", + "poses = []\n", + "for i, pose in enumerate(pose_data):\n", + "\n", + " video_id = pose[1][0]\n", + " pose_pts = pose[2]\n", + " crop_x1 = int(pose[6][0][0])\n", + " crop_y1 = int(pose[6][0][1])\n", + " crop_x2 = int(pose[6][0][2])\n", + " crop_y2 = int(pose[6][0][3])\n", + " w = pose[7][0][0]\n", + " h = pose[7][0][1]\n", + " scale = pose[5][0][0]\n", + " \n", + " for j in range(pose_pts.shape[2]): # 100 frames\n", + " x = [pose_pts[0][i][j] for i in range(7)]\n", + " y = [pose_pts[1][i][j] for i in range(7)]\n", + " poses.append({\n", + " 'video_id': video_id, \n", + " 'scale': scale,\n", + " 'crop_x1': crop_x1,\n", + " 'crop_y1': crop_y1,\n", + " 'crop_x2': crop_x2,\n", + " 'crop_y2': crop_y2,\n", + " 'width': w, \n", + " 'height': h,\n", + " 'head_x': x[0],\n", + " 'head_y': y[0],\n", + " 'wrist_right_x': x[1],\n", + " 'wrist_right_y': y[1],\n", + " 'wrist_left_x': x[2], \n", + " 'wrist_left_y': y[2],\n", + " 'elbow_right_x': x[3],\n", + " 'elbow_right_y': y[3],\n", + " 'elbow_left_x': x[4], \n", + " 'elbow_left_y': y[4],\n", + " 'shoulder_right_x': x[5],\n", + " 'shoulder_right_y': y[5],\n", + " 'shoulder_left_x': x[6], \n", + " 'shoulder_left_y': y[6],\n", + " })\n", + "df_poses = pd.DataFrame.from_dict(poses)\n", + "df_poses.to_csv(fp_out)" + ] + }, + { + "cell_type": "code", + "execution_count": 183, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "<div>\n", + "<style scoped>\n", + " .dataframe tbody tr th:only-of-type {\n", + " vertical-align: middle;\n", + " }\n", + "\n", + " .dataframe tbody tr th {\n", + " vertical-align: top;\n", + " }\n", + "\n", + " .dataframe thead th {\n", + " text-align: right;\n", + " }\n", + "</style>\n", + "<table border=\"1\" class=\"dataframe\">\n", + " <thead>\n", + " <tr style=\"text-align: right;\">\n", + " <th></th>\n", + " <th>crop_x1</th>\n", + " <th>crop_x2</th>\n", + " <th>crop_y1</th>\n", + " <th>crop_y2</th>\n", + " <th>elbow_left_x</th>\n", + " <th>elbow_left_y</th>\n", + " <th>elbow_right_x</th>\n", + " <th>elbow_right_y</th>\n", + " <th>head_x</th>\n", + " <th>head_y</th>\n", + " <th>...</th>\n", + " <th>shoulder_left_x</th>\n", + " <th>shoulder_left_y</th>\n", + " <th>shoulder_right_x</th>\n", + " <th>shoulder_right_y</th>\n", + " <th>video_id</th>\n", + " <th>width</th>\n", + " <th>wrist_left_x</th>\n", + " <th>wrist_left_y</th>\n", + " <th>wrist_right_x</th>\n", + " <th>wrist_right_y</th>\n", + " </tr>\n", + " </thead>\n", + " <tbody>\n", + " <tr>\n", + " <th>0</th>\n", + " <td>1</td>\n", + " <td>1920</td>\n", + " <td>1</td>\n", + " <td>1080</td>\n", + " <td>277.721438</td>\n", + " <td>192.416331</td>\n", + " <td>147.628696</td>\n", + " <td>169.326277</td>\n", + " <td>195.498320</td>\n", + " <td>81.471438</td>\n", + " <td>...</td>\n", + " <td>254.631384</td>\n", + " <td>127.088374</td>\n", + " <td>178.603159</td>\n", + " <td>134.691196</td>\n", + " <td>-osma2n86oA</td>\n", + " <td>720</td>\n", + " <td>278.566196</td>\n", + " <td>235.498992</td>\n", + " <td>158.047379</td>\n", + " <td>122.301411</td>\n", + " </tr>\n", + " <tr>\n", + " <th>1</th>\n", + " <td>1</td>\n", + " <td>1920</td>\n", + " <td>1</td>\n", + " <td>1080</td>\n", + " <td>273.497648</td>\n", + " <td>187.629368</td>\n", + " <td>152.134073</td>\n", + " <td>129.341062</td>\n", + " <td>207.324933</td>\n", + " <td>72.742272</td>\n", + " <td>...</td>\n", + " <td>254.349798</td>\n", + " <td>131.593750</td>\n", + " <td>181.137433</td>\n", + " <td>123.990927</td>\n", + " <td>-osma2n86oA</td>\n", + " <td>720</td>\n", + " <td>274.342406</td>\n", + " <td>235.498992</td>\n", + " <td>135.238911</td>\n", + " <td>91.608535</td>\n", + " </tr>\n", + " <tr>\n", + " <th>2</th>\n", + " <td>1</td>\n", + " <td>1920</td>\n", + " <td>1</td>\n", + " <td>1080</td>\n", + " <td>258.010417</td>\n", + " <td>159.752352</td>\n", + " <td>160.581653</td>\n", + " <td>143.138777</td>\n", + " <td>229.007056</td>\n", + " <td>76.966062</td>\n", + " <td>...</td>\n", + " <td>250.407594</td>\n", + " <td>125.117272</td>\n", + " <td>190.992944</td>\n", + " <td>117.232863</td>\n", + " <td>-osma2n86oA</td>\n", + " <td>720</td>\n", + " <td>213.801411</td>\n", + " <td>108.785282</td>\n", + " <td>181.982191</td>\n", + " <td>89.074261</td>\n", + " </tr>\n", + " <tr>\n", + " <th>3</th>\n", + " <td>1</td>\n", + " <td>1920</td>\n", + " <td>1</td>\n", + " <td>1080</td>\n", + " <td>274.342406</td>\n", + " <td>188.192540</td>\n", + " <td>142.841734</td>\n", + " <td>110.193212</td>\n", + " <td>203.101142</td>\n", + " <td>76.402890</td>\n", + " <td>...</td>\n", + " <td>253.786626</td>\n", + " <td>128.777890</td>\n", + " <td>185.361223</td>\n", + " <td>120.611895</td>\n", + " <td>-osma2n86oA</td>\n", + " <td>720</td>\n", + " <td>276.595094</td>\n", + " <td>231.556788</td>\n", + " <td>156.921035</td>\n", + " <td>55.847110</td>\n", + " </tr>\n", + " <tr>\n", + " <th>4</th>\n", + " <td>1</td>\n", + " <td>1920</td>\n", + " <td>1</td>\n", + " <td>1080</td>\n", + " <td>272.371304</td>\n", + " <td>194.387433</td>\n", + " <td>225.628024</td>\n", + " <td>164.820901</td>\n", + " <td>245.902218</td>\n", + " <td>93.016465</td>\n", + " <td>...</td>\n", + " <td>255.476142</td>\n", + " <td>139.478159</td>\n", + " <td>183.390121</td>\n", + " <td>126.806788</td>\n", + " <td>-osma2n86oA</td>\n", + " <td>720</td>\n", + " <td>305.316868</td>\n", + " <td>172.423723</td>\n", + " <td>278.284610</td>\n", + " <td>165.102487</td>\n", + " </tr>\n", + " </tbody>\n", + "</table>\n", + "<p>5 rows × 22 columns</p>\n", + "</div>" + ], + "text/plain": [ + " crop_x1 crop_x2 crop_y1 crop_y2 elbow_left_x elbow_left_y \\\n", + "0 1 1920 1 1080 277.721438 192.416331 \n", + "1 1 1920 1 1080 273.497648 187.629368 \n", + "2 1 1920 1 1080 258.010417 159.752352 \n", + "3 1 1920 1 1080 274.342406 188.192540 \n", + "4 1 1920 1 1080 272.371304 194.387433 \n", + "\n", + " elbow_right_x elbow_right_y head_x head_y ... \\\n", + "0 147.628696 169.326277 195.498320 81.471438 ... \n", + "1 152.134073 129.341062 207.324933 72.742272 ... \n", + "2 160.581653 143.138777 229.007056 76.966062 ... \n", + "3 142.841734 110.193212 203.101142 76.402890 ... \n", + "4 225.628024 164.820901 245.902218 93.016465 ... \n", + "\n", + " shoulder_left_x shoulder_left_y shoulder_right_x shoulder_right_y \\\n", + "0 254.631384 127.088374 178.603159 134.691196 \n", + "1 254.349798 131.593750 181.137433 123.990927 \n", + "2 250.407594 125.117272 190.992944 117.232863 \n", + "3 253.786626 128.777890 185.361223 120.611895 \n", + "4 255.476142 139.478159 183.390121 126.806788 \n", + "\n", + " video_id width wrist_left_x wrist_left_y wrist_right_x wrist_right_y \n", + "0 -osma2n86oA 720 278.566196 235.498992 158.047379 122.301411 \n", + "1 -osma2n86oA 720 274.342406 235.498992 135.238911 91.608535 \n", + "2 -osma2n86oA 720 213.801411 108.785282 181.982191 89.074261 \n", + "3 -osma2n86oA 720 276.595094 231.556788 156.921035 55.847110 \n", + "4 -osma2n86oA 720 305.316868 172.423723 278.284610 165.102487 \n", + "\n", + "[5 rows x 22 columns]" + ] + }, + "execution_count": 183, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_poses.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 172, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "22" + ] + }, + "execution_count": 172, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "len(df_poses.keys())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "megapixels", + "language": "python", + "name": "megapixels" + }, + "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.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} |
