Skip to Content
You are currently on the new version of our website. Access the old version .
ElectronicsElectronics
  • Article
  • Open Access

13 July 2026

30 Pages

Lightweight Malicious Traffic Detection Model for Edge Scenarios: Co-Optimization of Detection Accuracy and Computational Overhead

,
,
,
and
College of Computer Science, Jilin Normal University, Siping 136000, China
*
Authors to whom correspondence should be addressed.

Abstract

With the widespread deployment of IoT devices, deploying efficient network traffic classification models on resource-constrained edge nodes is critical for real-time boundary security. However, traditional lightweight models primarily rely on macro-level structural pruning, which often sacrifices crucial feature extraction capabilities when handling complex heterogeneous traffic, leading to a severe imbalance between parameter compression and detection accuracy. To overcome this bottleneck, we propose TinyFlowNet, an ultra-lightweight multi-module fusion architecture. To prevent the parameter explosion inherent in combining CNN, LSTM, and Transformer modules, TinyFlowNet innovatively adopts an extreme operator-level reconstruction strategy. By introducing debiased computations, affine-free normalization, and a customized micro-self-attention mechanism, it comprehensively strips away underlying redundant parameters. Simultaneously, an integrated parameter-free regularization mechanism is introduced to compensate for the representational capacity lost under this extreme compression, ensuring robust spatio-temporal feature fusion. Comprehensive evaluations on the custom X-IDS-20 balanced dataset alongside the complex CICDarknet2020 and ToN_IoT public datasets demonstrate that TinyFlowNet achieves exceptional accuracies of 95.31 percent, 99.53 percent, and 97.13 percent, respectively. Furthermore, it exhibits formidable robustness against extreme class imbalances by securing a peak Matthews Correlation Coefficient of 0.9465 and an outstanding PR-AUC of 0.9834, all while strictly confining the parameter count to merely 74,600. Crucially, actual on-device hardware profiling on a commercial edge device corroborates its deployment viability, exhibiting a minimal dynamic memory footprint of 8.26 MB, an average inference latency of 0.79 ms, and a processing throughput exceeding 1200 FPS. Compared to a standard heavy Hybrid CNN-LSTM-Transformer baseline, TinyFlowNet achieves superior detection accuracy while drastically reducing the parameter footprint by over 99.3% and computational FLOPs by 95.8%. Furthermore, against mainstream lightweight benchmarks like DistilBERT and heavy baselines such as LSTM, TinyFlowNet reduces parameters by 61.4% to 94% while simultaneously achieving absolute accuracy leaps and accelerating inference speed by nearly 4× over MobileNetV2, establishing a highly efficient new paradigm for intelligent edge defense.

1. Introduction

With the explosive growth of the Internet of Things and edge computing technologies, global smart terminals are projected to exceed 29 billion by 2030. However, because these edge devices often feature simplified hardware designs and limited computational resources, they are highly susceptible to becoming vulnerable entry points for novel network attacks [1]. In this context, the importance of anomaly-based Intrusion Detection Systems as the first line of defense for boundary security has become increasingly prominent. Traditional systems rely heavily on cloud servers for centralized processing, which incurs extremely high communication latency and carries the risk of sensitive data leakage. Therefore, deploying deep learning models with strong feature representation capabilities directly on network edge nodes to achieve real-time and localized traffic classification has become a consensus in both academia and industry [2]. This application of lightweight deep learning networks in edge security has triggered extensive follow-up research [3].
Although lightweight network security models are highly valuable, existing schemes generally fall into three limited paradigms that struggle to simultaneously balance detection capability and edge adaptability. At one end of the spectrum, heavy hybrid architectures prioritize high precision at the cost of high computational overhead. For instance, studies by Alashjaee et al. [4] and Kaur [5] cascaded complex modules such as CNNs, LSTMs, and Transformers. While these approaches are highly effective on standard datasets, their parameter counts easily reach the million scale, and their prolonged inference latency makes them completely unadaptable to micro edge devices. Furthermore, recent advancements in encrypted traffic classification like the TFE-GNN [6] have proposed sophisticated architectures integrating Temporal Fusion Encoders with Graph Neural Networks. Although achieving remarkable fine-grained classification performance, these massive hybrid architectures strictly rely on maintaining high-dimensional packet sequence states and dynamic adjacency matrices. This results in exponential growth in computational operations and prohibitive inference latency, rendering them fundamentally incompatible with resource-constrained edge environments.
To mitigate these overheads, a second paradigm explores knowledge distillation and cross-domain model adaptation. However, these methods often retain structural redundancy. Models like DistilBERT [7] remain a benchmark, but even after distillation for traffic data, they retain a prohibitively large parameter count. Similarly, vision-adapted models like MobileNetV2 [8] expose severe computational redundancy when applied to one-dimensional traffic sequences. Furthermore, direct concatenations of advanced modules, such as standard Hybrid CNN-LSTM-Transformer architectures [9], achieve high detection precision but impose an unacceptable computational burden and latency, with parameter counts easily exceeding tens of millions. At the other extreme, some researchers rely on over-pruned single networks to achieve ultra-low overhead [10]. This coarse-grained pruning inevitably leads to the loss of global temporal dependencies, causing a catastrophic degradation in generalization accuracy when the model confronts complex attack traffic [11].
To break the bottleneck where lightweighting and high precision are difficult to balance, researchers face two severe computational and architectural challenges. The first is the iteration efficiency barrier brought about by massive data evaluation, which leads to a sharp increase in the time costs associated with validating minor architectural ablations [12]. The second is the challenge of multi-module feature coordination under the constraint of extremely low parameter counts. When model parameters are strictly compressed below the 100,000 level, traditional coarse-grained module pruning easily leads to the loss of key features. Therefore, to ensure no sacrifice in accuracy and to effectively fuse local perception, channel feature recalibration, and global temporal dependencies, models must pivot towards refined reconstruction at the underlying operator level [13].
Recently, some studies have attempted to develop specific lightweight frameworks combining various modules to address edge computing needs. Most current hybrid models simply perform macro-level module concatenation, treating modules as black boxes and stacking them together. While this preserves high precision, the parameter count inevitably remains massive. In stark contrast, the novelty of our proposed TinyFlowNet is rooted in overcoming this parameter explosion through an operator-level extreme reconstruction strategy. Instead of conventional coarse-grained pruning, we deeply deconstruct the hybrid architecture by implementing unbiased computation, affine-free normalization, and customized micro-self-attention with strict dimensional alignment. This extreme micro-level optimization bypasses heavy macroscopic fusion and successfully compresses the total parameters to merely 74,600, bridging the critical gap between state-of-the-art accuracy and micro-device deployability.
In response to these severe challenges, this paper proposes a comprehensive solution. First, to address the lengthy trial-and-error cycles caused by massive datasets, we constructed an efficient and streamlined dataset oriented toward early-stage prototype validation through systematic feature alignment and distribution-balanced sampling. Building upon this foundation, we propose TinyFlowNet, an ultra-lightweight multi-module fusion network. Specifically, the main contributions of this paper are as follows:
(1)
Proposed a high-precision fundamental architecture with multi-module fusion. An end-to-end joint architecture integrating local feature perception, channel attention enhancement, and global temporal modeling was innovatively constructed. This fully leverages the synergistic advantages of multiple heterogeneous modules, fundamentally ensuring the model’s limit capability in representing and discriminating complex network traffic.
(2)
Designed an Extreme Lightweight Operator strategy. To address the parameter redundancy brought by fusion models, this paper delves into the underlying computational graph. By implementing unbiased and affine-free operator reconstruction, customizing a single-head micro-self-attention mechanism to streamline the hidden layer dimension to 64, refining dimensional alignment, and employing zero-parameter label smoothing regularization for compensation, the total parameter count of the fusion model was successfully compressed to a limit of only 74,600. This thoroughly breaks the barrier of parameter explosion in combinatorial models.
(3)
Rigorous Cross-Domain Evaluation and On-Device Profiling. Extensive validation across a custom-built balanced dataset (X-IDS-20) and challenging public benchmarks (CICDarknet2020, ToN_IoT) demonstrates peak accuracies up to 99.53%. Crucially, actual hardware deployment on a commercial edge device (Raspberry Pi 4B; Raspberry Pi Foundation, Cambridge, UK) corroborates its practical viability, exhibiting a minimal dynamic memory footprint of 8.26 MB and an ultra-low average inference latency of 0.79 ms. This physical validation confirms that TinyFlowNet bridges the gap between theoretical lightweight design and real-world edge execution, comprehensively outperforming mainstream baselines in both computational efficiency and detection accuracy.

3. Method

3.1. Hybrid Architecture Design for High-Precision Prediction

