ilessio-aiflowlab commited on
Commit
5deda82
·
verified ·
1 Parent(s): 5b596e6

Update model card: full Phase 1 + Phase 2 coverage, CUDA kernels, usage examples

Browse files
Files changed (1) hide show
  1. README.md +221 -26
README.md CHANGED
@@ -5,43 +5,238 @@ tags:
5
  - anomaly-detection
6
  - defense
7
  - cuda
 
 
8
  - anima
 
 
9
  license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  ---
11
 
12
- # DEF-sariad SAR Anomaly Detection
13
 
14
- **Wave 8 Defense Module** | ANIMA Framework
15
 
16
- ## Model Description
17
- Convolutional autoencoder (22.4M params) for SAR image anomaly detection.
18
- Trained on 11.8K SAR ship images. Detects anomalies via reconstruction error.
19
 
20
- ## CUDA Kernels (6 ops, 124x speedup)
21
- - `fused_median_filter_3x3` — 124x faster than PyTorch unfold+median
22
- - `fused_median_filter_5x5` — heavy denoising
23
- - `fused_sar_nlm_denoise` — non-local means for SAR
24
- - `sar_log_normalize` — SAR amplitude preprocessing
25
- - `anomaly_score` / `fused_reconstruct_error_map` — anomaly scoring
26
 
