{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Full Pipeline for taking coordinates and classifying the reps" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import sys\n", "import os\n", "import pickle\n", "sys.path.append('..')\n", "sys.path.append('../inference')\n", "sys.path.append('../data')\n", "sys.path.append('../feedback')\n", "from ai_trainer import Personal_Trainer\n", "\n", "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Step 1: Instantiate personal trainer and load classifiers" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[SUCCESS] ---------- > Classifiers stored for squat\n", "[SUCCESS] ---------- > Classifiers stored for pushup\n" ] } ], "source": [ "pt = Personal_Trainer({'squat':'NeckY','pushup':'NeckY'})\n", "\n", "#=====[ Get classifiers from pickled file ]=====\n", "squat_classifiers = pickle.load(open(os.path.join('../inference/','squat_classifiers_ftopt.p'),'rb'))\n", "pushup_classifiers = pickle.load(open(os.path.join('../inference/','pushup_classifiers_ftopt.p'),'rb'))\n", "\n", "#=====[ Set classifiers for our trainer ]=====\n", "pt.set_classifiers('squat',squat_classifiers)\n", "pt.set_classifiers('pushup',pushup_classifiers)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Step 2: Analyze Reps from raw coordinate data file" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [ "squats = pt.analyze_reps('squat','../data/raw_data/squat_pushupData_10to20/squatData15.txt')\n", "# squats = pt.analyze_reps('squat','../data/raw_data/squat_pushupData_10to20/squatData15.txt')\n", "# pushups = pt.analyze_reps('pushup','../data/raw_data/squat_pushupData_10to20/pushupData12.txt')\n", "\n", "#=====[ Extract feature vectors from squats and pushups for each corresponding exercise component ]=====\n", "squat_feature_vectors = pt.get_prediction_features_opt('squat',squats)\n", "# pushup_feature_vectors = pt.get_prediction_features_opt('pushup',pushups)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[SUCCESS] ---------- > bend_hips_knees: reps classified\n", "\n", "bend_hips_knees :\n", "[0 0 0 0 0 0 0 0 0 0] \n", "\n", "[SUCCESS] ---------- > stance_width: reps classified\n", "\n", "stance_width :\n", "[-1 0 -1 -1 0 0 0 0 0 0] \n", "\n", "[SUCCESS] ---------- > squat_depth: reps classified\n", "\n", "squat_depth :\n", "[1 0 1 1 1 0 0 0 0 0] \n", "\n", "[SUCCESS] ---------- > knees_over_toes: reps classified\n", "\n", "knees_over_toes :\n", "[1 1 1 0 1 1 1 1 1 1] \n", "\n", "[SUCCESS] ---------- > back_hip_angle: reps classified\n", "\n", "back_hip_angle :\n", "[ 0 0 0 1 0 0 1 0 -1 0] \n", "\n" ] } ], "source": [ "#=====[ Run classification on each squat component and report results ]=====\n", "results = {}\n", "for key in squat_feature_vectors:\n", " X = squat_feature_vectors[key]\n", " classification = pt.classify('squat', key, X, verbose=True)\n", " results[key] = classification\n", " print '\\n', key ,':\\n', classification, '\\n'" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "A total of 10 reps were analyzed\n", "\n", "\n", "Major Problems:\n", "\n", "Knee and Toe Alignment:keep your knees behind your toes\n", "\n", "\n", "\n", "Minor Problems:\n", "\n", "Stance:keep feet shoulder width apart\n", "Depth:go deep on the squat\n", "\n", "\n", "\n", "Strengths:\n", "\n", "Hip and Knee Coordination\n", "\n" ] } ], "source": [ "pt.get_advice('squat',results)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#=====[ Run classification on each pushup component and report results ]=====\n", "# results = {}\n", "# for key in pushup_feature_vectors:\n", "# X = pushup_feature_vectors[key]\n", "# classification = pt.classify('pushup', key, X)\n", "# results[key] = classification\n", "# print '\\n', key ,':\\n', classification, '\\n'" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# pt.get_advice('pushup',results)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 0 }