Single neural network models often possess blind spots in feature extraction when processing complex sequential data. To break through the accuracy bottleneck, this paper is dedicated to constructing a joint architecture with multidimensional feature fusion. By cascading a Convolutional Neural Network (CNN), Squeeze-and-Excitation (SE) channel attention, a Long Short-Term Memory (LSTM) network, and a self-attention mechanism (Transformer), it achieves comprehensive perception of local features, channel weights, short-term temporal dynamics, and global long-range dependencies. The overall experimental workflow is illustrated in Figure 1, systematically demonstrating the complete pipeline.In the figure, dashed arrows represent residual connections, and ellipses (…) indicate the temporal sequences or repeated tensor structures.
Figure 1. Overall workflow diagram.

3.1.1. Local Feature Extraction

This module adopts a two-layer one-dimensional (1D) convolutional cascaded structure to balance the fine granularity of feature extraction with computational efficiency, while strictly controlling the parameter count through lightweight design. To capture both spatial feature correlations and real temporal dynamics, the input data is formulated as a temporal sliding window sequence rather than isolated single-flow statistics. Specifically, the preprocessed traffic features undergo dimensionality expansion, where the sequence dimension explicitly represents the real temporal traffic sequence length. The input is expanded into 3D tensors to adapt to the input format requirements of the 1D convolutional layers. The first convolutional layer employs 32 1D convolution kernels of size 3. Without altering the feature sequence length, it performs preliminary extraction of local patterns from the raw traffic features, mapping them into a 32-dimensional primary feature space.
To further unearth high-dimensional nonlinear patterns within the features, the second convolutional layer deploys 64 1D convolution kernels of size 3. Using the same sliding parameters, it performs deep convolutional operations on the primary features, outputting 64-dimensional high-level local features to achieve differentiated feature abstraction for complex attack behaviors and subdivided traffic types.
To alleviate the internal covariate shift problem during model training and simultaneously implement the lightweight design, each convolutional operation is tightly coupled with an affine-free Batch Normalization and a ReLU activation function. The affine-free BN disables the learnable affine parameters γ and β, retaining only the zero-mean and unit-variance standardization operations on the data. This significantly reduces the module’s trainable parameter count while ensuring training stability and accelerating model convergence. The ReLU activation function, through f ( x ) = max ( 0 , x ) its nonlinear transformation, resolves the inability of linear models to fit the complex nonlinear distribution of network traffic; concurrently, its sparse activation characteristic further reduces computational redundancy and enhances the model’s forward inference speed. Combined with the MaxPooling downsampling operation, the complete feature mapping logic can be expressed by the formula:
X c n n ( 1 ) = M a x P o o l ( R e L U ( C o n v 1 D 1 ( X i n ) ) )
X c n n ( 2 ) = M a x P o o l ( R e L U ( C o n v 1 D 2 ( X c n n ( 1 ) ) ) )
Through the two-layer cascaded extraction, the final feature channel number is expanded to 64.
Where X i n ∈ R B × 1 × L and L strictly denotes the temporal sequence length of consecutive network flows. Through the two-layer cascaded extraction, without altering the temporal sequence length L, the final feature channel number is expanded to C = 64, preparing the temporal features for subsequent global sequence modeling.

3.1.2. Channel Feature Recalibration

Because traditional convolutional operators process all channel features indiscriminately within a local receptive field, crucial discriminative information can easily be submerged. To overcome this representational limitation, further enhance the model’s perceptual sensitivity to high-value features, and substantially improve the model’s prediction accuracy, this paper introduces the Squeeze-and-Excitation channel attention mechanism after CNN feature extraction. This mechanism aims to explicitly model the nonlinear dependencies between channels, dynamically amplifying the key features with the highest discriminative power for the current classification task. First, Adaptive Global Average Pooling is utilized to squeeze the high-dimensional feature maps X c n n ( 2 ) output by the CNN into a channel descriptor with a global receptive field, achieving information aggregation in the spatial dimension. The specific process can be represented by the formula:
z = G A P ( X c n n ( 2 ) )
The following describes feeding the descriptor z into a two-layer bottleneck fully connected network with a dimensionality reduction factor r = 2 . Through the combined activation of ReLU and Sigmoid, the model adaptively learns the nonlinear dependencies of each channel feature, generating an attention weight vector s that represents the channel importance coefficients, as shown in Formula (4):
s = σ ( W 2 δ ( W 1 z ) )
where W1 and W2 are weight matrices, δ is the ReLU activation function, and σ is the Sigmoid activation function.
Finally, the dynamic feature re-calibration involves multiplying the weight vector s by the original feature map X c n n ( 2 ) channel-by-channel to complete feature recalibration, as detailed in Formula (5):
X s e = X c n n ( 2 ) ⊗ s
Through this mechanism, the model forcibly amplifies high-value features and effectively suppresses redundant noise. This “false-eliminating and truth-retaining” feature filtering process significantly elevates the purity of the features fed into the subsequent temporal modules, laying a solid foundation for the model to achieve high-precision predictions in complex scenarios.

3.1.3. Global Feature Dependency Modeling

The recalibrated features are fed into a Bidirectional LSTM to capture genuine temporal traffic flow dynamics over the sequence window L. It is important to note that the input sequence strictly comprises historical flows to prevent future data leakage, with its hidden state representation denoted as h t = [ h → t ; h ← t ] . Subsequently, the self-attention mechanism of the Transformer is introduced to establish a global receptive field, performing non-linear mapping across these high-dimensional feature components to identify complex correlations that may span across different segments of the feature space.
First, the sequence of feature blocks is mapped into three independent spaces via linear transformations to generate the Query, Key, and Value vectors. This step serves as the foundation for the model to precisely capture global dependencies between disparate feature clusters, as shown in Formula (6):
Q = X l s t m W Q ,   K = X l s t m W K ,   V = X l s t m W V
Then, the self-attention weights are calculated, enabling the model to dynamically focus on key associations between these feature components within the input, as given by Formula (7):
A t t e n t i o n ( Q , K , V ) = s o f t m a x ( Q K T d k ) V
To further enhance the model’s non-linear fitting capability and the depth of feature representation, the output of the attention module passes through a Feed-Forward Network equipped with residual connections and layer normalization, represented by Formula (8):
F F N ( X a t t n ) = L a y e r N o r m ( X a t t n + L i n e a r 2 ( G E L U ( L i n e a r 1 ( X a t t n ) ) ) )
It is precisely through the deep fusion of the aforementioned structures—leveraging the global spatial mapping of the QKV mechanism and the deep non-linear activation of the FFN—that the model’s ability to extract discriminative, high-level traffic patterns is significantly elevated. This architectural synergy allows the model to map the input features into an optimal representation space, fundamentally guaranteeing high-precision classification for complex, heterogeneous network traffic.

3.2. Lightweight Reconstruction and Fusion

Although the aforementioned hybrid architecture can significantly elevate accuracy, this brute-force module concatenation inevitably triggers a severe computational disaster. In standard implementations, it generates millions of redundant parameters. Furthermore, the bias terms attached to each layer in the network and the affine parameters of the normalization layers cause unnecessary memory occupation. This phenomenon of “parameter explosion” renders high-precision fusion models extremely bloated, making them completely undeployable on resource-constrained edge computing devices.
To resolve the core contradiction between high precision and massive parameter volume, this paper adopts a top-down, layer-by-layer pruning strategy without altering the macro-topological structure of the hybrid architecture. Spanning from strict alignment at the macro dimension to bias stripping at the micro operator level, and finally to the micro-customization of core modules, this paper proposes an “extreme lightweight” reconstruction scheme, successfully restricting the model’s total parameter count strictly to the 70,000 level.

3.2.1. Shallowing of Macro Architecture and Strict Dimensional Alignment

The first step in model lightweighting is to fundamentally constrict the feature dimensions, avoiding redundant projection calculations during module interaction. During the CNN feature extraction phase, the network’s output dimension is constrained to 64; during the temporal feature extraction phase, the LSTM is drastically reduced to a single layer, and the number of units in its unidirectional hidden layer is strictly set to 32. The concatenated bidirectional output dimension of the LSTM equals exactly 64, which perfectly aligns with the hidden layer dimension requirement of the subsequent Transformer module d m o d e l = 64 . Through this seamless dimensional alignment, the model completely eliminates the extra linear mapping layers that must typically be introduced between different modules due to dimension mismatches, thereby cutting off parameter redundancy right at the architectural entry point.

3.2.2. Unbiased and Affine-Free Operator Reconstruction

The traditional network layer is defined as Y = W X + b . As the second step, this paper delves into the foundational operators, executing an extreme “de-redundancy” operation on a global scale. First, the model forcibly removes the learnable bias vectors from all 1D convolutional layers and fully connected mapping layers. Concurrently, for Batch Normalization and Layer Normalization, The learnable scaling parameter γ and translation parameter β have been frozen, retaining only the pure statistical standardization process, as shown in Formula (9):
Y n o r m = X − μ σ 2 + ϵ
This foundational operator-level optimization alone eliminates thousands of redundant scalar parameters across the entire network without compromising the model’s depth.

