Instructions to use hamzaN1/CNN-Model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use hamzaN1/CNN-Model with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://hamzaN1/CNN-Model") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,89 @@
|
|
| 1 |
---
|
| 2 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
+
|
| 4 |
+
tags:
|
| 5 |
+
- keras
|
| 6 |
+
- tensorflow
|
| 7 |
+
- time-series-classification
|
| 8 |
+
- sensor-data
|
| 9 |
+
- deep-learning-lab
|
| 10 |
---
|
| 11 |
+
|
| 12 |
+
# Wearable Activity Classifier — CNN
|
| 13 |
+
|
| 14 |
+
## Model description
|
| 15 |
+
A 1D Convolutional Neural Network that classifies short wearable-sensor
|
| 16 |
+
sequences into three physical activities: **Stationary**, **Walking**,
|
| 17 |
+
and **Running**. Built as part of a beginner deep learning group lab
|
| 18 |
+
comparing CNN, SimpleRNN, LSTM, and a CNN+LSTM hybrid on the same
|
| 19 |
+
fixed dataset.
|
| 20 |
+
|
| 21 |
+
## Intended use
|
| 22 |
+
Educational demonstration of sequence classification on wearable
|
| 23 |
+
sensor data. Not intended for production health/fitness monitoring.
|
| 24 |
+
|
| 25 |
+
## Architecture
|
| 26 |
+
|
| 27 |
+
Input (100 time steps, 1 sensor channel)
|
| 28 |
+
→ Conv1D(32 filters, kernel_size=5, activation="relu")
|
| 29 |
+
→ MaxPooling1D(pool_size=2)
|
| 30 |
+
→ Flatten()
|
| 31 |
+
→ Dense(32, activation="relu")
|
| 32 |
+
→ Dense(3, activation="softmax")
|
| 33 |
+
|
| 34 |
+
**Total parameters:** 49,475
|
| 35 |
+
|
| 36 |
+
## Training data
|
| 37 |
+
Fixed `Wearable_Activity_Dataset` release (seed 42 split): 600 training
|
| 38 |
+
sequences, 150 validation, 150 test — each sequence is 100 time steps
|
| 39 |
+
of a single sensor reading. Training set is perfectly class-balanced
|
| 40 |
+
(200 Stationary / 200 Walking / 200 Running).
|
| 41 |
+
|
| 42 |
+
## Training procedure
|
| 43 |
+
- Optimizer: Adam (default learning rate)
|
| 44 |
+
- Loss: sparse categorical crossentropy
|
| 45 |
+
- Epochs: 6, batch size: 32
|
| 46 |
+
- Same training configuration used across all four models in this lab,
|
| 47 |
+
for a fair comparison
|
| 48 |
+
|
| 49 |
+
## Evaluation results
|
| 50 |
+
|
| 51 |
+
| Model | Test Accuracy | Parameters | Train Time (s) |
|
| 52 |
+
|---|---|---|---|
|
| 53 |
+
| CNN | 1.000 | 49,475 | 2.81 |
|
| 54 |
+
| SimpleRNN | 0.580 | 1,187 | 4.77 |
|
| 55 |
+
| LSTM | 0.693 | 4,451 | 7.12 |
|
| 56 |
+
| CNN+LSTM (hybrid) | 1.000 | 8,611 | 6.35 |
|
| 57 |
+
|
| 58 |
+
## Limitations
|
| 59 |
+
- Trained on a small, synthetic/fixed dataset — accuracy may not
|
| 60 |
+
generalize to real-world wearable sensor data with more noise,
|
| 61 |
+
sensor drift, or additional activity classes
|
| 62 |
+
- Only 6 training epochs — SimpleRNN and LSTM in particular likely
|
| 63 |
+
hadn't converged; their reported accuracy understates what they
|
| 64 |
+
could achieve with more training
|
| 65 |
+
- Fixed 100-step sequence length — not tested on longer or
|
| 66 |
+
variable-length sequences
|
| 67 |
+
|
| 68 |
+
## How to use
|
| 69 |
+
```python
|
| 70 |
+
import tensorflow as tf
|
| 71 |
+
from tensorflow.keras import Sequential
|
| 72 |
+
from tensorflow.keras.layers import Conv1D, MaxPooling1D, Flatten, Dense
|
| 73 |
+
|
| 74 |
+
model = Sequential([
|
| 75 |
+
Conv1D(32, kernel_size=5, activation="relu", input_shape=(100, 1)),
|
| 76 |
+
MaxPooling1D(pool_size=2),
|
| 77 |
+
Flatten(),
|
| 78 |
+
Dense(32, activation="relu"),
|
| 79 |
+
Dense(3, activation="softmax")
|
| 80 |
+
])
|
| 81 |
+
model.load_weights("activity_model.weights.h5")
|
| 82 |
+
|
| 83 |
+
# X: numpy array of shape (n_samples, 100, 1)
|
| 84 |
+
predictions = model.predict(X)
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
## Authors
|
| 88 |
+
Group lab submission — [Group 6 - Iqra University Main Campus], CNN–RNN–LSTM Model
|
| 89 |
+
Challenge, Beginner Deep Learning Group Lab.
|