27
- ## Training
28
- - Dataset: Combined SAR Ship (11.8K images: SAR-Ship, HRSID, SSDD, Sentinel-1)
29
- - Architecture: Convolutional AE (encoder: 5 conv blocks, decoder: 5 deconv blocks)
30
- - Input: 256x256 RGB, latent_dim=256
31
- - Optimizer: AdamW, lr=3e-4, warmup+cosine schedule
32
- - Hardware: NVIDIA L4 (23GB)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
- ## Exports
35
- - `model.pth` — PyTorch state dict
36
- - `model.safetensors` SafeTensors format
37
- - `model.onnx` — ONNX export
38
- - `model_fp16.engine` TensorRT FP16
39
- - `model_fp32.engine` TensorRT FP32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  ## Usage
 
 
42
  ```python
 
43
  from def_sariad.models import SARAutoencoder
44
- model = SARAutoencoder(in_channels=3, latent_dim=256)
45
- model.load_state_dict(torch.load("model.pth"))
46
- anomaly_map = model.compute_anomaly_score(sar_image)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  - anomaly-detection
6
  - defense
7
  - cuda
8
+ - dinov2
9
+ - thermal
10
  - anima
11
+ - tensorrt
12
+ - onnx
13
  license: apache-2.0
14
+ pipeline_tag: image-classification
15
+ datasets:
16
+ - custom
17
+ metrics:
18
+ - mse
19
+ - anomaly_rate
20
+ model-index:
21
+ - name: DEF-sariad Combined AE
22
+ results:
23
+ - task:
24
+ type: anomaly-detection
25
+ name: SAR Anomaly Detection
26
+ metrics:
27
+ - name: Val Loss (MSE)
28
+ type: mse
29
+ value: 2.600
30
+ - name: Throughput
31
+ type: throughput
32
+ value: 877 img/s
33
+ - name: DEF-sariad DINOv2+KNN
34
+ results:
35
+ - task:
36
+ type: anomaly-detection
37
+ name: Feature-Space Anomaly Detection
38
+ metrics:
39
+ - name: CUDA Speedup
40
+ type: speedup
41
+ value: 81.4x
42
+ - name: Test Anomaly Rate
43
+ type: anomaly_rate
44
+ value: 4.9%
45
  ---
46
 
47
+ # DEF-sariad -- SAR Anomaly Detection
48
 
49
+ **Wave 8 Defense Module** | [ANIMA Framework](https://github.com/RobotFlow-Labs) | Apache 2.0
50
 
51
+ Two-phase SAR anomaly detection system with 8 custom CUDA kernels for real-time defense applications. Designed for NEMESIS (terrain navigation) and ATLAS (fleet autonomy) stacks.
 
 
52
 
53
+ ## Architecture
 
 
 
 
 
54
 
55
+ ```
56
+ Phase 1: Pixel-Space Reconstruction
57
+ Input (256x256 RGB) -> CUDA Median Filter (101x speedup)
58
+ -> Convolutional AE (22.4M params) -> Reconstruction Error -> Anomaly Map
59
+
60
+ Phase 2: Feature-Space Detection (recommended for deployment)
61
+ Input (256x256 RGB) -> DINOv2 ViT-B/14 (frozen, 86.6M params)
62
+ -> 768-dim features -> KNN/Gaussian/MLP detector -> Anomaly Score
63
+ ```
64
+
65
+ ## Models
66
+
67
+ ### Phase 1: Pixel-Space Autoencoders
68
+
69
+ | Model | Params | Latent | Val Loss | Throughput | Files |
70
+ |-------|--------|--------|----------|------------|-------|
71
+ | **Combined AE** (primary) | 22.4M | 256 | **2.600** | 877 img/s | `model.*`, `combined/` |
72
+ | Deep AE | 39.2M | 512 | 2.600 | 902 img/s | `combined/` variant |
73
+ | VAE | 55.9M | 512 | 2.603 | 878 img/s | `combined/` variant |
74
+ | SAR-only AE | 22.4M | 256 | 2.808 | 330 img/s | `best.pth` |
75
+
76
+ Trained on 62.8K combined SAR ship + VIVID++ thermal images. All architectures plateau at val_loss ~ 2.600 (pixel reconstruction ceiling).
77
+
78
+ ### Phase 2: DINOv2 Feature-Space Detectors
79
+
80
+ | Detector | Method | CUDA Speedup | Test Anomaly Rate | Files |
81
+ |----------|--------|-------------|-------------------|-------|
82
+ | **KNN** (recommended) | k=5 NN in 10K bank | **81.4x** | 4.9% | `feature_detector/knn_detector.pth` |
83
+ | Gaussian | Mahalanobis distance | **2.2x** | 38.0% | `feature_detector/gaussian_detector.pth` |
84
+ | MLP head | 768->256->128->1 | -- | learned | `feature_detector/mlp_head.*` |
85
+
86
+ Features extracted with DINOv2 ViT-B/14 (frozen). 71,917 features across 24 VIVID++ scenes. KNN detector at 81x CUDA speedup is recommended for real-time deployment.
87
+
88
+ ## CUDA Kernels (8 ops, sm_89)
89
 
90
+ Custom CUDA kernels compiled for NVIDIA L4 (compute 8.9), CUDA 12, torch cu128:
91
+
92
+ | Kernel | Speedup | Use Case |
93
+ |--------|---------|----------|
94
+ | `fused_median_filter_3x3` | **101x** | SAR speckle denoising |
95
+ | `fused_median_filter_5x5` | **14x** | Heavy speckle denoising |
96
+ | `sar_log_normalize` | **4.5x** | SAR amplitude preprocessing |
97
+ | `fused_reconstruct_error_map` | **1.9x** | Pixel anomaly scoring (4D) |
98
+ | `fused_sar_nlm_denoise` | -- | Non-local means denoising |
99
+ | `anomaly_score` | -- | Per-pixel reconstruction error (3D) |
100
+ | `fused_mahalanobis_distance` | **2.2x** | Gaussian feature-space scoring |
101
+ | `fused_knn_distance` | **81.4x** | KNN feature-space scoring |
102
+
103
+ All kernels have automatic PyTorch fallbacks when custom CUDA extensions aren't available.
104
+
105
+ ## Export Formats
106
+
107
+ ### Phase 1 (Combined AE)
108
+ | Format | File | Size |
109
+ |--------|------|------|
110
+ | PyTorch | `model.pth` | 86MB |
111
+ | SafeTensors | `model.safetensors` | 86MB |
112
+ | ONNX | `model.onnx` | 86MB |
113
+ | TensorRT FP16 | `model_fp16.engine` | 44MB |
114
+ | TensorRT FP32 | `model_fp32.engine` | 86MB |
115
+
116
+ ### Phase 2 (MLP Head)
117
+ | Format | File | Size |
118
+ |--------|------|------|
119
+ | PyTorch | `feature_detector/mlp_head.pth` | 0.9MB |
120
+ | SafeTensors | `feature_detector/mlp_head.safetensors` | 0.9MB |
121
+ | ONNX | `feature_detector/mlp_head.onnx` | 921KB |
122
+ | TensorRT FP16 | `feature_detector/mlp_head_fp16.engine` | 965KB |
123
+ | TensorRT FP32 | `feature_detector/mlp_head_fp32.engine` | 965KB |
124
 
125
  ## Usage
126
+
127
+ ### Phase 1: Pixel-Space Anomaly Detection
128
  ```python
129
+ import torch
130
  from def_sariad.models import SARAutoencoder