3.2.3. Micro-Customization of Core Transformer Components

The most bloated component in the fusion architecture is the Transformer. In the third step, this paper thoroughly deconstructs and miniaturizes its internal mechanisms: firstly, a TinySelfAttention module is proposed to replace the protracted multi-head mechanism of the native Transformer. This module retains only a single-head attention mechanism and limit the dimension d m o d e l of the hidden layer to 64. To further squeeze out parameters, the three independent matrix multiplications in traditional models are consolidated into a single unbiased linear layer. A tensor with a one-time output dimension of d m o d e l × 3 is then split greatly reducing the parameter count of matrix multiplications. The specific formula is expressed as (10):
Q K V = W q k v X n o r m ,   W q k v ∈ R 3 d m o d e l × d m o d e l
Secondly, targeting the Feed-Forward Network, a TinyFFN is proposed. It discards the practice in traditional Transformers of expanding the internal hidden layer dimension by a factor of 4. Instead, it extremely restrainedly set the internal dimension d f f to 128, resulting in only a two-fold expansion. The specific formula is shown as (11):
T i n y F F N ( X ) = W 2 ( G E L U ( W 1 X ) ) ,   W 1 ∈ R d f f × d m o d e l , W 2 ∈ R d m o d e l × d f f
The miniaturization of these two core modules drastically compresses the Transformer encoder layer—which typically boasts millions of parameters—down to approximately 32,700 parameters. While preserving the global receptive field, it thoroughly shatters the computational barriers to edge deployment. To present this operator-level lightweight design more intuitively, Figure 2 details the deconstruction of the internal forward propagation data flow within the Tiny Transformer Encoder Layer. This figure illustrates the complete data flow of the feature matrix through the single-head self-attention and the micro feed-forward network.In the figure, the ellipsis (…) represents the continuous temporal sequences of the feature map.
Figure 2. Internal architecture of the Tiny Transformer encoder.

3.2.4. Lightweight Substitution of Auxiliary Feature Modules

Regarding auxiliary attention and positional information, this paper adopts a substitution strategy to design the TinySEBlock and TinyPositionalEncoding. In the TinySEBlock channel attention, by combining adaptive average pooling with a two-layer unbiased linear bottleneck structure and maintain the dimension reduction ratio at r = 2 , the module requires a precise control of merely 4096 parameters to accomplish channel recalibration. The specific flowchart of TinySEBlock is shown in Figure 3.
Figure 3. Flowchart of TinySEBlock.
In terms of positional encoding, traditional trigonometric encodings are computationally cumbersome, whereas full-size learnable matrices equal in length to the sequence possess an excessively large parameter count. This paper adopts a minimalist embedding lookup table as a replacement, with the formula expressed as (12):
X p o s _ e n c o d e d = X + E p o s [ p o s _ i n d i c e s ]
The size of this table is fixed at 64 × 64 , keeping its parameter count precisely constant at 4096, thereby achieving the injection of temporal information at an extremely low cost.

3.2.5. Zero-Parameter Accuracy Compensation: Label Smoothing Regularization

The extreme streamlining of foundational operators inevitably weakens the model’s absolute capacity, making it prone to feature loss during training. To ensure that the lightweight reconstruction does not come at the expense of the high accuracy brought by the prior fusion architecture, the final step introduces a compensation strategy that adds absolutely zero trainable parameters. This paper introduces a label smoothing loss function with a smoothing coefficient α = 0.08 in the training objectives. For the actual one-hot labels y , they are transformed into a soft distribution, as specified in formula (13):
y i L S = 1 − α + α K , i f   i = t a r g e t α K , o t h e r w i s e L L S = − ∑ i = 1 K y i L S log ( p i )
where K is the number of classes, and p i is the predicted probability of the model. Simultaneously, the training process is coupled with the weight decay mechanism of the AdamW optimizer and Automatic Mixed Precision (AMP). This multi-pronged, zero-parameter regularization strategy effectively prevents the lightweight model from overfitting to hard labels. It enables the model to maintain and output high-precision results comparable to the original heavy hybrid architecture, even after experiencing a precipitous pruning of its parameter scale.

3.2.6. Edge Deployment Adaptation

To bridge the gap between algorithmic design and physical hardware execution, TinyFlowNet incorporates an edge deployment adaptation phase. Following the zero-parameter accuracy compensation training, the optimized PyTorch (version 2.4.1) model is converted into the Open Neural Network Exchange (ONNX) format. This process performs an automated graph-level optimization—specifically, operator fusion and constant folding—to minimize the computational graph complexity. This fundamental structural simplification strips away dynamic Python (version 3.8.10) runtime overhead, ensuring that the model maintains high computational efficiency directly on the hardware’s execution engine.

4. Experimental

4.1. Datasets

To comprehensively and objectively evaluate the overall performance of the proposed lightweight model, TinyFlowNet, Section 4 selects three network traffic datasets with varying data distributions and application scenarios. These three datasets are progressively structured in their evaluation logic advancing from fundamental multidimensional feature extraction capability, to the representational limits under constrained samples and encrypted environments, and finally to deployment feasibility in heterogeneous IoT edge scenarios.

4.1.1. Custom Dataset (X-IDS-20)

To overcome the inherent limitations of massive scale, long-tail class imbalance, and heterogeneous feature spaces in existing public benchmarks, this study constructs a streamlined, highly balanced, and cross-platform comprehensive traffic dataset named X-IDS-20. This dataset aims to accelerate ablation studies for lightweight models and provide a rigorous benchmark for heterogeneous IoT edge scenarios. Addressing the critical aspects of dataset construction, feature alignment, and reproducibility, the detailed methodology is outlined as follows:
(1)
Source Datasets and Feature Alignment: The X-IDS-20 dataset integrates raw network traffic data from five authoritative cybersecurity organizations: CIC-IDS-2017, CIC-IDS-2018, CSE-CIC-IDS2018, UNSW-NB15, and CTU-13. Given the varied feature definitions across these platforms, a systematic feature alignment and standardization process was executed. We extracted and computed the 20 most discriminative core features that represent the fundamental properties of network flows. These 20-dimensional features are categorized into four groups: Temporal Features (e.g., timestamps, hour of day, day of week), Network Attributes (e.g., IP, port, protocols), Flow Statistical Metrics (e.g., packet size, packet count, flow duration, byte/packet rate), and QoS/Anomaly Indicators (e.g., latency, jitter, TCP anomalies, HTTP error rates).
(2)
Data Cleaning and Deduplication: To ensure the high quality and independence of the samples, rigorous data cleaning protocols were applied. Invalid records containing NaN or Infinity values were purged. Furthermore, strict deduplication mechanisms were employed to remove overlapping, duplicate, or conflicting records that inherently exist when merging cross-source datasets.
(3)
Stratified Sampling Strategy and Class Balance: Traditional datasets suffer from severe class imbalance, which introduces evaluation bias (overfitting to the majority class). To eliminate this, X-IDS-20 employs a strict uniform sampling strategy. Spanning a simulated temporal range from January 2022 to July 2024, the final dataset retains exactly 30,000 high-quality records. It encompasses one normal traffic category and seven typical attack categories: DDoS, SQL Injection, Port Scan, Botnet, Data Exfiltration, Brute Force, and Anomalous Encryption. The sampling rule strictly controlled each of the 8 categories to contain exactly 3750 records, achieving a mathematically perfect distribution of 12.5% per class.
(4)
Reproducibility and Public Availability: We fully acknowledge the importance of reproducibility in cybersecurity research. The rigorous multi-source feature extraction and class-balancing ensure that X-IDS-20 faithfully retains the typical distributions of diverse attack patterns while maintaining an ultra-lightweight footprint (approx. 3.9 MB). To ensure that our key claims can be validated independently by the community while strictly adhering to academic publication policies, the complete X-IDS-20 dataset, along with the Python processing scripts detailing the feature alignment and sampling rules, are available from the corresponding author upon reasonable request. Furthermore, the entire dataset and codebase will be formally released in a public academic repository upon the acceptance and publication of this manuscript.

4.1.2. CICDarknet2020

Encrypted Traffic Dataset Released by the Canadian Institute for Cybersecurity, this dataset focuses on the fine-grained differentiation between regular traffic and highly obfuscated encrypted traffic, such as Tor and VPN. To evaluate the representational limits of the model under the dual challenges of a “highly complex encryption scenario” and “restricted sample size,” this experiment conducted a 10% distribution-preserving stratified sampling on the original dataset. This subset aims to verify whether the proposed CNN and SE modules can precisely capture the microscopic key features of encrypted traffic with minimal data throughput under extreme parameter compression, thereby maintaining model robustness in adversarial environments.

4.1.3. ToN_IoT

