{ "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", " | crop_x1 | \n", "crop_x2 | \n", "crop_y1 | \n", "crop_y2 | \n", "elbow_left_x | \n", "elbow_left_y | \n", "elbow_right_x | \n", "elbow_right_y | \n", "head_x | \n", "head_y | \n", "... | \n", "shoulder_left_x | \n", "shoulder_left_y | \n", "shoulder_right_x | \n", "shoulder_right_y | \n", "video_id | \n", "width | \n", "wrist_left_x | \n", "wrist_left_y | \n", "wrist_right_x | \n", "wrist_right_y | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "1 | \n", "1920 | \n", "1 | \n", "1080 | \n", "277.721438 | \n", "192.416331 | \n", "147.628696 | \n", "169.326277 | \n", "195.498320 | \n", "81.471438 | \n", "... | \n", "254.631384 | \n", "127.088374 | \n", "178.603159 | \n", "134.691196 | \n", "-osma2n86oA | \n", "720 | \n", "278.566196 | \n", "235.498992 | \n", "158.047379 | \n", "122.301411 | \n", "
| 1 | \n", "1 | \n", "1920 | \n", "1 | \n", "1080 | \n", "273.497648 | \n", "187.629368 | \n", "152.134073 | \n", "129.341062 | \n", "207.324933 | \n", "72.742272 | \n", "... | \n", "254.349798 | \n", "131.593750 | \n", "181.137433 | \n", "123.990927 | \n", "-osma2n86oA | \n", "720 | \n", "274.342406 | \n", "235.498992 | \n", "135.238911 | \n", "91.608535 | \n", "
| 2 | \n", "1 | \n", "1920 | \n", "1 | \n", "1080 | \n", "258.010417 | \n", "159.752352 | \n", "160.581653 | \n", "143.138777 | \n", "229.007056 | \n", "76.966062 | \n", "... | \n", "250.407594 | \n", "125.117272 | \n", "190.992944 | \n", "117.232863 | \n", "-osma2n86oA | \n", "720 | \n", "213.801411 | \n", "108.785282 | \n", "181.982191 | \n", "89.074261 | \n", "
| 3 | \n", "1 | \n", "1920 | \n", "1 | \n", "1080 | \n", "274.342406 | \n", "188.192540 | \n", "142.841734 | \n", "110.193212 | \n", "203.101142 | \n", "76.402890 | \n", "... | \n", "253.786626 | \n", "128.777890 | \n", "185.361223 | \n", "120.611895 | \n", "-osma2n86oA | \n", "720 | \n", "276.595094 | \n", "231.556788 | \n", "156.921035 | \n", "55.847110 | \n", "
| 4 | \n", "1 | \n", "1920 | \n", "1 | \n", "1080 | \n", "272.371304 | \n", "194.387433 | \n", "225.628024 | \n", "164.820901 | \n", "245.902218 | \n", "93.016465 | \n", "... | \n", "255.476142 | \n", "139.478159 | \n", "183.390121 | \n", "126.806788 | \n", "-osma2n86oA | \n", "720 | \n", "305.316868 | \n", "172.423723 | \n", "278.284610 | \n", "165.102487 | \n", "
5 rows × 22 columns
\n", "