Cognitive Security Framework | Deep Learning | Computer Vision | Flask | CICIDS & UNSW-NB15
A production-ready Intrusion Detection System (IDS) for IoT and 5G networks that takes raw network traffic (CSV), converts it into visual image representations, and classifies it as BENIGN or ATTACK using a dual-CNN ensemble architecture.
The key novelty: instead of treating network features as tabular data, this system transforms them into RGB and Grayscale images and leverages convolutional neural networks β bringing computer vision techniques to the cybersecurity domain.
| Feature | Detail |
|---|---|
| Approach | Feature-to-image transformation + CNN classification |
| Datasets | CICIDS 2017, CICIDS 2018, UNSW-NB15 |
| Models | Dual CNN (RGB + Grayscale) with weighted ensemble |
| Class Imbalance | SMOTE oversampling + random undersampling |
| Deployment | Flask web app β upload CSV, get instant prediction |
| Domain | IoT Security Β· 5G Networks Β· Network Forensics |
Raw Network Traffic (CSV)
β
βΌ
ββββββββββββββββββββββββ
β Data Preprocessing β MinMaxScaler + Label Encoding + Binary Classification
ββββββββββββ¬ββββββββββββ
β
ββββββββ΄βββββββ
βΌ βΌ
ββββββββββ ββββββββββββ
β RGB β βGrayscale β Feature β Image Conversion (64Γ64 px)
β Image β β Image β Cubic Interpolation for Grayscale
βββββ¬βββββ ββββββ¬ββββββ
β β
βΌ βΌ
ββββββββββ ββββββββββββ
βCNN RGB β βCNN Gray β Separate trained models per modality
βββββ¬βββββ ββββββ¬ββββββ
β β
ββββββββ¬ββββββββ
βΌ
ββββββββββββββββββββ
β Weighted Ensemble β RGB weight: 0.98 | Gray weight: 0.94
ββββββββββ¬ββββββββββ
βΌ
BENIGN / ATTACK
Traditional ML methods treat network flows as flat vectors. This approach encodes relational structure between features spatially, enabling CNNs to learn patterns across multiple features simultaneously β a technique gaining traction in network security research.
Intrusions/
βββ app/
β βββ preprocessing.py # Feature scaling and cleaning
β βββ image_converter.py # RGB and grayscale image generation
β βββ main.py # Flask routes and model inference
βββ models/
β βββ model_rgb.h5 # Trained CNN for RGB images
β βββ model_gray.h5 # Trained CNN for Grayscale images
βββ templates/
β βββ index.html # Web UI for CSV upload + prediction
βββ static/images/ # Generated visualization outputs
βββ output/ # Prediction results
βββ main.py # Flask application entry point
βββ model_train.ipynb # Full training pipeline notebook
βββ scaler.joblib # Saved MinMaxScaler
βββ instance1.csv # Sample test instance (CICIDS)
βββ instance2.csv # Sample test instance (UNSW-NB15)
βββ requirements.txt
# 1. Clone the repository
git clone https://github.com/fahad03-mfa/Intrusions.git
cd Intrusions
# 2. Install dependencies
pip install -r requirements.txt
# 3. Launch the Flask application
python main.pyVisit http://127.0.0.1:5000 β upload a network traffic CSV and get a prediction instantly.
Upload a .csv file containing network flow features (compatible with CICIDS or UNSW-NB15 feature sets). Sample files instance1.csv and instance2.csv are included.
RGB Mode: Each normalized feature value is mapped to a 24-bit RGB color using:
rgb_value = int(value * 16777215) # 2^24 - 1 colors
r = (rgb_value >> 16) & 0xFF
g = (rgb_value >> 8) & 0xFF
b = rgb_value & 0xFFFeatures are distributed across a 64Γ64 pixel canvas.
Grayscale Mode: Features are arranged in a 2D grid, then upscaled to 64Γ64 using cubic spline interpolation (RegularGridInterpolator), preserving spatial relationships between features.
- SMOTE (Synthetic Minority Over-sampling Technique) to generate realistic synthetic minority class samples
- Random undersampling to trim dominant class
- Result: balanced training distribution, unbiased recall
# RGB model has slightly higher weight due to richer color encoding
combined = (rgb_pred * 0.5098) + (gray_pred * 0.4902)
final_class = 1 if combined > 0.54 else 0 # ATTACK or BENIGN| Metric | RGB Model | Grayscale Model | Ensemble |
|---|---|---|---|
| Accuracy | 99.19% | 94.78% | 99.10% |
| Precision | 98.9% | 94.50% | 98.90% |
| Recall | 99.10% | 94.60% | 99% |
| F1 Score | 99% | 94.55% | 98.99% |
The Flask app provides a clean interface to:
- Upload a CSV of network flow features
- Visualize the generated RGB and Grayscale images
- Get a prediction β BENIGN or ATTACK β from the ensemble
Endpoints:
GET /β Home pagePOST /processβ Upload CSV β returns prediction + imageGET /downloadβ Download generated grayscale image
| Layer | Technology |
|---|---|
| ML Framework | TensorFlow / Keras |
| Data Processing | NumPy, Pandas, Scikit-learn |
| Image Processing | Matplotlib, SciPy (interp2d, RegularGridInterpolator) |
| Class Balancing | imbalanced-learn (SMOTE) |
| Web Backend | Flask |
| Model Persistence | Joblib, Keras .h5 |
| Datasets | CICIDS 2017/2018, UNSW-NB15 |
- Real-time packet capture and inference (PyShark / Scapy integration)
- Explainability layer β Grad-CAM visualization on predicted images
- Transformer-based encoder (ViT) to replace CNN backbone
- Docker containerization for one-command deployment
- REST API with authentication for enterprise integration
- Multi-class attack classification (DDoS, Probe, R2L, U2R)
- CICIDS 2017/2018 β Canadian Institute for Cybersecurity, University of New Brunswick. Covers DoS, DDoS, Brute Force, Web attacks.
- UNSW-NB15 β UNSW Canberra. Modern hybrid dataset with real attack traffic and synthetic normal traffic.
Mohammed Fahad Altamash
Bangalore, India
GitHub
If this project helped you, consider giving it a β β it helps others find it!