Security Benchmark Dataset Published by the University of New South Wales, this dataset records the authentic communication states of IoT nodes subjected to nine major categories of complex attacks, including backdoors, ransomware, and Man-in-the-Middle. To realistically simulate the storage and computation-constrained deployment environments of edge computing nodes while eliminating data redundancy, this experiment performed stratified sampling to extract a 10% network traffic subset. While preserving the heterogeneous characteristics of the data, this strategy tests the model’s generalization capability against unknown attack variants using a stringently limited sample size. Furthermore, in conjunction with FLOPs and inference latency metrics, this subset is utilized to rigorously demonstrate the feasibility of the proposed architecture for real-time security protection in low-power IoT devices.

4.2. Data Processing and Feature Analysis

4.2.1. Data Preprocessing and Splitting

To guarantee the efficient processing of the custom-built comprehensive dataset for main experiments, as well as the CICDarknet2020 and ToN_IoT datasets used for generalization validation in complex scenarios, this study constructed a unified, standardized preprocessing pipeline. First, Label Encoding is adopted to convert discrete features, such as protocols and services, into numerical tensors. Furthermore, missing values and infinite values within the feature space are cleaned through zero-imputation and extreme-value truncation to ensure the numerical stability of deep network computations. Second, a normalization strategy is applied to eliminate massive dimensional disparities among heterogeneous traffic metrics, thereby accelerating optimizer convergence. In the data splitting phase, to align with the computational constraints of edge devices, a 10% scale reduction was pre-executed on the high-dimensional and massive CICDarknet2020 dataset. Subsequently, all three major datasets uniformly employed distribution-preserving stratified sampling to divide the data into training and testing sets at a 4:1 ratio, strictly precluding evaluation bias caused by class imbalance.
To rule out potential data-label leakage, rigorous constraints were enforced. First, to prevent identity-based leakage, all explicit routing identifiers were completely stripped; the model relies solely on intrinsic behavioral statistics. Second, to prevent temporal look-ahead leakage within the bidirectional sequence models, our sliding window strictly inputs consecutive historical traffic states, ensuring no future flow information is inadvertently used.

4.2.2. Spatio-Temporal Feature Visualization

Following data cleaning and feature normalization, to deeply investigate the underlying data structure of edge network traffic and further validate the discriminability of the extracted 20-dimensional core features, this study conducts grayscale visualization on eight categories of traffic samples. Traditional methods typically treat a single network flow as an isolated data point, neglecting the continuous burstiness and temporal evolution characteristics often exhibited by network attacks in real-world scenarios. Therefore, this study aggregates and concatenates 20 consecutive network flow samples belonging to the same category to construct a 20 × 20 2D spatio-temporal feature matrix. In this matrix, each pixel’s grayscale value directly corresponds to the normalized numerical value of a traffic feature. The horizontal axis represents the 20-dimensional statistical features, reflecting the spatial topological correlation among features, while the vertical axis represents 20 consecutive samples in the time series, reflecting the temporal evolution of attack behaviors. The results are shown in Figure 4.
Figure 4. Grayscale Image of Network Traffic in the X-IDS-20 Dataset.
Different attack types manifest distinctly different texture patterns akin to “barcodes.” For instance, DDoS attacks exhibit extremely bright and continuous vertical bands on specific feature columns, reflecting their high-frequency and uniform flooding characteristics; conversely, SQL injection and port scanning present discrete grid-like distributions. This demonstrates the high discriminative power of the preprocessed features. The simultaneous presence of horizontal local feature mutations and vertical temporal gradations in the images profoundly indicates that a single CNN with only a local receptive field cannot adequately correlate contextual samples, while a single RNN struggles to mine the geometric distribution among multiple features simultaneously. This dual “spatio-temporal” coupled data distribution lays a solid data foundation for achieving high-precision classification with the proposed lightweight TinyFlowNet model. It validates that the custom dataset possesses clear category boundaries without sample confusion, providing a robust theoretical basis for the model to maintain excellent detection performance even under extreme parameter compression.

4.2.3. Implementation Details and Hyperparameter Configurations

To guarantee full transparency and reproducibility of the proposed TinyFlowNet, we explicitly detail the layer-wise dimensions, activation functions, and training hyperparameters. Regarding the network architecture, the local feature extraction phase utilizes two 1D convolutional layers with output channels of 32 and 64, strictly coupled with affine-free Batch Normalization and ReLU activation functions. The subsequent TinySEBlock employs ReLU and Sigmoid activations for a 64-32-64 dimensional bottleneck channel recalibration. The temporal modeling utilizes a single-layer Bidirectional LSTM with a hidden size of 32, concatenating to a 64-dimensional representation. Finally, the Tiny Transformer encoder maintains a hidden dimension of 64, employing the GELU activation function within its intermediate 128-dimensional Feed-Forward Network.
During the training phase, all models were implemented using the PyTorch framework and trained end-to-end on an NVIDIA RTX GPU platform. The network was optimized using the AdamW optimizer with an initial learning rate of 0.004 and a weight decay of 3 × 1 0 − 5 . To prevent overfitting to hard labels, a label smoothing cross-entropy loss function with a smoothing coefficient of 0.08 was applied. The training process was conducted with a batch size of 64 for a maximum of 100 epochs. Furthermore, we employed a ReduceLROnPlateau scheduler (with a reduction factor of 0.5 and a patience of 5 epochs) for dynamic learning rate decay. To prevent redundant computations, an early stopping mechanism with a patience of 20 epochs was integrated to halt training when the validation accuracy plateaued. Additionally, to ensure gradient stability under extreme lightweight configurations, gradient clipping with a maximum norm of 0.8 was strictly enforced.

4.3. Evaluation Metrics

To comprehensively validate the effectiveness and deployment feasibility of the TinyFlowNet model for practical IoT boundary protection, this study adopts a multidimensional evaluation framework comprising classification performance and hardware efficiency metrics.

4.3.1. Classification Performance Evaluation Metrics

Given the significant class imbalance inherently present in multi-class network traffic, relying solely on overall Accuracy may obscure the model’s performance on minority attack classes. Therefore, this study introduces Macro-averaged Precision, Recall, and F1-Score as core discriminative metrics. Furthermore, to provide a more holistic evaluation of the model’s robustness under such skewed distributions, threshold-independent metrics including the Matthews Correlation Coefficient (MCC), Receiver Operating Characteristic Area Under Curve (ROC-AUC), and Precision-Recall AUC (PR-AUC) are also incorporated.
Assuming the dataset contains N categories, for the ith category, let TPi be True Positives, FPi be False Positives, TNi be True Negatives, and FNi be False Negatives. The mathematical definitions of the evaluation metrics are as follows:
A c c u r a c y = ∑ i = 1 N ( T P i + T N i ) ∑ i = 1 N ( T P i + T N i + F P i + F N i )
P r e c i s i o n i = T P i T P i + F P i
R e c a l l i = T P i T P i + F N i
F 1 − S c o r e i = 2 × P r e c i s i o n i × R e c a l l i P r e c i s i o n i + R e c a l l i
To rigorously quantify the classification performance on imbalanced minority classes, the Matthews Correlation Coefficient for the i-th category is formulated as:
M C C i = T P i × T N i − F P i × F N i ( T P i + F P i ) ( T P i + F N i ) ( T N i + F P i ) ( T N i + F N i )
Additionally, ROC-AUC and PR-AUC evaluate global classification boundaries independent of threshold settings using integrals:
T P R i = R e c a l l i = T P i T P i + F N i ,   F P R i = F P i F P i + T N i
R O C − A U C i = ∫ 0 1 T P R i   d ( F P R i )
P R − A U C i = ∫ 0 1 P r e c i s i o n i   d ( R e c a l l i )

4.3.2. Lightweight and Efficiency Evaluation Metrics

To substantiate the deployment feasibility of TinyFlowNet in resource-constrained environments and comprehensively quantify its “lightweight” characteristics, this study establishes a multidimensional evaluation framework. This framework assesses the model’s performance through both theoretical complexity metrics and physical hardware-centric profiling.
Theoretical efficiency is evaluated using Parameter Count, which reflects the static memory footprint, and MFLOPs, which acts as the standard for computational cost. To intuitively quantify the model’s real-time responsiveness and physical throughput, we introduce hardware-centric profiling metrics: Inference Latency, System Throughput, and Thermal Stability. The specific mathematical formulas for these metrics are defined as follows:
L = 1 N ∑ i = 1 N t i
T = N ∑ i = 1 N t i
Δ Θ = Θ e n d − Θ s t a r t

4.3.3. Statistical Reliability and Repeated Runs

