Add ONNX exports (7 stages, 1.4GB) for Jetson Nano inference
Browse files- README.md +68 -70
- onnx/feature_adapter.onnx +3 -0
- onnx/history_encoder.onnx +3 -0
- onnx/hourslot_encoder.onnx +3 -0
- onnx/minute_encoder.onnx +3 -0
- onnx/output_heads.onnx +3 -0
- onnx/patch_encoder.onnx +3 -0
- onnx/vitalguard.onnx +3 -0
README.md
CHANGED
|
@@ -8,17 +8,60 @@ tags:
|
|
| 8 |
- imu
|
| 9 |
- heart-rate
|
| 10 |
- edge-deployment
|
|
|
|
|
|
|
| 11 |
license: mit
|
| 12 |
---
|
| 13 |
|
| 14 |
-
# SISA-RoutineGuard v5b
|
| 15 |
|
| 16 |
-
**노인 일상 패턴 이상 감지
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
Train/val split + early stopping 적용한 production ckpt.
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
| Component | Params | Deploy |
|
| 24 |
|---|---:|---|
|
|
@@ -32,9 +75,9 @@ Train/val split + early stopping 적용한 production ckpt.
|
|
| 32 |
| OutputHeads | 1.58M | Jetson |
|
| 33 |
| **Total** | **444.66M** | — |
|
| 34 |
|
| 35 |
-
## 성능 (OOD: HAR-70+ 노인 70-95세, 학습 X)
|
| 36 |
|
| 37 |
-
| 시나리오 |
|
| 38 |
|---|---:|---:|---:|
|
| 39 |
| Normal | 0.0004 | — | — |
|
| 40 |
| walk_missing | 0.9995 | **1.000** | 0% |
|
|
@@ -43,75 +86,30 @@ Train/val split + early stopping 적용한 production ckpt.
|
|
| 43 |
| activity_drop | 0.7145 | 0.950 | 28% |
|
| 44 |
| **Overall** | — | **0.987** | — |
|
| 45 |
|
| 46 |
-
## Train/Val Split + Early Stopping
|
| 47 |
|
| 48 |
-
- Train/Val: 80/20
|
| 49 |
-
- Train samples: 3,277 / Val: 819
|
| 50 |
- **Best epoch = 1, val_loss = 0.2814** (saved)
|
| 51 |
- Early stop at epoch 13 (patience=10)
|
|
|
|
| 52 |
|
| 53 |
-
## 학습
|
| 54 |
-
|
| 55 |
-
| Dataset | Subjects | Duration | Stage |
|
| 56 |
-
|---|---:|---|---|
|
| 57 |
-
| CAPTURE-24 | 151명 | 24h wrist 100Hz | 1, 2 |
|
| 58 |
-
| ArWISE V3 | 10명 | 9일, 76일 raw | 1, 3, 4, 5 |
|
| 59 |
-
| PPG-DaLiA | 15명 | 2.5h wrist | 6 |
|
| 60 |
-
| WESAD | 15명 | 1.7h wrist+chest | 6 |
|
| 61 |
-
| MHEALTH | 10명 | 53m 23ch | 6 |
|
| 62 |
-
| **HAR-70+** | **18명 70-95세** | **테스트만 (OOD)** | — |
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
```python
|
| 67 |
-
import torch
|
| 68 |
-
from src.models.full_model import SISARoutineGuard
|
| 69 |
-
|
| 70 |
-
model = SISARoutineGuard().cuda().eval()
|
| 71 |
-
state = torch.load("stage5_full.pt", map_location="cpu")["model"]
|
| 72 |
-
model.load_state_dict(state, strict=False)
|
| 73 |
-
vg = torch.load("stage6_vitalguard.pt", map_location="cpu")["model"]
|
| 74 |
-
model.vitalguard.load_state_dict(vg, strict=False)
|
| 75 |
-
|
| 76 |
-
# forward_replay (90 history × 60 min + 3 today × 60 min)
|
| 77 |
-
out = model.forward_replay(history_features_norm, today_features_norm,
|
| 78 |
-
day_offset, slot_pos, day_type,
|
| 79 |
-
history_mask, today_mask)
|
| 80 |
-
# 448 ms / batch=2 on RTX 4090
|
| 81 |
-
```
|
| 82 |
-
|
| 83 |
-
## ONNX (Phone deploy)
|
| 84 |
-
```python
|
| 85 |
-
import onnxruntime as ort
|
| 86 |
-
sess = ort.InferenceSession("patch_encoder.onnx", providers=["CPUExecutionProvider"])
|
| 87 |
-
out = sess.run(None, {"acc": acc_array}) # [6, 250, 3] → [6, 256]
|
| 88 |
-
```
|
| 89 |
-
|
| 90 |
-
## Files
|
| 91 |
-
| File | Size | Stage |
|
| 92 |
|---|---:|---|
|
| 93 |
-
| stage1_patch.pt | 879 KB |
|
| 94 |
-
| stage2_minute.pt | 192 MB |
|
| 95 |
-
| stage2_adapter.pt | 2.7 MB |
|
| 96 |
-
| stage3_hourslot.pt | 570 MB |
|
| 97 |
-
| stage4_history.pt | 567 MB |
|
| 98 |
-
| stage4_refiner.pt | 390 MB |
|
| 99 |
-
|
|
| 100 |
-
| stage6_vitalguard.pt | 48 MB |
|
| 101 |
-
| patch_encoder.onnx | 880 KB | Phone |
|
| 102 |
| normalizer.pkl | 405 B | Feature normalizer |
|
| 103 |
|
| 104 |
-
##
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
2. Reason multi-class 1~2개만 정확 (routine_time_shift 100%, 나머지 28% 이하)
|
| 108 |
-
3. VitalGuard ground-truth HR 평가 미실시
|
| 109 |
-
|
| 110 |
-
## 코드
|
| 111 |
-
https://github.com/tlstngud/sisa-routineguard (private)
|
| 112 |
-
- PRESENTATION.md 상세 발표 자료 포함
|
| 113 |
|
| 114 |
-
##
|
| 115 |
-
-
|
| 116 |
-
- CAPTURE-24: Walmsley 2021 (DOI 10.5287/bodleian:NGx0JOMP5)
|
| 117 |
-
- ArWISE V3: CASAS / Diane Cook (Zenodo 15803341)
|
|
|
|
| 8 |
- imu
|
| 9 |
- heart-rate
|
| 10 |
- edge-deployment
|
| 11 |
+
- onnx
|
| 12 |
+
- jetson-nano
|
| 13 |
license: mit
|
| 14 |
---
|
| 15 |
|
| 16 |
+
# SISA-RoutineGuard v5b — ONNX Edition
|
| 17 |
|
| 18 |
+
**노인 일상 패턴 이상 감지** (Galaxy Watch + Jetson Orin Nano Super)
|
| 19 |
+
**ONNX exports** for fast Jetson inference (TensorRT compatible).
|
| 20 |
|
| 21 |
+
## 📦 ONNX Models (Jetson deploy)
|
|
|
|
| 22 |
|
| 23 |
+
| File | Size | Stage | Input | Output |
|
| 24 |
+
|---|---:|---|---|---|
|
| 25 |
+
| **patch_encoder.onnx** | 0.9 MB | 1 (Phone) | acc [6, 250, 3] | tokens [6, 256] |
|
| 26 |
+
| **minute_encoder.onnx** | 192.5 MB | 2 | patch_tokens [B, 6, 256] | minute_embed [B, 768] |
|
| 27 |
+
| **feature_adapter.onnx** | 2.7 MB | 2 | feature [B, 12] | embed [B, 768] |
|
| 28 |
+
| **hourslot_encoder.onnx** | 570.9 MB | 3 | minute_embeds [B, 60, 768] | slot [B, 1024], slot_minutes [B, 60, 1024] |
|
| 29 |
+
| **history_encoder.onnx** | 567.7 MB | 4 | slot_embeds [B, 90, 1024] + meta | history_embeds [B, 90, 1024] |
|
| 30 |
+
| **vitalguard.onnx** | 48.2 MB | 6 | vital_features [B, 60, 5] + hrv | hr_residual_z + trend + context |
|
| 31 |
+
| **output_heads.onnx** | 6.3 MB | — | cls_pooled [B, 1024] | anomaly + reason + confidence |
|
| 32 |
+
|
| 33 |
+
> **QueryRefiner ONNX** 는 cross-attention shape 복잡으로 미지원 (PyTorch ckpt만).
|
| 34 |
+
|
| 35 |
+
**Total ONNX: ~1.4 GB**
|
| 36 |
+
|
| 37 |
+
## 🚀 Jetson Inference Example
|
| 38 |
+
|
| 39 |
+
```python
|
| 40 |
+
import onnxruntime as ort
|
| 41 |
+
import numpy as np
|
| 42 |
+
|
| 43 |
+
# TensorRT EP (Jetson에서 자동 가속)
|
| 44 |
+
providers = [
|
| 45 |
+
'TensorrtExecutionProvider', # Jetson Orin Nano TensorRT
|
| 46 |
+
'CUDAExecutionProvider', # fallback CUDA
|
| 47 |
+
'CPUExecutionProvider', # last resort
|
| 48 |
+
]
|
| 49 |
+
|
| 50 |
+
# 1. Phone 측 PatchEncoder (Phone ONNX)
|
| 51 |
+
phone_sess = ort.InferenceSession("patch_encoder.onnx", providers=['CPUExecutionProvider'])
|
| 52 |
+
patches = phone_sess.run(None, {"acc": acc_array}) # [6, 250, 3] → [6, 256]
|
| 53 |
+
|
| 54 |
+
# 2. Jetson Pipeline
|
| 55 |
+
me_sess = ort.InferenceSession("minute_encoder.onnx", providers=providers)
|
| 56 |
+
minute = me_sess.run(None, {"patch_tokens": patches.reshape(1, 6, 256)})[0]
|
| 57 |
+
|
| 58 |
+
hs_sess = ort.InferenceSession("hourslot_encoder.onnx", providers=providers)
|
| 59 |
+
slot, slot_minutes = hs_sess.run(None, {"minute_embeds": minute_batch}) # [B, 60, 768]
|
| 60 |
+
|
| 61 |
+
# ... history, query, heads chain
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
## 🎯 모델 사이즈 — **444.66M params**
|
| 65 |
|
| 66 |
| Component | Params | Deploy |
|
| 67 |
|---|---:|---|
|
|
|
|
| 75 |
| OutputHeads | 1.58M | Jetson |
|
| 76 |
| **Total** | **444.66M** | — |
|
| 77 |
|
| 78 |
+
## 📊 성능 (OOD: HAR-70+ 노인 70-95세, 학습 X)
|
| 79 |
|
| 80 |
+
| 시나리오 | Score | AUC | Reason |
|
| 81 |
|---|---:|---:|---:|
|
| 82 |
| Normal | 0.0004 | — | — |
|
| 83 |
| walk_missing | 0.9995 | **1.000** | 0% |
|
|
|
|
| 86 |
| activity_drop | 0.7145 | 0.950 | 28% |
|
| 87 |
| **Overall** | — | **0.987** | — |
|
| 88 |
|
| 89 |
+
## 🔧 Train/Val Split + Early Stopping
|
| 90 |
|
| 91 |
+
- Train/Val: 80/20 (3,277 / 819 samples)
|
|
|
|
| 92 |
- **Best epoch = 1, val_loss = 0.2814** (saved)
|
| 93 |
- Early stop at epoch 13 (patience=10)
|
| 94 |
+
- Overfitting 방지 검증됨
|
| 95 |
|
| 96 |
+
## 📁 PyTorch checkpoints (학습 reproducibility용)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
+
| File | Size | Purpose |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|---|---:|---|
|
| 100 |
+
| stage1_patch.pt | 879 KB | PatchEncoder (also ONNX) |
|
| 101 |
+
| stage2_minute.pt | 192 MB | MinuteEncoder (also ONNX) |
|
| 102 |
+
| stage2_adapter.pt | 2.7 MB | FeatureAdapter (also ONNX) |
|
| 103 |
+
| stage3_hourslot.pt | 570 MB | HourSlotEncoder (also ONNX) |
|
| 104 |
+
| stage4_history.pt | 567 MB | HistoryEncoder (also ONNX) |
|
| 105 |
+
| stage4_refiner.pt | 390 MB | QueryRefiner (PyTorch only) |
|
| 106 |
+
| stage5_full.pt | 1.78 GB | Full model (val-split best) |
|
| 107 |
+
| stage6_vitalguard.pt | 48 MB | VitalGuard (also ONNX) |
|
|
|
|
| 108 |
| normalizer.pkl | 405 B | Feature normalizer |
|
| 109 |
|
| 110 |
+
## 학습 데이터
|
| 111 |
+
CAPTURE-24 (151) + ArWISE V3 (10명/76일) + PPG-DaLiA (15) + WESAD (15) + MHEALTH (10).
|
| 112 |
+
**HAR-70+ (18명 70-95세)는 OOD 평가에만 사용.**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
+
## Code
|
| 115 |
+
https://github.com/tlstngud/sisa-routineguard (PRESENTATION.md 포함)
|
|
|
|
|
|
onnx/feature_adapter.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e04ac945f372bd85de13c354284775abda293ccad5d3b91724032f4645ac58d9
|
| 3 |
+
size 2655392
|
onnx/history_encoder.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:841a56105c6b7f5d13853569210557fdd54eda1472d24a824a137abc6ae06ea0
|
| 3 |
+
size 567704068
|
onnx/hourslot_encoder.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:423c1a986934013c735bdcc52085ee9f5991dfc74a6648bd31193785de40583d
|
| 3 |
+
size 570882636
|
onnx/minute_encoder.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d829aa866bcc5b098fb53b55245254f11ac982f8a18d0824630f4ff4aee70b81
|
| 3 |
+
size 192494083
|
onnx/output_heads.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2a0fa889488acb6182adc8a477a5e411d9d241e568d1591fdbac28ee052610b8
|
| 3 |
+
size 6315889
|
onnx/patch_encoder.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:27a63803c361a19bfc991ec55d843c057972af26e3cdb52cd7ea776e63318b20
|
| 3 |
+
size 880614
|
onnx/vitalguard.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:de948c8c0e3808b632b77129677f4805b0a21529fd7207d732edc1c231468b85
|
| 3 |
+
size 48198043
|