Ejemplo n.º 1
0
'''
See paper:  Sensors 2018, 18(4), 1055; https://doi.org/10.3390/s18041055
"Divide and Conquer-Based 1D CNN Human Activity Recognition Using Test Data Sharpening"
by Heeryon Cho & Sang Min Yoon

This code investigates the effects of test data sharpening on 
1D CNN End-to-End activity classification model using LOWER body VALIDATION data.

The performance is measured using X_valid, y_valid dataset.

See left line graph in Figure 14 (a) (Validation Data Recognition Accuracy). 
(Sensors 2018, 18(4), 1055, page 16 of 24)
'''

X_train, y_train, X_valid, y_valid, X_test, y_test = sd.load_data("lower", "end2end")

print "\n=== COMPARE ACCURACY: NO SHARPEN vs. SHARPENED  ==="
print "===   [LOWER body sensors data] End2End Class   ==="
print "===                1D CNN  MODEL                ==="
print "===       Evaluation on VALIDATION DATA         ===\n"

# Load model
model = load_model('model/lower_end2end.hdf5')

print ">>> RAW:"
pred = model.predict(np.expand_dims(X_valid, axis=2), batch_size=32)
print accuracy_score(y_valid, np.argmax(pred, axis=1))
print confusion_matrix(y_valid, np.argmax(pred, axis=1)), '\n'

alpha = np.arange(0.5, 3.5, 0.5)
Ejemplo n.º 2
0
import select_data as sd

import warnings
warnings.simplefilter(action='ignore', category=UserWarning)

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
'''
See paper:  Sensors 2018, 18(4), 1055; https://doi.org/10.3390/s18041055
"Divide and Conquer-Based 1D CNN Human Activity Recognition Using Test Data Sharpening"
by Heeryon Cho & Sang Min Yoon

This code learns DOWN position activity classification model using LOWER body sensors data.
'''

X_train, y_train, X_valid, y_valid, X_test, y_test = sd.load_data(
    "lower", "down")

n_classes = 2

# Generates one-hot encoding of the activity labels
y_train_oh = np.eye(n_classes)[y_train]
y_test_oh = np.eye(n_classes)[y_test]
y_valid_oh = np.eye(n_classes)[y_valid]

# Fit 1D CNN
k_init = TruncatedNormal(mean=0.0, stddev=0.001, seed=2017)