To rigorously validate the statistical reliability of the proposed architecture and eliminate performance bias caused by favorable random initialization, TinyFlowNet was evaluated using a 5-fold repeated runs strategy. The model was independently trained and evaluated five times using different random seeds for data shuffling and weight initialization.
As shown in Table 1, the 5-run statistical results demonstrate an average Accuracy of 0.9445 ± 0.0059 and a high ROC-AUC of 0.9947 ± 0.0008. The extremely low standard deviations across all comprehensive metrics explicitly prove the high robustness and statistical significance of the TinyFlowNet architecture. It is important to note that for practical edge deployment, the ultimate goal is to utilize the optimal model weights. Therefore, to reflect the performance ceiling of the deployable models, the subsequent comparative experiments uniformly report the performance of the optimal deployable model.
Table 1. Statistical evaluation results of TinyFlowNet under 5 repeated runs.

4.4. Analysis of Experimental Results

4.4.1. Analysis of Training Convergence and Generalization Stability

To verify the convergence health and generalization stability of the proposed TinyFlowNet model throughout the learning process, and to avoid the overfitting pitfalls common in deep networks, Figure 5 details the complete training dynamics of the model under optimal hyperparameter configurations.
Figure 5. Training convergence and generalization performance curves of the TinyFlowNet model: (a) Downward trend of training loss; (b) Synchronous convergence comparison between training set and test set accuracy.
As illustrated by the training loss curve in Figure 5a, the loss exhibits a rapid and monotonically convergent decline within the initial 10 epochs. This rapid convergence indicates that the cascaded feature space effectively captures highly discriminative features from heterogeneous traffic, enabling the optimizer to successfully bypass local minima. Furthermore, Figure 5b depicts the synchronous evolution of the training and test set accuracies. Unlike traditional deep fusion models, which frequently suffer from a severe “generalization gap” due to massive parameter counts, TinyFlowNet demonstrates exceptional synchronous convergence. The test accuracy surges past 90% in early epochs and tightly tracks the training accuracy during the subsequent plateau phase, with the discrepancy strictly constrained within 2%.
This ideal synchronous convergence provides direct evidence of the model’s superior generalization capability. The underlying mechanism attributes to the synergy between local convolutions and the global attention mechanism, which precisely isolates the core spatio-temporal structures defining attack attributes. Consequently, TinyFlowNet maintains high inference robustness against unknown complex attack patterns, thoroughly circumventing the overfitting risks prevalent in traditional deep networks.

4.4.2. Comparison with Existing Lightweight Benchmark Models

To objectively validate the deployment advantages of the proposed TinyFlowNet in edge computing environments, this section selects representative benchmark models for a comprehensive lateral comparison of performance. The comparative models include MobileNetV2 based on depthwise separable convolutions, EfficientNet-EdgeTPU featuring an extremely lightweight architecture optimized for edge TPUs, DistilBERT as a lightweight Transformer model based on knowledge distillation, and a standard heavy Hybrid CNN-LSTM-Transformer to represent unoptimized multi-module concatenation. The evaluation dimensions encompass classification accuracy and F1-Score alongside core hardware metrics like Params, FLOPs, and Latency. The detailed quantitative comparison data are shown in Table 2. Concurrently, to intuitively demonstrate the comprehensive trade-off between accuracy and computational overhead for each model, Figure 6 plots a scatter comparison of classification accuracy versus single-sample inference latency.
Table 2. Comparison of lightweight benchmark models.
Figure 6. Scatter comparison plot of classification accuracy versus single-sample inference latency for each model.
As shown in Table 2 and Figure 6, existing models struggle to balance accuracy and computational overhead. EfficientNet-EdgeTPU achieves extreme compression but suffers a precipitous accuracy drop to 0.7188. DistilBERT reaches a higher accuracy of 0.9375 but requires 1.24 million parameters, making it unsuitable for micro-nodes, while MobileNetV2 exhibits severe computational redundancy. Even the heavy Hybrid CNN-LSTM-Transformer, despite achieving a strong accuracy of 0.9456, triggers a severe parameter explosion reaching 12.32 million parameters and 57.03 million FLOPs. In contrast, TinyFlowNet achieves an optimal trade-off. It reaches a superior accuracy of 0.9531, with an exceptional Matthews Correlation Coefficient of 0.9465 and ROC-AUC of 0.9938, comprehensively outperforming all baselines. Simultaneously, it strictly compresses its parameter count to 74,600 and inference latency to 0.71 ms, proving its customized minimalist architecture successfully meets the real-time deployment requirements for edge network intrusion detection.
Although static final performance metrics corroborate the model’s representation capability, they struggle to reflect the feature fitting efficiency and gradient propagation status during the optimization process. To further investigate the internal optimization mechanisms during training and intuitively demonstrate the superiority of the proposed architecture design, Figure 7 details the dynamic convergence process of training loss and testing accuracy for TinyFlowNet and the three baseline models over 100 epochs.
Figure 7. Dynamic comparison of the training convergence process between TinyFlowNet and Baselines: (a) Downward curve of training loss; (b) Upward curve of testing accuracy.
As shown in the convergence trajectories of Figure 7a,b, 1D-EfficientNet exhibits sluggish convergence with persistently high loss, highlighting the representational damage caused by excessive pruning. Meanwhile, despite achieving a high final accuracy, DistilBERT suffers from severe initial oscillations, indicating that heavy baseline models easily fall into local optimization dilemmas on limited edge datasets. Conversely, TinyFlowNet converges rapidly, with its accuracy surpassing 90% within just 15 epochs before smoothly entering a stable plateau. This rapid, oscillation-free convergence validates our core architectural designs: operator-level reconstruction accelerates gradient propagation by eliminating redundant noise, while the zero-parameter regularization effectively suppresses early overfitting. Consequently, TinyFlowNet successfully reconciles the traditional trade-off between extreme lightweight compression and stable training convergence.

4.4.3. Comparative Evaluation of Baseline Architectures

Having clarified the relative advantages over lightweight benchmark models, to further demonstrate the necessity of the TinyFlowNet architecture, this paper compares it with traditional foundational temporal networks. These include: LSTM, CNN, Transformer encoder, CNN+GRU, CNN+TCN, and the proposed TinyFlowNet model. The results are shown in Table 3.
Table 3. Comparison of baseline architectures.
Concurrently, to intuitively present the matching relationship between model prediction results and true labels, and to further analyze the classification error distribution of different models, this study plots the confusion matrices for each deep learning model, as detailed in Figure 8.
Figure 8. Confusion matrices for each deep learning model. (a) Confusion matrix of the TinyFlowNet model; (b) Confusion matrix of the LSTM model; (c) Confusion matrix of the CNN model; (d) Confusion matrix of the Transformer model; (e) Confusion matrix of the CNN+GRU model; (f) Confusion matrix of the CNN+TCN model.
Figure 9 is a scatter comparison plot of model parameter count versus classification accuracy, which intuitively presents the trade-off relationship between parameter count and accuracy for the six intrusion detection models. It serves primarily to highlight the lightweight advantages of the proposed TinyFlowNet model.
Figure 9. Scatter comparison plot of model parameter count and classification accuracy.
Experimental results demonstrate that while baseline CNN and Transformer models are more lightweight, their accuracies drop significantly by 7.12 and 11.31 percentage points compared to TinyFlowNet, with F1-Scores falling by 7.05 and 11.27 points, respectively. This representational deficiency is even more severely exposed in threshold-independent evaluations. For instance, the single Transformer architecture suffers a catastrophic drop in MCC to merely 0.8177 and a PR-AUC of 0.8909, explicitly revealing its vulnerability and severe bias when handling imbalanced minority attacks. Conversely, heavy-parameter models like LSTM and CNN+TCN consume far more resources yet still underperform, exhibiting accuracy reductions of 7.06 and 4.00 percentage points, alongside a noticeably degraded ROC-AUC score of 0.9810 for the LSTM model. Furthermore, even when compared to a lighter fusion alternative like CNN+GRU, TinyFlowNet maintains a 4.69% accuracy and 4.61% F1-Score lead.
Ultimately, with merely 74,600 parameters, TinyFlowNet achieves the highest overall accuracy of 0.9531 and an exceptional MCC of 0.9465. Its near-perfect ROC-AUC of 0.9938 and PR-AUC of 0.9679 further corroborate that rather than blindly compressing the network scale, our hybrid architecture fully exploits multi-module synergy to achieve a superior performance-complexity balance. By simultaneously overcoming the resource exhaustion of massive networks and the representational deficiencies of overly pruned models, TinyFlowNet provides a highly efficient and practical paradigm for network intrusion detection in resource-constrained edge environments.
In summary, the experimental results demonstrate the superiority of TinyFlowNet: compared to heavy baselines, it achieves superior detection performance while drastically reducing computational overhead; compared to existing lightweight benchmarks, it maintains a lower parameter count while providing significant accuracy gains. These findings confirm that TinyFlowNet offers an optimal performance-complexity balance, establishing a highly efficient and practical paradigm for intelligent edge-based network intrusion detection.

4.5. Cross-Dataset Generalization and Robustness Validation

