-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_me.py
More file actions
115 lines (93 loc) · 4.8 KB
/
run_me.py
File metadata and controls
115 lines (93 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
import DataPreprocessing as dp
import FeatureExtraction as fe
import NeuralNetClassifier as nnc
import RandomForestClassifier as rfc
import ClassifierHelperFunctions as hf
import sys
import os
import time
import datetime
print '\nACTIVITY/SPORT CLASSIFICATION USING SENSOR DATA'
# Log parameters
verbose = False
show_val_acc = True
# Fixed parameters
sports = ['Badminton','Basketball','Foosball','Running','Skating','Walking']
channels = 6
pca_whiten = True
trimLength = 15
hidden_sizes = [1024,1024]
# Variable parameters
numSecondsPerImage_options = [15, 30]
fftWidth_options = [4, 6]
fftJump_options = [1]
num_pca_components_options = [100, 200]
algo_switch_options = [0, 1, 2, 3]
for algoSwitch in algo_switch_options:
################################################################
# !!! SHOULD RESET THIS AT THE END !!!
# Set up printing out a log (redirects all prints to the file)
orig_stdout = sys.stdout
f_log_name = '../Results/' + os.path.basename(__file__) \
+ '_' \
+ datetime.datetime.fromtimestamp(time.time()).strftime('%Y%m%d_%H%M%S') \
+ '.log'
logger = hf.Logger(f_log_name)
sys.stdout = logger
for numSecondsPerImage in numSecondsPerImage_options:
if algoSwitch <= 1:
dp.data_preprocessing(sports=sports, secondsToKeep=numSecondsPerImage, trimLength=trimLength,
switchAlgo=algoSwitch)
if algoSwitch == 2:
dp.data_preprocessing(sports=sports, secondsToKeep=numSecondsPerImage, trimLength=trimLength,
switchAlgo=0)
dp.data_preprocessing(sports=sports, secondsToKeep=numSecondsPerImage, trimLength=trimLength,
switchAlgo=algoSwitch)
if algoSwitch == 3:
dp.data_preprocessing(sports=sports, secondsToKeep=numSecondsPerImage, trimLength=trimLength,
switchAlgo=4)
dp.data_preprocessing(sports=sports, secondsToKeep=numSecondsPerImage, trimLength=trimLength,
switchAlgo=algoSwitch)
for fftWidth in fftWidth_options:
for fftJump in fftJump_options:
fe.feature_extraction(sports=sports, numSecondsPerImage=numSecondsPerImage, fftWidth=fftWidth,
fftJump=fftJump, finalOrNew=0)
if algoSwitch > 1:
fe.feature_extraction(sports=sports, numSecondsPerImage=numSecondsPerImage, fftWidth=fftWidth,
fftJump=fftJump, finalOrNew=1)
for num_pca_components in num_pca_components_options:
# Derived parameters
freqDims = 50 * fftWidth / 2
timeDims = (numSecondsPerImage - fftWidth) / fftJump + 1
# Log current run parameters
print 'algoSwitch =', algoSwitch
print 'sports =', sports
print 'trimLength =', trimLength
print 'numSecondsPerImage =', numSecondsPerImage
print 'fftWidth =', fftWidth
print 'fftJump =', fftJump
print 'channels =', channels
print 'num_pca_components =', num_pca_components
print 'pca_whiten =', pca_whiten
print 'hidden_sizes =', hidden_sizes
print 'verbose =', verbose
print 'show_val_acc =', show_val_acc
print 'freqDims =', freqDims
print 'timeDims =', timeDims
# CLASSIFIERS
nnc.run_neural_net_classifier(sports=sports, freqDims=freqDims, timeDims=timeDims,
channels=channels, num_pca_components=num_pca_components,
pca_whiten=pca_whiten, hidden_sizes=hidden_sizes, verbose=verbose,
show_val_acc=show_val_acc, algoSwitch=algoSwitch)
rfc.run_random_forest_classifier(sports=sports, featuresFile='../Data/featuresFinal.csv',
labelsFile='../Data/labelsFinal.csv', freqDims=freqDims,
timeDims=timeDims, channels=channels,
num_pca_components=num_pca_components, pca_whiten=pca_whiten,
algoSwitch=algoSwitch)
################################################################
# !!! RESETTING STDOUT LOGGING !!!
# Stop redirecting pring out to log
logger.close_log()
sys.stdout = orig_stdout