seed(2017)
model = Sequential()
model.add(
    Conv1D(100,
Ejemplo n.º 3
0
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
'''
See paper:  Sensors 2018, 18(4), 1055; https://doi.org/10.3390/s18041055
"Divide and Conquer-Based 1D CNN Human Activity Recognition Using Test Data Sharpening"
by Heeryon Cho & Sang Min Yoon

This code investigates the effects of test data sharpening on 
1D CNN UP position activity classification model using UPPER body TEST data.

The performance is measured using X_test, y_test dataset.

See right line graph in Figure 13 (Test Data Recognition Accuracy). 
(Sensors 2018, 18(4), 1055, page 16 of 24)
'''

X_train, y_train, X_valid, y_valid, X_test, y_test = sd.load_data(
    "upper", "up")

print "\n=== COMPARE ACCURACY: NO SHARPEN vs. SHARPENED  ==="
print "===     [UPPER body sensors data] UP Class      ==="
print "===                1D CNN  MODEL                ==="
print "===          Evaluation on TEST DATA            ===\n"

# Load model
model = load_model('model/upper_up.hdf5')

print ">>> RAW:"
pred = model.predict(np.expand_dims(X_test, axis=2), batch_size=32)
print accuracy_score(y_test, np.argmax(pred, axis=1))
print confusion_matrix(y_test, np.argmax(pred, axis=1)), '\n'

alpha = np.arange(0.5, 15.5, 0.5)
Ejemplo n.º 4
0
See bar graph with 1D CNN in Figure 15, blue bars indicating Upper Body Sensors data. 
(Sensors 2018, 18(4), 1055, page 17 of 24)

'''

print "========================================================="
print "   Outputs performance of 1D CNN using UPPER body sensors data"
print "   On various 2-class & 4-class classification tasks:"
print "   end2end, abst, up, & down."
print "========================================================="

sensor_data_type = "upper"
model_list = ['end2end', 'abst', 'up', 'down']

for m in model_list:
    X_train, y_train, X_valid, y_valid, X_test, y_test = sd.load_data(
        sensor_data_type, m)
    model_path = "model/{}_{}.hdf5".format(sensor_data_type, m)
    model = load_model(model_path)
    pred = model.predict(np.expand_dims(X_test, axis=2), batch_size=32)
    print "\n-------------------------------------"
    print ">>> Test ACC [{}_{}]".format(sensor_data_type, m)
    print accuracy_score(y_test, np.argmax(pred, axis=1))
    print confusion_matrix(y_test, np.argmax(pred, axis=1))
    del model
    K.clear_session()
'''
/usr/bin/python2.7 /home/hcilab/Documents/OSS/sensors2018cnnhar/opp/eval_model_upper.py
/home/hcilab/.local/lib/python2.7/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
=========================================================
Ejemplo n.º 5
0
import warnings
warnings.simplefilter(action='ignore', category=UserWarning)

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

'''
See paper:  Sensors 2018, 18(4), 1055; https://doi.org/10.3390/s18041055
"Divide and Conquer-Based 1D CNN Human Activity Recognition Using Test Data Sharpening"
by Heeryon Cho & Sang Min Yoon

This code learns DOWN position activity classification model using RAW (lower) sensor data.
'''

X_train, y_train, X_valid, y_valid, X_test, y_test = sd.load_data("raw", "down")

n_classes = 2

# Generates one-hot encoding of the activity labels
y_train_oh = np.eye(n_classes)[y_train]
y_test_oh = np.eye(n_classes)[y_test]
y_valid_oh = np.eye(n_classes)[y_valid]

# Fit 1d CNN
k_init = TruncatedNormal(mean=0.0, stddev=0.001, seed=2017)

seed(2017)
model = Sequential()
model.add(Conv1D(100, 3, input_shape=(585, 1), activation='relu', kernel_initializer=k_init))
model.add(MaxPooling1D(3, strides=1))
Ejemplo n.º 6
0
(Sensors 2018, 18(4), 1055, page 17 of 24)

'''


print "========================================================="
print "   Outputs performance of other ML techniques, namely,"
print "   Logistic Regression & Random Forest"
print "   Using LOWER body sensors data."
print "========================================================="

print "\n==========================="
print "      [LOWER] 4-Class"
print "===========================\n"

X_train, y_train, X_valid, y_valid, X_test, y_test = sd.load_data("lower", "end2end")

clf_lr = LogisticRegression(random_state=2018)
clf_lr.fit(X_train, y_train)
pred_lr = clf_lr.predict(X_test)
print "--- Logistic Regression ---"
print "Test Acc: ", accuracy_score(y_test, pred_lr)
print confusion_matrix(y_test, pred_lr), '\n'

clf_dt = RandomForestClassifier(random_state=2018, max_depth=5, n_estimators=10, max_features=1)
clf_dt.fit(X_train, y_train)
pred_dt = clf_dt.predict(X_test)
print "\n------ Random Forest ------"
print "Test Acc: ", accuracy_score(y_test, pred_dt)
print confusion_matrix(y_test, pred_dt)
Ejemplo n.º 7
0
import warnings
warnings.simplefilter(action='ignore', category=UserWarning)

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

'''
See paper:  Sensors 2018, 18(4), 1055; https://doi.org/10.3390/s18041055
"Divide and Conquer-Based 1D CNN Human Activity Recognition Using Test Data Sharpening"
by Heeryon Cho & Sang Min Yoon

This code learns ABSTract activity classification model using RAW (lower) sensor data.
'''

X_train, y_train, X_valid, y_valid, X_test, y_test = sd.load_data("raw", "abst")

n_classes = 2

# Generates one-hot encoding of the activity labels
y_train_oh = np.eye(n_classes)[y_train]
y_test_oh = np.eye(n_classes)[y_test]
y_valid_oh = np.eye(n_classes)[y_valid]

# Fit 1d CNN
k_init = TruncatedNormal(mean=0.0, stddev=0.025, seed=2017)

seed(2017)
model = Sequential()
model.add(Conv1D(30, 2, input_shape=(585, 1), activation='relu', kernel_initializer=k_init))
model.add(Conv1D(50, 2, activation='relu', kernel_initializer=k_init))