Downloads · 30 days
7
17% of all-time downloads
akwancakra/nids-model-cnn-bilstm-ae
nids-model-cnn-bilstm-ae is a tabular classification model from akwancakra. Use it for the tabular classification task on the model card, and read the license before you ship it in a product. It is set up for keras. The card lists the license as mit.
This model is a Hybrid CNN-BiLSTM Autoencoder designed for anomaly-based Network Intrusion Detection. It extracts spatial representations from packet features using 1D Convolution layers and captures temporal sequence…
Downloads · 30 days
7
17% of all-time downloads
All-time downloads
42
Public
Repo size
749 KB
Likes
0
Public
Click a slice to open those files.
.keras748 KB · 71%
From the Hugging Face model README
This model is a Hybrid CNN-BiLSTM Autoencoder designed for anomaly-based Network Intrusion Detection. It extracts spatial representations from packet features using 1D Convolution layers and captures temporal sequences of network flows using Bidirectional LSTM layers.
The model was adapted to real-world traffic using a Three-Phase Training scheme (Pre-training on CIC-IDS 2017 -> Distillation & Margin adaptation on CSE-CIC-IDS 2018 -> Domain Adaptation on 24h Real Benign Traffic).
T = 10 flows.To use this model for inference, download the weights hybrid_nids_v13_fixed_v2.keras and the preprocessing parameters scaler_params.pkl.
import joblib
import numpy as np
import pandas as pd
import tensorflow as tf
# 1. Load model and scaler
model = tf.keras.models.load_model("hybrid_nids_v13_fixed_v2.keras")
scaler = joblib.load("scaler_params.pkl")
# 2. Define the 25 features required
FEATURES = [
"Init Fwd Win Byts", "Bwd Pkts/s", "Init Bwd Win Byts", "Pkt Size Avg",
"Dst Port", "Bwd Pkt Len Max", "Bwd IAT Tot", "Flow IAT Min",
"Flow IAT Mean", "Fwd Pkts/s", "Flow IAT Std", "Fwd Seg Size Avg",
"TotLen Fwd Pkts", "Flow Byts/s", "Bwd Pkt Len Min", "Bwd Pkt Len Std",
"Fwd IAT Min", "FIN Flag Cnt", "SYN Flag Cnt", "Fwd IAT Std",
"Subflow Bwd Byts", "Down/Up Ratio", "Pkt Len Std", "Fwd Pkt Len Std",
"Fwd Act Data Pkts"
]
# 3. Create dummy flow data (minimum 10 rows for sequence context)
df = pd.DataFrame(np.random.rand(15, len(FEATURES)), columns=FEATURES)
df["Dst Port"] = np.random.randint(0, 65535, size=15)
# 4. Preprocess: scale features
X_scaled = scaler.transform(df[FEATURES].values)
# 5. Create sequences (Window size T = 10)
T = 10
n_seq = len(X_scaled) - T + 1
X_seq = np.empty((n_seq, T, len(FEATURES)), dtype=np.float32)
for i in range(n_seq):
X_seq[i] = X_scaled[i : i + T]
# 6. Run inference & calculate reconstruction error
reconstruction = model.predict(X_seq)
errors = np.mean(np.abs(X_seq - reconstruction), axis=(1, 2))
# 7. Apply Dual Thresholds
THR_WARNING = 0.05831 # Warning: FPR ~1.0%
THR_CRITICAL = 0.07033 # Critical: FPR ~0.17%
for idx, error in enumerate(errors):
flow_idx = idx + T - 1
alert = "NORMAL"
if error > THR_CRITICAL:
alert = "CRITICAL"
elif error > THR_WARNING:
alert = "WARNING"
print(f"Flow {flow_idx} -> Reconstruction Error: {error:.5f} | Status: {alert}")
The model was trained on 25 network features selected from 77 canonical features of CIC datasets using a robust pipeline of:
Calibrated thresholds evaluated on real-world validation data:
0.05831): Calibrated for balanced detection. FPR ~1.0% on real benign validation set.0.07033): Calibrated for high precision. FPR ~0.17% on real benign validation set.If you use this model or code in your research, please cite:
@thesis{nids_hybrid_cnn_bilstm_ae_2026,
author = {Akwan Cakra Tajimalela},
title = {Anomaly-based Network Intrusion Detection System using Hybrid CNN-BiLSTM Autoencoder and Domain Adaptation},
school = {Universitas Pendidikan Indonesia},
year = {2026},
type = {Undergraduate Thesis}
}