forked from stevenzchen/pose-trainer
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1998027
commit 42d7582
Showing
15 changed files
with
2,822 additions
and
1,930 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 was deleted.
Oops, something went wrong.
776 changes: 0 additions & 776 deletions
776
.ipynb_checkpoints/analysis_shoulderpress-checkpoint.ipynb
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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,146 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"import math\n", | ||
"import glob\n", | ||
"import utils\n", | ||
"\n", | ||
"from parse import load_ps\n", | ||
"from pprint import pprint\n", | ||
"from scipy.signal import medfilt\n", | ||
"from sklearn.model_selection import train_test_split\n", | ||
"from sklearn.neighbors import KNeighborsClassifier\n", | ||
"from sklearn.neighbors import DistanceMetric\n", | ||
"from sklearn.metrics import classification_report" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"files = utils.files_in_order('poses_compressed/frontraise')\n", | ||
"X_train_names, X_test_names = train_test_split(files, test_size=0.4, random_state=42)\n", | ||
"y_train = utils.get_labels(X_train_names)\n", | ||
"y_test = utils.get_labels(X_test_names)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def load_features(names):\n", | ||
" output1 = [] # List of torso-arm vectors\n", | ||
" for filename in names:\n", | ||
" ps = load_ps('poses_compressed/frontraise/'+filename)\n", | ||
" poses = ps.poses\n", | ||
"\n", | ||
" right_present = [1 for pose in poses \n", | ||
" if pose.rshoulder.exists and pose.relbow.exists and pose.rwrist.exists]\n", | ||
" left_present = [1 for pose in poses\n", | ||
" if pose.lshoulder.exists and pose.lelbow.exists and pose.lwrist.exists]\n", | ||
" right_count = sum(right_present)\n", | ||
" left_count = sum(left_present)\n", | ||
" side = 'right' if right_count > left_count else 'left'\n", | ||
"\n", | ||
" if side == 'right':\n", | ||
" joints = [(pose.rshoulder, pose.relbow, pose.rwrist, pose.rhip, pose.neck) for pose in poses]\n", | ||
" else:\n", | ||
" joints = [(pose.lshoulder, pose.lelbow, pose.lwrist, pose.lhip, pose.neck) for pose in poses]\n", | ||
"\n", | ||
" # filter out data points where a part does not exist\n", | ||
" joints = [joint for joint in joints if all(part.exists for part in joint)]\n", | ||
" joints = np.array(joints)\n", | ||
" \n", | ||
" # Shoulder to hip \n", | ||
" torso_vecs = np.array([(joint[0].x - joint[3].x, joint[0].y - joint[3].y) for joint in joints])\n", | ||
" # Arm\n", | ||
" arm_vecs = np.array([(joint[0].x - joint[2].x, joint[0].y - joint[2].y) for joint in joints])\n", | ||
"\n", | ||
" # normalize vectors\n", | ||
" torso_vecs = torso_vecs / np.expand_dims(np.linalg.norm(torso_vecs, axis=1), axis=1)\n", | ||
" arm_vecs = arm_vecs / np.expand_dims(np.linalg.norm(arm_vecs, axis=1), axis=1)\n", | ||
" \n", | ||
" angles = np.degrees(np.arccos(np.clip(np.sum(np.multiply(torso_vecs, arm_vecs), axis=1), -1.0, 1.0)))\n", | ||
" \n", | ||
" output1.append(angles.tolist())\n", | ||
" return output1\n", | ||
"\n", | ||
"X_train_1 = load_features(X_train_names)\n", | ||
"X_test_1 = load_features(X_test_names)\n", | ||
"#features = load_features(files)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
" precision recall f1-score support\n", | ||
"\n", | ||
" correct 1.00 1.00 1.00 6\n", | ||
" incorrect 1.00 1.00 1.00 6\n", | ||
"\n", | ||
"avg / total 1.00 1.00 1.00 12\n", | ||
"\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"predictions = []\n", | ||
"for example in range(len(X_test_names)):\n", | ||
" # Store the average distance to good and bad training examples\n", | ||
" f1_good, f1_bad = [[] for i in range(2)]\n", | ||
" \n", | ||
" # Compare distance of current test example with all training examples\n", | ||
" for i in range(len(X_train_1)):\n", | ||
" dist1 = utils.DTWDistance(X_train_1[i], X_test_1[example])\n", | ||
" if y_train[i]:\n", | ||
" f1_good.append(dist1)\n", | ||
" else:\n", | ||
" f1_bad.append(dist1)\n", | ||
" good_score = np.mean(f1_good)\n", | ||
" bad_score = np.mean(f1_bad)\n", | ||
" if good_score < bad_score:\n", | ||
" predictions.append(1)\n", | ||
" else:\n", | ||
" predictions.append(0)\n", | ||
"print(classification_report(y_test, predictions, target_names=['correct', 'incorrect']))" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.5.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
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
Oops, something went wrong.