From 90abf459d1df1f21960c1d653a1f936d1ec30256 Mon Sep 17 00:00:00 2001 From: adamhrv Date: Wed, 5 Dec 2018 12:00:15 +0100 Subject: . --- .../datasets/mpii_pose/pose_mpi_clean_data.ipynb | 399 +++++++++++++++++++++ 1 file changed, 399 insertions(+) create mode 100644 megapixels/notebooks/datasets/mpii_pose/pose_mpi_clean_data.ipynb (limited to 'megapixels/notebooks/datasets/mpii_pose/pose_mpi_clean_data.ipynb') 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": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
crop_x1crop_x2crop_y1crop_y2elbow_left_xelbow_left_yelbow_right_xelbow_right_yhead_xhead_y...shoulder_left_xshoulder_left_yshoulder_right_xshoulder_right_yvideo_idwidthwrist_left_xwrist_left_ywrist_right_xwrist_right_y
01192011080277.721438192.416331147.628696169.326277195.49832081.471438...254.631384127.088374178.603159134.691196-osma2n86oA720278.566196235.498992158.047379122.301411
11192011080273.497648187.629368152.134073129.341062207.32493372.742272...254.349798131.593750181.137433123.990927-osma2n86oA720274.342406235.498992135.23891191.608535
21192011080258.010417159.752352160.581653143.138777229.00705676.966062...250.407594125.117272190.992944117.232863-osma2n86oA720213.801411108.785282181.98219189.074261
31192011080274.342406188.192540142.841734110.193212203.10114276.402890...253.786626128.777890185.361223120.611895-osma2n86oA720276.595094231.556788156.92103555.847110
41192011080272.371304194.387433225.628024164.820901245.90221893.016465...255.476142139.478159183.390121126.806788-osma2n86oA720305.316868172.423723278.284610165.102487
\n", + "

5 rows × 22 columns

\n", + "
" + ], + "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 +} -- cgit v1.2.3-70-g09d2