|
| 1 | +# Table of Contents |
| 2 | +- [Table of Contents](#table-of-contents) |
| 3 | + - [Pre-Requisites](#pre-requisites) |
| 4 | + - [Data](#data) |
| 5 | + - [Pre-Processing Data](#pre-processing-data) |
| 6 | + - [Generating Predictions](#generating-predictions) |
| 7 | + - [Training Your Own Model](#training-your-own-model) |
| 8 | + |
| 9 | +## Pre-Requisites |
| 10 | +You must be running on Python 3 with the following python packages installed. We also recommend using a machine that has GPU support. |
| 11 | + |
| 12 | + pip install "tensorflow-gpu>=1.13.0,<2.0" # for cpu use "tensorflow>=1.13.0,<2.0" |
| 13 | + pip install pandas |
| 14 | + pip install numpy |
| 15 | + |
| 16 | +## Data |
| 17 | +- **Accelerometer Data**: We assume the input data is obtained from ActiGraph GT3X device and converted into single .csv files. The files should be named as **<subject_id>.csv** and files for all subjects should be put in the same directory. First few lines of a sample csv file are as follows: |
| 18 | + ~~~ |
| 19 | + ------------ Data File Created By ActiGraph GT3X+ ActiLife v6.13.3 Firmware v3.2.1 date format M/d/yyyy at 30 Hz Filter Normal ----------- |
| 20 | + Serial Number: NEO1F18120387 |
| 21 | + Start Time 00:00:00 |
| 22 | + Start Date 5/7/2014 |
| 23 | + Epoch Period (hh:mm:ss) 00:00:00 |
| 24 | + Download Time 10:31:05 |
| 25 | + Download Date 5/20/2014 |
| 26 | + Current Memory Address: 0 |
| 27 | + Current Battery Voltage: 4.07 Mode = 12 |
| 28 | + -------------------------------------------------- |
| 29 | + Accelerometer X,Accelerometer Y,Accelerometer Z |
| 30 | + -0.182,-0.182,0.962 |
| 31 | + -0.182,-0.176,0.959 |
| 32 | + -0.179,-0.182,0.959 |
| 33 | + -0.179,-0.182,0.959 |
| 34 | + ~~~ |
| 35 | +
|
| 36 | +- **(Optional) Events Data**: Optionally, you can also provide ActivPal events data, especially if you wish to train your own models, for each subjects as a single .csv file. These files should also be named in the **<subject_id>.csv** format and files for all subjects should be put in the same directory. First few lines of a sample csv file are as follows: |
| 37 | + ~~~ |
| 38 | + StartTime,EndTime,Behavior |
| 39 | + 2014-05-07 09:47:23,2014-05-07 09:48:21,standingStill |
| 40 | + 2014-05-07 09:48:22,2014-05-07 09:48:26,walking/running |
| 41 | + 2014-05-07 09:48:27,2014-05-07 09:49:03,standingStill |
| 42 | + 2014-05-07 09:49:04,2014-05-07 09:49:04,walking/running |
| 43 | + 2014-05-07 09:49:05,2014-05-07 09:49:11,standingStill |
| 44 | + 2014-05-07 09:49:12,2014-05-07 09:49:15,walking/running |
| 45 | + ~~~ |
| 46 | +
|
| 47 | +## Pre-Processing Data |
| 48 | +First, you need to create pre-processed data from the source data. To do this invoke the `pre_process_data.py` script as follows: |
| 49 | +
|
| 50 | + python pre_process_data.py --gt3x-dir <gt3x_data_dir> --activpal-dir <activpal_data_dir> --pre-processed-dir <output_dir> |
| 51 | +
|
| 52 | +Complete usage details of this script are as follows: |
| 53 | +
|
| 54 | + usage: pre_process_data.py [-h] --gt3x-dir GT3X_DIR --pre-processed-dir |
| 55 | + PRE_PROCESSED_DIR [--activpal-dir ACTIVPAL_DIR] |
| 56 | + [--window-size WINDOW_SIZE] |
| 57 | + [--gt3x-frequency GT3X_FREQUENCY] |
| 58 | + [--activpal-label-map ACTIVPAL_LABEL_MAP] |
| 59 | + [--silent] |
| 60 | +
|
| 61 | + Argument parser for preprocessing the input data. |
| 62 | +
|
| 63 | + required arguments: |
| 64 | + --gt3x-dir GT3X_DIR GT3X data directory |
| 65 | + --pre-processed-dir PRE_PROCESSED_DIR |
| 66 | + Pre-processed data directory |
| 67 | +
|
| 68 | + optional arguments: |
| 69 | + -h, --help show this help message and exit |
| 70 | + --activpal-dir ACTIVPAL_DIR |
| 71 | + ActivPAL data directory |
| 72 | + --window-size WINDOW_SIZE |
| 73 | + Window size in seconds on which the predictions to be |
| 74 | + made |
| 75 | + --gt3x-frequency GT3X_FREQUENCY |
| 76 | + GT3X device frequency in Hz |
| 77 | + --activpal-label-map ACTIVPAL_LABEL_MAP |
| 78 | + ActivPal label vocabulary |
| 79 | + --silent Whether to hide info messages |
| 80 | +
|
| 81 | +## Generating Predictions |
| 82 | +You can use the released pre-trained models to generate predictions using your own data. To do so invoke the `make_predictions.py` as follows: |
| 83 | +
|
| 84 | + python make_predictions.py --pre-processed-dir <pre-processed-dir> --predictions-dir <predictions-dir> |
| 85 | +
|
| 86 | +Complete usage details of this script are as follows: |
| 87 | +
|
| 88 | + usage: make_predictions.py [-h] --pre-processed-dir PRE_PROCESSED_DIR |
| 89 | + [--predictions-dir PREDICTIONS_DIR] |
| 90 | + [--batch-size BATCH_SIZE] |
| 91 | + [--num-classes NUM_CLASSES] |
| 92 | + [--window-size WINDOW_SIZE] |
| 93 | + [--gt3x-frequency GT3X_FREQUENCY] [--no-label] |
| 94 | + [--model-checkpoint-path MODEL_CHECKPOINT_PATH] |
| 95 | + [--remove-gravity] [--silent] |
| 96 | +
|
| 97 | + Argument parser for generating model predictions. |
| 98 | +
|
| 99 | + required arguments: |
| 100 | + --pre-processed-dir PRE_PROCESSED_DIR |
| 101 | + Pre-processed data directory |
| 102 | +
|
| 103 | + optional arguments: |
| 104 | + -h, --help show this help message and exit |
| 105 | + --predictions-dir PREDICTIONS_DIR |
| 106 | + Training batch size |
| 107 | + --batch-size BATCH_SIZE |
| 108 | + Training batch size |
| 109 | + --num-classes NUM_CLASSES |
| 110 | + Number of classes in the training dataset |
| 111 | + --window-size WINDOW_SIZE |
| 112 | + Window size in seconds on which the predictions to be |
| 113 | + made |
| 114 | + --gt3x-frequency GT3X_FREQUENCY |
| 115 | + GT3X device frequency in Hz |
| 116 | + --no-label Whether to not output the label |
| 117 | + --model-checkpoint-path MODEL_CHECKPOINT_PATH |
| 118 | + Path where the trained model will be saved |
| 119 | + --remove-gravity Whether to remove gravity from accelerometer data |
| 120 | + --silent Whether to hide info messages |
| 121 | +
|
| 122 | +## Training Your Own Model |
| 123 | +To train your own model invoke the `train_model.py` as follows: |
| 124 | +
|
| 125 | + python --pre-processed-dir <pre-processed-dir> --model-checkpoint-path <checkpoint-dir> |
| 126 | +
|
| 127 | +Complete usage details of this script are as follows: |
| 128 | +
|
| 129 | + usage: train_model.py [-h] --pre-processed-dir PRE_PROCESSED_DIR |
| 130 | + [--learning-rate LEARNING_RATE] |
| 131 | + [--num-epochs NUM_EPOCHS] [--batch-size BATCH_SIZE] |
| 132 | + [--dropout-rate DROPOUT_RATE] |
| 133 | + [--shuffle-buffer-size SHUFFLE_BUFFER_SIZE] |
| 134 | + [--training-data-fraction TRAINING_DATA_FRACTION] |
| 135 | + [--validation-data-fraction VALIDATION_DATA_FRACTION] |
| 136 | + [--testing-data-fraction TESTING_DATA_FRACTION] |
| 137 | + [--model-checkpoint-path MODEL_CHECKPOINT_PATH] |
| 138 | + [--window-size WINDOW_SIZE] |
| 139 | + [--gt3x-frequency GT3X_FREQUENCY] |
| 140 | + [--num-classes NUM_CLASSES] |
| 141 | + [--class-weights CLASS_WEIGHTS] [--remove-gravity] |
| 142 | + [--silent] |
| 143 | +
|
| 144 | + Argument parser for training CNN model. |
| 145 | +
|
| 146 | + required arguments: |
| 147 | + --pre-processed-dir PRE_PROCESSED_DIR |
| 148 | + Pre-processed data directory |
| 149 | +
|
| 150 | + optional arguments: |
| 151 | + -h, --help show this help message and exit |
| 152 | + --learning-rate LEARNING_RATE |
| 153 | + Learning rate for training the model |
| 154 | + --num-epochs NUM_EPOCHS |
| 155 | + Number of epochs to train the model |
| 156 | + --batch-size BATCH_SIZE |
| 157 | + Training batch size |
| 158 | + --dropout-rate DROPOUT_RATE |
| 159 | + Dropout rate during training |
| 160 | + --shuffle-buffer-size SHUFFLE_BUFFER_SIZE |
| 161 | + Training data shuffle buffer size in terms of number |
| 162 | + of records |
| 163 | + --training-data-fraction TRAINING_DATA_FRACTION |
| 164 | + Percentage of subjects to be used for training |
| 165 | + --validation-data-fraction VALIDATION_DATA_FRACTION |
| 166 | + Percentage of subjects to be used for validation |
| 167 | + --testing-data-fraction TESTING_DATA_FRACTION |
| 168 | + Percentage of subjects to be used for testing |
| 169 | + --model-checkpoint-path MODEL_CHECKPOINT_PATH |
| 170 | + Path where the trained model will be saved |
| 171 | + --window-size WINDOW_SIZE |
| 172 | + Window size in seconds on which the predictions to be |
| 173 | + made |
| 174 | + --gt3x-frequency GT3X_FREQUENCY |
| 175 | + GT3X device frequency in Hz |
| 176 | + --num-classes NUM_CLASSES |
| 177 | + Number of classes in the training dataset |
| 178 | + --class-weights CLASS_WEIGHTS |
| 179 | + Class weights for loss aggregation |
| 180 | + --remove-gravity Whether to remove gravity from accelerometer data |
| 181 | + --silent Whether to hide info messages |
| 182 | +
|
| 183 | +Notice that this script relies on several hyperparameters required for training the model such as learning rate, batch size, and number of training epochs etc. The script comes with set of default values for these parameters. However, you may need to tweak these parameters for your dataset to get the best performance. |
| 184 | +
|
| 185 | +After training your own model you can use it to generate predictions by passing the model checkpoint path to the `make_predictions.py` script as follows: |
| 186 | +
|
| 187 | + python make_predictions.py --pre-processed-dir <pre-processed-dir> --predictions-dir <predictions-dir> --model-checkpoint-path <checkpoint-dir> |
0 commit comments