File size: 2,114 Bytes
58580ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
---
license: apache-2.0
language: en
library_name: keras
tags:
- intrusion-detection
- network-security
- iot-security
- cnn
- bilstm
- time-series
- cybersecurity
datasets:
- CICIoT2023
---

# Binary Network-Layer Cyber-Physical IDS

A hybrid **CNN-BiLSTM** model for real-time binary network intrusion detection in IoT environments.  
This model acts as the first line of defense by quickly distinguishing between malicious and legitimate traffic.

## Model Description

- **Architecture:** `Conv1D -> ... -> Bidirectional LSTM -> Dense -> Dense (Sigmoid)`  
- **Dataset:** Balanced subset of CICIoT2023  
- **Performance:** 99.9997% accuracy  
- **Limitations:** Validated only on CICIoT2023-like network traffic; may not detect novel attack types. Input must be normalized.  
- **Training Information:**  
  - Optimizer: Adam  
  - Loss: Binary Cross-Entropy  
  - Balanced dataset: 2 million samples (1M benign, 1M attack)  

## Intended Use
- **Primary Use:** Real-time network intrusion detection  
- **Input:** `(batch_size, 10, 46)` — 46 network flow features, normalized  
- **Output:** Float between 0.0 (Benign) and 1.0 (Attack), threshold 0.5  

## How to Use
```python
import tensorflow as tf
import numpy as np
from huggingface_hub import hf_hub_download

# Download the model from Hugging Face
MODEL_PATH = hf_hub_download("Codelord01/binary_model", "binary_model.keras")
model = tf.keras.models.load_model(MODEL_PATH)
model.summary()

# Prepare a sample input: 1 sample, 10 timesteps, 46 features
sample_data = np.random.rand(1, 10, 46).astype(np.float32)

# Make a prediction
prediction_prob = model.predict(sample_data)
predicted_class = 1 if prediction_prob > 0.5 else 0

print(f"Prediction Probability: {prediction_prob:.4f}")
print("Malicious Traffic Detected" if predicted_class == 1 else "Benign Traffic")


@mastersthesis{ababio2025multilayered,
  title={A Multi-Layered Hybrid Deep Learning Framework for Cyber-Physical Intrusion Detection in Climate-Monitoring IoT Systems},
  author={Awuni David Ababio},
  year={2025},
  school={Kwame Nkrumah University of Science and Technology}
}