import sys
import os
import pickle
sys.path.append('..')
sys.path.append('../inference')
sys.path.append('../data')
sys.path.append('../feedback')
from ai_trainer import Personal_Trainer
%load_ext autoreload
%autoreload 2
pt = Personal_Trainer({'squat':'NeckY','pushup':'NeckY'})
#=====[ Get classifiers from pickled file ]=====
squat_classifiers = pickle.load(open(os.path.join('../inference/','squat_classifiers_ftopt.p'),'rb'))
pushup_classifiers = pickle.load(open(os.path.join('../inference/','pushup_classifiers_ftopt.p'),'rb'))
#=====[ Set classifiers for our trainer ]=====
pt.set_classifiers('squat',squat_classifiers)
pt.set_classifiers('pushup',pushup_classifiers)
[SUCCESS] ---------- > Classifiers stored for squat [SUCCESS] ---------- > Classifiers stored for pushup
squats = pt.analyze_reps('squat','../data/raw_data/squat_pushupData_10to20/squatData15.txt')
# squats = pt.analyze_reps('squat','../data/raw_data/squat_pushupData_10to20/squatData15.txt')
# pushups = pt.analyze_reps('pushup','../data/raw_data/squat_pushupData_10to20/pushupData12.txt')
#=====[ Extract feature vectors from squats and pushups for each corresponding exercise component ]=====
squat_feature_vectors = pt.get_prediction_features_opt('squat',squats)
# pushup_feature_vectors = pt.get_prediction_features_opt('pushup',pushups)
#=====[ Run classification on each squat component and report results ]=====
results = {}
for key in squat_feature_vectors:
X = squat_feature_vectors[key]
classification = pt.classify('squat', key, X, verbose=True)
results[key] = classification
print '\n', key ,':\n', classification, '\n'
[SUCCESS] ---------- > bend_hips_knees: reps classified bend_hips_knees : [0 0 0 0 0 0 0 0 0 0] [SUCCESS] ---------- > stance_width: reps classified stance_width : [-1 0 -1 -1 0 0 0 0 0 0] [SUCCESS] ---------- > squat_depth: reps classified squat_depth : [1 0 1 1 1 0 0 0 0 0] [SUCCESS] ---------- > knees_over_toes: reps classified knees_over_toes : [1 1 1 0 1 1 1 1 1 1] [SUCCESS] ---------- > back_hip_angle: reps classified back_hip_angle : [ 0 0 0 1 0 0 1 0 -1 0]
pt.get_advice('squat',results)
A total of 10 reps were analyzed Major Problems: Knee and Toe Alignment:keep your knees behind your toes Minor Problems: Stance:keep feet shoulder width apart Depth:go deep on the squat Strengths: Hip and Knee Coordination
#=====[ Run classification on each pushup component and report results ]=====
# results = {}
# for key in pushup_feature_vectors:
# X = pushup_feature_vectors[key]
# classification = pt.classify('pushup', key, X)
# results[key] = classification
# print '\n', key ,':\n', classification, '\n'
# pt.get_advice('pushup',results)