Downloads · 30 days
0
keyvan-ai/CANDefender-DoS
CANDefender-DoS is a machine learning model from keyvan-ai. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as cc-by-nc-nd-4.0.
Model Summary This model detects DoS attacks on the CAN bus. It was trained on approximately 4.6 million real CAN frames (both normal traffic and DoS data). The core is an LSTM architecture that processes the CAN ID a…
Downloads · 30 days
0
Access
Public
Updated Jul 9, 2026
Repo size
79.5 KB
Likes
0
Public
Click a slice to open those files.
.pt79.5 KB · 95%
From the Hugging Face model README
Model Summary
This model detects DoS attacks on the CAN bus. It was trained on approximately 4.6 million real CAN frames (both normal traffic and DoS data). The core is an LSTM architecture that processes the CAN ID and the 8-byte payload to classify each frame as either “DoS” or “Normal.”
Test Accuracy: ~94.06%
Confusion Matrix (DoS vs. Normal):
| True \ Pred | DoS (pred) | Normal (pred) |
|---|---|---|
| DoS | 3,632,463 | 2,120 |
| Normal | 272,327 | 716,544 |
Interpretation: Almost no DoS frames are missed, but ~28% of normal traffic is misclassified as DoS (higher false alarms).
import torch
import numpy as np
from can_defender_dos import CANLSTM # replace with your actual import
# Example frame: [CAN_ID, b0, b1, ..., b7]
frame = [0x315, 0x12, 0x4F, 0xA2, 0x00, 0x00, 0x78, 0x1C, 0xAA]
# Convert to the same shape as the model expects: (batch_size, seq_len, features)
x_np = np.array(frame, dtype=np.float32).reshape(1, 1, 9)
model = CANLSTM(input_dim=9, hidden_dim=64, num_classes=2)
model.load_state_dict(torch.load("candefender_dos_final.pt"))
model.eval()
with torch.no_grad():
logits = model(torch.from_numpy(x_np))
pred = torch.argmax(logits, dim=1).item()
print("Prediction:", "DoS" if pred == 0 else "Normal")