131
+ from def_sariad.backends.cuda_ops import cuda_median_filter
132
+
133
+ # Load model
134
+ model = SARAutoencoder(in_channels=3, latent_dim=256).cuda()
135
+ state = torch.load("model.pth", map_location="cuda")
136
+ model.load_state_dict(state["model"] if "model" in state else state)
137
+ model.eval()
138
+
139
+ # Preprocess with CUDA median filter (101x speedup)
140
+ sar_image = torch.randn(1, 3, 256, 256).cuda()
141
+ denoised = cuda_median_filter(sar_image, kernel_size=3)
142
+
143
+ # Detect anomalies
144
+ with torch.no_grad():
145
+ anomaly_map = model.compute_anomaly_score(denoised)
146
+ # anomaly_map shape: [1, 256, 256] -- higher values = more anomalous
147
+ ```
148
+
149
+ ### Phase 2: Feature-Space Anomaly Detection (Recommended)
150
+ ```python
151
+ import torch
152
+
153
+ # Load pre-extracted DINOv2 features (768-dim)
154
+ features = torch.load("vivid_dinov2_features/scene_features.pt")
155
+
156
+ # KNN detector (81x CUDA speedup)
157
+ knn_state = torch.load("feature_detector/knn_detector.pth")
158
+ feature_bank = knn_state["feature_bank"].cuda() # [10000, 768]
159
+ threshold = knn_state["threshold"] # 23.94
160
+
161
+ # Score new features
162
+ query = features[:100].cuda() # [100, 768]
163
+ dists = torch.cdist(query, feature_bank) # [100, 10000]
164
+ knn_dists, _ = dists.topk(5, largest=False, dim=1) # k=5
165
+ scores = knn_dists.mean(dim=1) # [100]
166
+ anomalies = scores > threshold
167
+ ```
168
+
169
+ ### ONNX Inference
170
+ ```python
171
+ import onnxruntime as ort
172
+ import numpy as np
173
+
174
+ session = ort.InferenceSession("model.onnx", providers=["CUDAExecutionProvider"])
175
+ input_data = np.random.randn(1, 3, 256, 256).astype(np.float32)
176
+ outputs = session.run(None, {"input": input_data})
177
+ ```
178
+
179
+ ### TensorRT Inference
180
+ ```python
181
+ # Use model_fp16.engine for fastest inference
182
+ # Requires tensorrt Python package
183
+ import tensorrt as trt
184
+ # Load engine and run inference via TRT runtime
185
  ```
186
+
187
+ ## Training Details
188
+
189
+ | Parameter | Phase 1 | Phase 2 |
190
+ |-----------|---------|---------|
191
+ | Dataset | 62.8K SAR+thermal | 71.9K DINOv2 features |
192
+ | Input | 256x256 RGB | 768-dim vectors |
193
+ | Optimizer | AdamW | -- (KNN/Gaussian are non-parametric) |
194
+ | Learning rate | 3e-4 | -- |
195
+ | Scheduler | Warmup (5%) + Cosine | -- |
196
+ | Epochs | 50-100 | 1 (feature extraction) |
197
+ | GPU | NVIDIA L4 (23GB) | NVIDIA L4 (23GB) |
198
+ | Precision | FP32 | FP32 |
199
+
200
+ ## File Structure
201
+
202
+ ```
203
+ DEF-sariad/
204
+ +-- model.pth # Phase 1: Combined AE weights
205
+ +-- model.safetensors # Phase 1: SafeTensors format
206
+ +-- model.onnx # Phase 1: ONNX export
207
+ +-- model_fp16.engine # Phase 1: TensorRT FP16
208
+ +-- model_fp32.engine # Phase 1: TensorRT FP32
209
+ +-- best.pth # Phase 1: SAR-only AE weights
210
+ +-- combined/ # Phase 1: Combined AE full export set
211
+ +-- feature_detector/
212
+ | +-- gaussian_detector.pth # Phase 2: Mahalanobis detector
213
+ | +-- knn_detector.pth # Phase 2: KNN detector (recommended)
214
+ | +-- mlp_head.pth # Phase 2: Learned MLP head
215
+ | +-- mlp_head.safetensors # Phase 2: MLP SafeTensors
216
+ | +-- mlp_head.onnx # Phase 2: MLP ONNX
217
+ | +-- mlp_head_fp16.engine # Phase 2: MLP TRT FP16
218
+ | +-- mlp_head_fp32.engine # Phase 2: MLP TRT FP32
219
+ | +-- training_report.json # Phase 2: Detector metrics
220
+ +-- config/
221
+ | +-- anima_module.yaml # ANIMA module manifest
222
+ | +-- autoencoder.toml # AE training config
223
+ | +-- paper.toml # Paper reproduction config
224
+ +-- export_manifest.json # Export metadata
225
+ +-- training_report.json # Phase 1 training metrics
226
+ +-- TRAINING_REPORT.md # Full training report
227
+ +-- README.md # This model card
228
+ ```
229
+
230
+ ## Citation
231
+
232
+ ```bibtex
233
+ @article{sariad2025,
234
+ title={SARIAD: A Comprehensive Benchmark for SAR Image Anomaly Detection},
235
+ year={2025},
236
+ note={arXiv:2504.08115}
237
+ }
238
+ ```
239
+
240
+ ## License
241
+
242
+ Apache 2.0. Part of the [ANIMA Framework](https://github.com/RobotFlow-Labs) by Robot Flow Labs.