The ultimate objective of model lightweighting is to address real-world, dynamic network boundary defense environments. To verify that TinyFlowNet does not suffer from overfitting dependence on specific data distributions, and to demonstrate its generalization reliability and deployment robustness across diverse, real-world network boundary defense scenarios, this paper introduces two highly challenging public benchmark datasets, ToN_IoT and CICDarknet2020, for cross-domain validation. The results are presented in Table 4.
Table 4. Cross-dataset validation results.
Furthermore, to further validate the generalization capability and lightweight performance of TinyFlowNet on cross-scenario heterogeneous data, Figure 10 visually illustrates the comprehensive performance of the model across the three major datasets: ToN_IoT, CICDarknet2020, and the custom-built X-IDS-20.
Figure 10. Bar chart comparison of classification accuracy and FLOPs across different datasets.
The experimental data amply demonstrate that TinyFlowNet successfully overcomes the defects of overfitting and specific distribution dependency often associated with lightweight models, exhibiting exceptional generalization efficacy across multi-source heterogeneous data. When confronting the complex edge device attack variants in ToN_IoT, the model achieved a high accuracy of 0.9713 and an F1-Score of 0.9555, complemented by a robust Matthews Correlation Coefficient of 0.9671 along with exceptional ROC-AUC and PR-AUC scores of 0.9986 and 0.9834, respectively. Moreover, in the highly obfuscated and extremely difficult CICDarknet2020 darknet classification task, the accuracy soared to an impressive 0.9953. This performance is further validated by a Matthews Correlation Coefficient of 0.9900 and strong ROC-AUC and PR-AUC scores of 0.9906 and 0.9516, which decisively prove that the model maintains robust boundary delineation even in complex unknown environments.
More importantly, the cross-dataset experiments further corroborate the formidable lightweight robustness of the model architecture. Although differences in input feature dimensions and the number of target categories across datasets caused adaptive fluctuations within a reasonable range for both parameter count and floating-point operations during model adaptation, the overall scale remains strictly confined within an extremely rigorous micro-computing threshold. It is particularly worth emphasizing that, regardless of the dimensional complexity of the feature space it confronts, TinyFlowNet’s single-sample inference latency consistently remains highly stable at the ultra-low level of 0.71 ms. This stable performance of consistently maintaining low-latency inference across multi-source heterogeneous data not only verifies the high determinism of the model in terms of time complexity but also strongly argues for TinyFlowNet’s outstanding deployment potential for executing real-time online defense tasks on compute-constrained edge nodes.

4.6. Zero-Day Anomaly Detection Capability

To evaluate TinyFlowNet’s robustness against zero-day threats, we conducted a Leave-One-Out anomaly detection experiment by entirely withholding a specific attack (e.g., Brute Force, Class 5) during training. During testing, 200 samples of this unseen attack were reintroduced alongside known traffic. Rather than classifying the exact novel label—an open-set problem beyond the scope of lightweight classifiers—the objective is to verify if the model can flag these unseen payloads as anomalous, preventing them from bypassing the firewall as benign traffic.
As shown in Table 5, TinyFlowNet achieved a 100.00% Anomaly Detection Rate. It successfully isolated all 200 zero-day samples into malicious categories without a single misclassification as benign traffic. Concurrently, the model maintained a robust overall testing accuracy of 85.25%, demonstrating that it avoids prediction collapse and retains stable decision boundaries for known classes. This zero-leakage performance empirically validates that TinyFlowNet’s multi-module fusion provides highly effective heuristic anomaly detection for real-world edge deployment.
Table 5. Zero-Day Attack (Leave-One-Out) Detection Performance.

4.7. On-Device Hardware Deployment and Edge Profiling

Existing lightweight network security models often rely on theoretical estimates like FLOPs, lacking empirical validation on physical edge environments. To address this gap and validate the real-time defense capability of TinyFlowNet, we established a hardware profiling testbed on a Raspberry Pi 4B (Raspberry Pi Foundation, Cambridge, UK) Model B equipped with a Broadcom BCM2711 processor and 8GB RAM. The model was converted to ONNX format to maximize execution efficiency. Table 6 summarizes the comprehensive full-dimensional hardware benchmarking conducted over 1000 continuous inference cycles.
Table 6. Comprehensive on-device hardware profiling results for TinyFlowNet.
TinyFlowNet demonstrates exceptional storage and resource efficiency. The converted ONNX model occupies only 0.30 MB of storage, while the dynamic memory footprint during inference remains as low as 8.26 MB. With a total process RAM peak usage of 48.07 MB, the model is highly suited for deployment on memory-constrained IoT devices.
Regarding speed and system stability, the profiling results confirm the superior performance of TinyFlowNet. The model achieves an average inference latency of 0.79 ms and a high sustained throughput of 1266.33 FPS. The P99 long-tail latency of 2.05 ms indicates that the model operates with high determinism and avoids severe latency spikes. Furthermore, during a sustained stress test with 100% CPU utilization, the device temperature showed excellent thermal stability, increasing marginally from 55.5 °C to 57.9 °C. This minimal thermal envelope makes TinyFlowNet ideal for continuous, fanless 24/7 operation in real-world intelligent edge protection scenarios.

4.8. Analysis of Hyperparameter Variations and Model Performance

4.8.1. Impact of Batch Size Variations on Model Performance

This experiment aims to systematically investigate the synergistic impact mechanism of learning rate and batch size on the performance and training efficiency of deep learning models. By constructing multiple sets of controlled experiments, the performance and time costs of the TinyFlowNet model under different hyperparameter configurations are tested to determine the optimal parameter combination, thereby achieving a balanced optimization of model accuracy and training speed. The experiment evaluates six gradients for batch size and tests the optimal accuracy, optimal training time, and running time of the TinyFlowNet model under these different batch sizes. The specific experimental results are detailed in Table 7.
Table 7. Optimal accuracy parameters for different batches.
As indicated in Table 7, a batch size of 8 yields an accuracy of 0.9431 at the 34th epoch but suffers from prolonged training time and low computational resource utilization. Conversely, increasing the batch size to 128 and 256 drastically reduces training time but causes an observable decline in optimal accuracy and premature convergence. Ultimately, setting the batch size to 64 emerges as the optimal configuration, reaching the highest overall accuracy of 0.9531 at the 52nd epoch. This specific setting significantly accelerates training compared to smaller batches, achieving a highly effective balance between classification performance and computational efficiency for practical deployment.

4.8.2. Impact of Learning Rate Variations on Model Performance

To systematically optimize the lightweight model, this study investigates the synergistic impact of learning rate and batch size on training efficiency. Because the learning rate dictates convergence dynamics while batch size influences generalization stability, joint tuning is essential to prevent optimization failure or degraded performance.
To quantify these effects, comparative experiments were designed with the training duration strictly fixed at 100 epochs. Specifically, the model was evaluated under two distinct learning rates: 0.004 and 0.002. The corresponding classification accuracy, execution time, and overall operational efficiency metrics under these configurations are detailed in Table 8 and Table 9.
Table 8. TinyFlowNet model performance metrics at a learning rate of 0.004.
Table 9. TinyFlowNet model performance metrics at a learning rate of 0.002.
Table 8 and Table 9 show that the configuration of a 0.004 learning rate and 64 batch size delivers optimal overall performance: all metrics reach their peaks, and training time is minimized to 37.36 s. Compared with the far longer training duration at batch size 8, this setup balances classification precision and computational efficiency well. Figure 11 visualizes the multidimensional comparison across all configurations.
Figure 11. Multidimensional comparison of model performance under different learning rate and batch size configurations.
With a fixed batch size, the 0.004 learning rate outperforms 0.002 on all performance metrics. An appropriate learning rate prevents both slow parameter updates and insufficient feature fitting caused by too low a rate, as well as gradient oscillations from an excessively high rate. When paired with batch size 64, it ensures stable gradient estimation while cutting training time, achieving a good trade-off between model performance and efficiency.

4.9. Ablation Experiments

