File size: 2,738 Bytes
dbe02cf
 
47016a0
 
 
 
 
 
 
dbe02cf
47016a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: mit

tags:
  - keras
  - tensorflow
  - time-series-classification
  - sensor-data
  - deep-learning-lab
---

# Wearable Activity Classifier — CNN

## Model description
A 1D Convolutional Neural Network that classifies short wearable-sensor
sequences into three physical activities: **Stationary**, **Walking**,
and **Running**. Built as part of a beginner deep learning group lab
comparing CNN, SimpleRNN, LSTM, and a CNN+LSTM hybrid on the same
fixed dataset.

## Intended use
Educational demonstration of sequence classification on wearable
sensor data. Not intended for production health/fitness monitoring.

## Architecture

Input (100 time steps, 1 sensor channel)
→ Conv1D(32 filters, kernel_size=5, activation="relu")
→ MaxPooling1D(pool_size=2)
→ Flatten()
→ Dense(32, activation="relu")
→ Dense(3, activation="softmax")

**Total parameters:** 49,475

## Training data
Fixed `Wearable_Activity_Dataset` release (seed 42 split): 600 training
sequences, 150 validation, 150 test — each sequence is 100 time steps
of a single sensor reading. Training set is perfectly class-balanced
(200 Stationary / 200 Walking / 200 Running).

## Training procedure
- Optimizer: Adam (default learning rate)
- Loss: sparse categorical crossentropy
- Epochs: 6, batch size: 32
- Same training configuration used across all four models in this lab,
  for a fair comparison

## Evaluation results

| Model | Test Accuracy | Parameters | Train Time (s) |
|---|---|---|---|
| CNN | 1.000 | 49,475 | 2.81 |
| SimpleRNN | 0.580 | 1,187 | 4.77 |
| LSTM | 0.693 | 4,451 | 7.12 |
| CNN+LSTM (hybrid) | 1.000 | 8,611 | 6.35 |

## Limitations
- Trained on a small, synthetic/fixed dataset — accuracy may not
  generalize to real-world wearable sensor data with more noise,
  sensor drift, or additional activity classes
- Only 6 training epochs — SimpleRNN and LSTM in particular likely
  hadn't converged; their reported accuracy understates what they
  could achieve with more training
- Fixed 100-step sequence length — not tested on longer or
  variable-length sequences

## How to use
```python
import tensorflow as tf
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Conv1D, MaxPooling1D, Flatten, Dense

model = Sequential([
    Conv1D(32, kernel_size=5, activation="relu", input_shape=(100, 1)),
    MaxPooling1D(pool_size=2),
    Flatten(),
    Dense(32, activation="relu"),
    Dense(3, activation="softmax")
])
model.load_weights("activity_model.weights.h5")

# X: numpy array of shape (n_samples, 100, 1)
predictions = model.predict(X)
```

## Authors
Group lab submission — [Group 6 - Iqra University Main Campus], CNN–RNN–LSTM Model
Challenge, Beginner Deep Learning Group Lab.