To elucidate the contribution of each module, strict single-variable ablation experiments were conducted across the X-IDS-20, ToN_IoT, and CICDarknet2020 datasets, The baseline TinyFlowNet was compared against its ablated variants across classification metrics and computational overhead, specifically FLOPs and inference latency.
The ablation experiments strictly adhered to the principle of controlling a single variable. All experiments were executed using identical datasets, training environments, and hyperparameter configurations to guarantee the fairness and comparability of the experimental results. The ablation results for the three evaluated datasets are presented in Table 10, Table 11 and Table 12, respectively. The stark contrast in core performance metrics between the baseline model and the various ablated variants clearly reflects the specific impact of each module on the model’s discriminative power across varying traffic distributions.
Table 10. Ablation Study Results of TinyFlowNet on the X-IDS-20 Dataset.
Table 11. Ablation Study Results of TinyFlowNet on the ToN_IoT Dataset.
Table 12. Ablation Study Results of TinyFlowNet on the CICDarknet2020 Dataset.
As observed across the experimental results, the complete TinyFlowNet model consistently achieves the highest classification performance across all three datasets. The successive removal of internal components leads to varying degrees of performance degradation, which provides compelling empirical evidence for the architectural synergy and necessity of the hybrid network.
The complete model consistently achieves peak performance, while removing key modules triggers severe degradation. Omitting the LSTM layer causes massive accuracy drops across all datasets, culminating in a catastrophic precision collapse on the highly obfuscated CICDarknet2020 dataset. Similarly, removing the Transformer effectively reduces the FLOPs to 1.18 M and latency to 0.47 ms on the X-IDS-20 dataset. However, the resulting collapse in detection capabilities renders the network highly vulnerable. Such modest computational savings cannot justify the critical loss in security robustness.
Ablating auxiliary components further demonstrates their indispensability. Removing the Squeeze-and-Excitation block significantly degrades the F1-Score on CICDarknet2020 with negligible reductions in FLOPs and latency, indicating a severe loss in fine-grained discriminative power. Furthermore, removing the positional encoder deprives the model of sequence-order context, causing noticeable metric drops without providing any meaningful computational acceleration.
In summary, the ablation study compellingly validates the necessity of each customized module within TinyFlowNet. While aggressive structural pruning, such as removing the LSTM or Transformer, can further shrink the parameter footprint, the resulting collapse in detection capabilities is entirely unacceptable for real-world security tasks. The complete model achieves the optimal trade-off. Whether maintaining a highly constrained parameter scale for standard edge traffic or adaptively scaling up to handle the more complex input distributions of the darknet dataset, it consistently proves that the designed multi-module fusion retains maximal representational power without breaching the stringent deployment limits of edge devices.

5. Conclusions and Future Work

This paper addresses the inherent contradiction between high-precision classification and stringent resource constraints in deploying intelligent network boundary defense systems on edge IoT devices. To resolve this challenge, we propose TinyFlowNet, an ultra-lightweight hybrid neural network based on extreme operator-level reconstruction. By innovating an end-to-end multi-module cascaded architecture integrating CNN, SE, LSTM, and Transformer components, and applying parameter pruning techniques—such as affine-free operators, customized micro-self-attention, and zero-parameter regularization—TinyFlowNet successfully strips away computational redundancy while fully preserving robust spatio-temporal feature extraction. Extensive cross-dataset experiments demonstrate exceptional classification accuracies of 95.31%, 99.53%, and 97.13% on the custom X-IDS-20, CICDarknet2020, and ToN_IoT datasets, respectively, with parameters strictly compressed to 74,600. Crucially, actual hardware deployment on a Raspberry Pi 4B corroborates its practical viability, exhibiting a minimal dynamic memory footprint of 8.26 MB, an average inference latency of 0.79 ms, and a processing throughput exceeding 1200 FPS. Compared to existing mainstream benchmarks, TinyFlowNet establishes a highly deployable and robust new paradigm for real-time edge network defense.
Despite these significant breakthroughs and the robust zero-day anomaly detection capabilities demonstrated in our evaluations, we acknowledge certain operational boundaries in real-world extreme edge scenarios. Specifically, while our multi-module fusion establishes a strong baseline for intra-domain generalization and heuristic interception of unseen threats, real-world streaming traffic is highly dynamic and presents formidable challenges such as cross-dataset concept drift and sophisticated adversarial perturbations. Currently, achieving true cross-domain transferability (e.g., cross-dataset training/testing protocols) typically requires integrating complex Domain Adaptation (DA) modules or Continual Learning paradigms. However, indiscriminately appending these heavy mechanisms would inevitably trigger a resurgence of the “parameter explosion,” directly contradicting our core objective of extreme operator-level lightweighting (confining parameters strictly below 75k).
Therefore, exploring how to empower ultra-lightweight models with cross-domain transferability without sacrificing their micro-computing footprint remains a critical open challenge. Our future work will proceed along two complementary trajectories. First, at the algorithmic level, we plan to explore zero-parameter domain alignment strategies and few-shot meta-learning frameworks to tackle cross-dataset variance. Concurrently, we will focus on integrating adaptive streaming-data processing mechanisms and adversarial training frameworks to continuously enhance robustness against evasion attacks in hostile environments. Second, at the hardware level, we plan to explore quantization-aware training and dynamic inference paradigms like adaptive early-exit branches. These strategies will further shrink the memory footprint and reduce theoretical FLOPs, pushing the physical boundaries of deployment toward ultra-low-power microcontrollers for continuous IoT monitoring.

Author Contributions

Conceptualization, W.L.; methodology, W.L.; software, W.L. and G.W.; validation, W.L. and X.M.; formal analysis, W.L.; investigation, W.L.; resources, H.S.; data curation, W.L.; writing—original draft preparation, W.L.; writing—review and editing, W.L. and H.S.; visualization, W.L. and G.W.; supervision, H.S.; project administration, Y.D.; funding acquisition, W.L. and H.S. All authors have read and agreed to the published version of the manuscript.

Funding

This research was funded by the Science and Technology Development Project of the Department of Education of Jilin Province (JJKH20250945KJ). Jilin Province Science and Technology Development Plan Project—Youth Growth Science and Technology Plan Project (20220508038RC).

Data Availability Statement

The data supporting the findings of this study consist of both publicly available benchmarks and a custom-curated dataset. The public datasets, namely ToN_IoT and CICDarknet2020, are openly accessible from their respective official repositories managed by UNSW Canberra and the Canadian Institute for Cybersecurity. The custom-built X-IDS-20 dataset generated and analyzed during the current study is not publicly available due to privacy policies but is available from the corresponding author upon reasonable request.

Conflicts of Interest

The authors declare no conflicts of interest.

References

  1. Yalli, J.S.; Hasan, M.H.; Jung, L.T.; Yerima, A.I.; Aliyu, D.A.; Maiwada, U.D.; Al-Selwi, S.M.; Shaikh, M.U.R. A Systematic Review for Evaluating IoT Security: A Focus on Authentication, Protocols and Enabling Technologies. IEEE Internet Things J. 2025, 12, 18908–18928. [Google Scholar] [CrossRef] [Scilit]
  2. U, V.M.; Kumaravelu, V.B.; C, V.K.; A, R.; Chinnadurai, S.; Venkatesan, R.; Hai, H.; Selvaprabhu, P. AI-Powered IoT: A Survey on Integrating Artificial Intelligence With IoT for Enhanced Security, Efficiency, and Smart Applications. IEEE Access 2025, 13, 50296–50339. [Google Scholar]
  3. Cui, J.; Sun, H.; Zhong, H.; Zhang, J.; Wei, L.; Bolodurina, I.; He, D. Collaborative Intrusion Detection System for SDVN: A Fairness Federated Deep Learning Approach. IEEE Trans. Parallel Distrib. Syst. 2023, 34, 2512–2528. [Google Scholar] [CrossRef] [Scilit]
  4. Alashjaee, A.M. Deep learning for network security: An Attention-CNN-LSTM model for accurate intrusion detection. Sci. Rep. 2025, 15, 21856. [Google Scholar] [CrossRef] [Scilit] [PubMed]
  5. Kaur, A. Intrusion Detection Approach for Industrial Internet of Things Traffic Using Deep Recurrent Reinforcement Learning Assisted Federated Learning. IEEE Trans. Artif. Intell. 2025, 6, 37–50. [Google Scholar] [CrossRef] [Scilit]
  6. Zhang, H.; Yu, L.; Xiao, X.; Li, Q.; Mercaldo, F.; Luo, X.; Liu, Q. TFE-GNN: A Temporal Fusion Encoder Using Graph Neural Networks for Fine-grained Encrypted Traffic Classification. In Proceedings of the ACM Web Conference 2023 (WWW ‘23); Association for Computing Machinery: New York, NY, USA, 2023; pp. 2066–2075. [Google Scholar]
  7. Sanh, V.; Debut, L.; Chaumond, J.; Wolf, T. DistilBERT, a distilled version of BERT: Smaller, faster, cheaper and lighter. arXiv 2019, arXiv:1910.01108. [Google Scholar]
  8. Sandler, M.; Howard, A.; Zhu, M.; Zhmoginov, A.; Chen, L.C. MobileNetV2: Inverted Residuals and Linear Bottlenecks. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), Salt Lake City, UT, USA, 18–23 June 2018; pp. 4510–4520. [Google Scholar]
  9. González-Ramos, J.A.; Abril, E.J.; Fernández, P.; Prieto, J.; Chamoso, P. Adversarial robustness evaluation of hybrid CNN-LSTM-transformer NIDS on evolving threats. J. Inf. Secur. Appl. 2026, 100, 104467. [Google Scholar] [CrossRef] [Scilit]
  10. Aljuhani, A.; Alamri, A.; Kumar, P.; Jolfaei, A. An Intelligent and Explainable SaaS-Based Intrusion Detection System for Resource-Constrained IoMT. IEEE Internet Things J. 2024, 11, 25454–25463. [Google Scholar] [CrossRef] [Scilit]
  11. Cerasuolo, F.; Bovenzi, G.; Marescalco, C.; Cirillo, F.; Ciuonzo, D.; Pescapè, A. Adaptive Intrusion Detection Systems: Class Incremental Learning for IoT Emerging Threats. In Proceedings of the 2023 IEEE International Conference on Big Data (BigData), Sorrento, Italy, 15–18 December 2023; pp. 3547–3555. [Google Scholar]
  12. Nazari, H.; Farooqi, A.H.; Raza, B.; Kamal, S.; Nawaz, W.; Abbass, W. A CUDA-Accelerated Hybrid CNN-DNN Approach for Multi-Class Malware Detection in IoT Networks. IEEE Access 2025, 13, 150054–150067. [Google Scholar] [CrossRef] [Scilit]
  13. Zhu, S.; Xu, X.; Gao, H.; Xiao, F. CMTSNN: A Deep Learning Model for Multiclassification of Abnormal and Encrypted Traffic of Internet of Things. IEEE Internet Things J. 2023, 10, 11773–11791. [Google Scholar] [CrossRef] [Scilit]
  14. Stolfo, S.J.; Fan, W.; Lee, W.; Prodromidis, A.; Chan, P.K. Cost-based modeling for fraud and intrusion detection: Results from the JAM project. In Proceedings of the 2000 DARPA Information Survivability Conference and Exposition (DISCEX), Hilton Head, SC, USA, 25–27 January 2000; IEEE: New York, NY, USA, 2002; Volume 2, pp. 130–144. [Google Scholar]
  15. Tavallaee, M.; Bagheri, E.; Lu, W.; Ghorbani, A. A detailed analysis of the KDD CUP 99 data set. In Proceedings of the 2009 IEEE Symposium on Computational Intelligence for Security and Defense Applications, Ottawa, ON, Canada, 8–10 July 2009; pp. 1–6. [Google Scholar]
  16. Sharafaldin, I.; Lashkari, A.H.; Ghorbani, A.A. Toward generating a new intrusion detection dataset and intrusion traffic characterization. In Proceedings of the 4th International Conference on Information Systems Security and Privacy (ICISSP), Funchal, Portugal, 22–24 January 2018; pp. 108–116. [Google Scholar]
  17. Hadi, H.J.; Hayat, U.; Musthaq, N.; Hussain, F.B.; Cao, Y. Developing Realistic Distributed Denial of Service (DDoS) Dataset for Machine Learning-based Intrusion Detection System. In Proceedings of the 2022 9th International Conference on Internet of Things: Systems, Management and Security (IOTSMS), Milan, Italy, 29 November–1 December 2022; pp. 1–6. [Google Scholar]
  18. Moustafa, N.; Slay, J. UNSW-NB15: A comprehensive data set for network intrusion detection systems (UNSW-NB15 network data set). In Proceedings of the 2015 Military Communications and Information Systems Conference (MilCIS), Canberra, Australia, 10–12 November 2015; pp. 1–6. [Google Scholar]
  19. Ferrag, M.A.; Friha, O.; Hamouda, D.; Maglaras, L.; Janicke, H. Edge-IIoTset: A New Comprehensive Realistic Cyber Security Dataset of IoT and IIoT Applications for Centralized and Federated Learning. IEEE Access 2022, 10, 40281–40306. [Google Scholar] [CrossRef] [Scilit]
  20. Yang, L.; Moubayed, A.; Shami, A. MTH-IDS: A Multitiered Hybrid Intrusion Detection System for Internet of Vehicles. IEEE Internet Things J. 2022, 9, 616–632. [Google Scholar] [CrossRef] [Scilit]
  21. Hemavathy, J.; Dhanalakshmi, A. A Comprehensive Review of IOT-Based Security Models for Intrusion Detection Methods Using Deep Learning. In Proceedings of the 2025 1st International Conference on Smart and Intelligent Systems (SISCON), Thiruvananthapuram, India, 19–20 December 2025; pp. 1–6. [Google Scholar]
  22. Garcia, S.; Grill, M.; Stiborek, J.; Zunino, A. An empirical comparison of botnet detection methods. Comput. Secur. 2014, 45, 100–123. [Google Scholar] [CrossRef] [Scilit]
  23. Shiravani, A.; Sadreddini, M.H.; Nahook, H.N. Network intrusion detection using data dimensions reduction techniques. J. Big Data 2023, 10, 27. [Google Scholar] [CrossRef] [Scilit]
  24. Al-Omar, B.; Trabelsi, Z. Intrusion Detection Using Attention-Based CNN-LSTM Model. In Proceedings of the Artificial Intelligence Applications and Innovations (AIAI 2023), León, Spain, 14–17 June 2023; Maglogiannis, I., Iliadis, L., MacIntyre, J., Dominguez, M., Eds.; IFIP Advances in Information and Communication Technology; Springer: Cham, Switzerland, 2023; Volume 675. [Google Scholar]
  25. Howard, A.G.; Zhu, M.; Chen, B.; Kalenichenko, D.; Wang, W.; Weyand, T.; Andreetto, M.; Adam, H. MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications. arXiv 2017, arXiv:1704.04861. [Google Scholar]
  26. Hooker, S.; Courville, A.; Clark, G.; Dauphin, Y.; Frome, A. What Do Compressed Deep Neural Networks Forget? arXiv 2021, arXiv:1911.05248. [Google Scholar]
  27. Wei, X.; Wei, H.; Lu, M.; Zhang, Z.; Chang, S.; Zeng, S.; Wang, F.; Chen, M. Large-Scale Parallel Embedded Computing with Improved-MPI in Off-Chip Distributed Clusters. IEEE Trans. Ind. Inform. 2024, 20, 12575–12585. [Google Scholar] [CrossRef] [Scilit]
  28. Asadi, N.; Goudarzi, M. Variant Parallelism: Lightweight Deep Convolutional Models for Distributed Inference on IoT Devices. IEEE Internet Things J. 2024, 11, 345–352. [Google Scholar] [CrossRef] [Scilit]
  29. Kumar, D.; Pawar, P.P.; Addula, S.R.; Meesala, M.K.; Oni, O.; Cheema, Q.N.; Haq, A.U.; Sajja, G.S. AI-Powered Security for IoT Ecosystems: A Hybrid Deep Learning Approach to Anomaly Detection. J. Cybersecur. Priv. 2025, 5, 90. [Google Scholar] [CrossRef] [Scilit]
  30. Aljohani, A.; AlMuhaini, M.; Poor, H.V.; Binqadhi, H.M. A Deep Learning-Based Cyber Intrusion Detection and Mitigation System for Smart Grids. IEEE Trans. Artif. Intell. 2024, 5, 3902–3914. [Google Scholar] [CrossRef] [Scilit]
  31. Nemiwal, G.; Rani, D.; Kumar, R. Transformer-based Network Intrusion Detection: A Multi-dataset Analysis. In Proceedings of the 2025 3rd International Conference on Inventive Computing and Informatics (ICICI), Bangalore, India, 4–6 June 2025; pp. 966–972. [Google Scholar]
  32. Rguibi, A.; Younes, A.; Ahmed, A.; Lahcen, O. Hybrid Edge-Based Intrusion Detection for IoT Using Adaptive Lightweight SVM with Dynamic Feature Pruning. In Proceedings of the 2025 International Conference on Circuit, Systems and Communication (ICCSC), Fez, Morocco, 19–20 June 2025; pp. 1–6. [Google Scholar]
  33. He, M.; Huang, Y.; Wang, X.; Wei, P.; Wang, X. A Lightweight and Efficient IoT Intrusion Detection Method Based on Feature Grouping. IEEE Internet Things J. 2024, 11, 2935–2949. [Google Scholar] [CrossRef] [Scilit]
  34. Akuthota, U.C.; Bhargava, L. Transformer-Based Intrusion Detection for IoT Networks. IEEE Internet Things J. 2025, 12, 6062–6067. [Google Scholar] [CrossRef] [Scilit]
  35. Umair, M.; Khan, M.S.; Al Malwi, W.; Asiri, F.; Nafea, I.; Saeed, F.; Ahmad, J. Knowledge Distillation for Lightweight and Explainable Intrusion Detection in Resource-Constrained Consumer Devices. IEEE Trans. Consum. Electron. 2025, 71, 12157–12165. [Google Scholar] [CrossRef] [Scilit]
  36. Wang, Z.; Zhou, R.; Yang, S.; He, D.; Chan, S. A Novel Lightweight IoT Intrusion Detection Model Based on Self-Knowledge Distillation. IEEE Internet Things J. 2025, 12, 16912–16930. [Google Scholar] [CrossRef] [Scilit]
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Article Metrics

Citations

Article Access Statistics

Multiple requests from the same IP address are counted as one view.