A small sample abnormal traffic classification method based on alignment prototype network
By using an alignment prototype network-based approach, which leverages the internal and external alignment of category prototypes, the supervision collapse and efficiency issues in small-sample abnormal traffic detection are resolved, achieving efficient and accurate abnormal traffic classification in sparse environments.
Patent Information
- Application Number
- CN202311730942.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-15
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2043-12-15
Smart Images

Figure CN117729015B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of network security technology, and in particular to a small-sample abnormal traffic classification method based on Aligned Prototype Network (APN). Background Technology
[0002] In today's rapidly evolving cyberattack landscape, the number of labeled samples of new types of abnormal traffic that can be collected is extremely limited. When training samples are insufficient, the performance of existing data-supported detection models will be significantly reduced.
[0003] To address this, few-shot expectation is a more suitable identification and detection method. This method utilizes a small amount of labeled data to learn anomaly pattern features, reducing training costs while improving the detection capability of novel anomalous traffic, effectively addressing the challenge of sparse data. However, current few-shot expectation methods still face two problems in network traffic environments: supervised failure and limited operational efficiency.
[0004] Supervisory breakdown: While network traffic exhibits significant similarities in transmission environment, message format, and packet context, these differences also reveal characteristics of varying attack patterns. Therefore, contextual information becomes crucial. With a small sample size, significant biases in contextual information can exacerbate supervisory breakdown.
[0005] Operational efficiency: The model needs to strike a balance between feature extraction and operational efficiency. Deep learning module stacking and Siamese network comparisons will lead to an increase in model parameters, complexity, and running time, which cannot meet the fast requirements of current detection systems. Summary of the Invention
[0006] To address the aforementioned technical problems in the existing technology, this invention provides a small-sample abnormal traffic classification method based on an aligned prototype network.
[0007] This method includes: using historical samples with actual labels as the support set. and query set ,
[0008] ;
[0009] ;
[0010] In the formula, C represents the category. The set, for The samples in for Corresponding categories K is Quantity; for The samples in for Corresponding categories , for The quantity; among which, the categories have been pre-classified into normal traffic categories and abnormal traffic categories;
[0011] Through the APN backbone network Will and Convert to a one-dimensional representation and average all The feature vectors yield the category prototype for each category. ,
[0012] ;
[0013] By distance function calculate and prototypes of various categories The distance between them is then calculated using SoftMax. Probability of belonging to each category ,
[0014] ;
[0015] In the formula, for Any category in, for The category prototype;
[0016] right The migration weight is ,
[0017] ;
[0018] Correcting category prototypes through transfer weights Obtain the internally aligned category prototype. ,
[0019] ;
[0020] In the formula, To correct the threshold, ;
[0021] Calculate the sample and category prototypes in the query set Cosine similarity measure between ,
[0022] ;
[0023] Calculate category prototype Weights required to migrate to query set space ,
[0024] ;
[0025] Adjusting the category prototype based on the transfer vector from the category prototype space to the query set space Obtain the externally aligned category prototype ,
[0026] ;
[0027] In the formula, This indicates element-wise multiplication;
[0028] network traffic Traffic extraction, sampling, and image characterization are performed to form a set X of samples to be detected;
[0029] By distance function Calculate the samples in set X and prototypes of various categories The distance between them is then used to calculate the sample using SoftMax. The probability of belonging to each category is used to select the category with the highest probability as the sample. The system categorizes traffic and classifies abnormal traffic based on these categories.
[0030] Furthermore, the method also includes: using a distance function calculate The distance between the prototype and each category is then calculated using SoftMax. Probability of belonging to each category Obtain the corresponding predicted classification ,
[0031] ;
[0032] ;
[0033] In the formula, for Any category in, for Category prototype, for The actual label, for belong The probability of the corresponding category;
[0034] Through entropy loss function renew The tag,
[0035] ;
[0036] In the formula, for A set;
[0037] Calculated using SoftMax The probability of belonging to each category, obtain The predicted classification is compared with the actual label, and the loss for internal alignment is calculated using cross-entropy.
[0038] ;
[0039] In the formula, for A set;
[0040] Calculated using SoftMax The probability of belonging to each category, obtain The predicted classification is compared with the actual label, and the loss for external alignment is calculated using cross-entropy.
[0041] ;
[0042] Calculate the total loss of APN ,
[0043] ;
[0044] In the formula, and For the pre-set weight parameters, above
[0045] Update the category prototype using the total loss of APN. .
[0046] Furthermore, comparison With the updated category prototype ,
[0047] .
[0048] Preferably, the above sampling specifically involves: retaining the first five tuples of network traffic. Each packet is a separate packet, and the first few packets are intercepted. A byte; a 5-tuple network traffic consists of the source IP, destination IP, source port, destination port, and protocol within a preset time period.
[0049] Preferably, the image representation includes truncating or masking the IP address and port of each byte sequence of network traffic, and converting each byte into a grayscale value in hexadecimal format; specifically:
[0050] Rearrange ,generate Pixel matrix;
[0051] when At that time, each pixel in the pixel matrix corresponds to a one-byte value;
[0052] When the number of bytes reaches the width of the pixel matrix, a skip row arrangement is performed, and empty pixels are filled with 0.
[0053] This method is based on a prototype network framework, which can extract prototype representations of categories and achieve high-performance classification with a very small number of samples. The introduction of internal and external alignment can avoid supervision collapse and generate more dynamic and accurate category prototypes. It can adjust the feature extraction and category prototype characterization of novel abnormal traffic, and work together with the prototype network framework to achieve effective and efficient sparse abnormal traffic classification. Attached Figure Description
[0054] Figure 1 This is a schematic diagram of the overall process of the small sample abnormal traffic classification network (APN) based on the aligned prototype network in this invention.
[0055] Figure 2 This is a schematic diagram illustrating the internal and external alignment mechanisms in this invention.
[0056] Figure 3 This is a schematic diagram of the network structure of the small sample abnormal traffic classification network (APN) based on the aligned prototype network in this invention.
[0057] Figure 4 This is a schematic diagram illustrating the effect verification of the visual distribution of class prototypes and test samples in this invention.
[0058] Figure 5 This is a bar chart showing the average distance comparison between the sample and the prototype in this invention.
[0059] Figure 6 This is a bar chart showing the comparison of prototype distances between categories in this invention. Detailed Implementation
[0060] With the rapid development and widespread adoption of network technology, the number of attacks on global networks is constantly increasing. In 2022, the number of high-level cyberattacks worldwide increased by 38% year-on-year. With the rapid advancement of artificial intelligence technologies such as ChatGPT, hackers can generate new and more complex attack methods and carry out attacks more quickly and automatically. Massive cyberattacks lead to the emergence of new abnormal network traffic, further exacerbating the already challenging cybersecurity situation. Therefore, identifying abnormal network traffic in sparse environments is an important research and application direction, and it has significant value for cybersecurity defense and construction.
[0061] The development of network anomaly traffic detection and classification has gone through several stages, including statistical feature analysis, rule analysis, machine learning, and deep learning. Statistical methods utilize the distribution patterns of network traffic, calculating the parameters of the probability density function for each known type of network traffic, and then testing whether new samples belong to a certain distribution, including univariate, multivariate, and time-series models. Rule analysis defines rules to characterize abnormal or normal traffic by creating a knowledge base, including finite state machines, description languages, expert systems, and fingerprint recognition. However, these methods often require extensive expert experience and have poor robustness, failing to adapt to the rapid evolution of network attacks. Machine learning and deep learning methods have been widely used to improve the automation and intelligence of anomaly traffic detection. However, their performance depends on a large number of training samples, resulting in high training and analysis costs.
[0062] However, small-sample expectation detection classification methods suffer from supervised failure and limited operational efficiency, resulting in limited efficiency in sparse anomaly traffic classification.
[0063] To address the above technical problems, this invention provides a small-sample abnormal traffic classification method based on aligned prototype networks, such as... Figure 1 As shown, it specifically includes:
[0064] Historical samples with actual labels are used as the support set. and query set ,
[0065] ;
[0066] ;
[0067] In the formula, C represents the category. The set, for The samples in for Corresponding categories K is Quantity; for The samples in for Corresponding categories , for The number of traffic flows; among which, the categories have been pre-classified into normal traffic categories and abnormal traffic categories.
[0068] In this study, historical samples with actual labels were used as the support set. and query set Specifically, this involves sampling from all sample sets to form a task set, Episode, which is set as an N-Way K-Shot Q-Query classification task, where N represents the number of classes in the classification task, K represents the number of support set samples included in each class, and Q represents the number of query set samples included in each class. Within the few-shot framework, the training and testing datasets for each classification task are defined as the support set and query set, respectively. For each training iteration, the APN randomly assembles the task and then lets the model perform the classification task, using the loss to guide model updates. For new classes with fewer labels, the APN similarly constructs a classification task and provides a limited set of samples as the support set.
[0069] Through backbone network Will and Converting to a one-dimensional representation yields its D-dimensional representation. , where R is the set of real numbers.
[0070] Average All The feature vectors yield the category prototype for each category. ,
[0071] .
[0072] By distance function calculate and prototypes of various categories The distance between them is then calculated using SoftMax. Probability of belonging to each category ,
[0073] ;
[0074] In the formula, for Any category in, for The category prototype.
[0075] right The migration weight is ,
[0076] .
[0077] Correction by migration weights Obtain the internally aligned category prototype. ,
[0078] ;
[0079] In the formula, To correct the threshold, Among them, the internal alignment mechanism is as follows: Figure 2 As shown in (a).
[0080] Calculate the sample and category prototypes in the query set Cosine similarity measure between ,
[0081] .
[0082] Calculate category prototype Weights required to migrate to query set space ,
[0083] .
[0084] Adjusting the category prototype based on the transfer vector from the category prototype space to the query set space Obtain the externally aligned category prototype That is, comparing category prototypes Cosine similarity between the sample and the query set.
[0085] ;
[0086] In the formula, This indicates element-wise multiplication. The external alignment mechanism is as follows: Figure 2 As shown in (b).
[0087] network traffic Traffic extraction, sampling, and image characterization are performed to form a set X of samples to be detected;
[0088] By distance function Calculate the samples in set X and prototypes of various categories The distance between them is then used to calculate the sample using SoftMax. The probability of belonging to each category is used to select the category with the highest probability as the sample. The system categorizes traffic and classifies abnormal traffic based on these categories.
[0089] In the long-term, repeated abnormal traffic classification process, it is also necessary to update the class prototypes of samples in the query set based on the total loss of the APN network. APN uses a two-layer Conv2D network as the backbone to perform the embedding representation of the input samples and obtains the class prototype by averaging the representations of the supporting samples in the embedding space. The class prototype is updated through internal and external alignment to obtain the corrected class prototype. Its internal alignment module corrects the bias of the prototype in the sample distribution space using the prediction loss of the support set, while the external alignment module embeds the prototype into the distribution space of the query set by comparing the similarity between the prototype and the samples in the query set, generating dynamically corrected class prototypes. Specifically, the abnormal traffic classification process, including class prototype updating, is as follows: Figure 3 As shown.
[0090] By distance function calculate The distance between the prototype and each category is then calculated using SoftMax. Probability of belonging to each category Obtain the corresponding predicted classification ,
[0091] ;
[0092] ;
[0093] In the formula, for The actual label, for belong The probability of the corresponding category;
[0094] Through entropy loss function renew The tag,
[0095] ;
[0096] In the formula, for A set of.
[0097] in, Cross-entropy is defined as:
[0098] ;
[0099] Calculated using SoftMax The probability of belonging to each category, obtain The predicted classification is compared with the actual label, and the loss for internal alignment is calculated using cross-entropy.
[0100] ;
[0101] In the formula, for A set;
[0102] Calculated using SoftMax The probability of belonging to each category, obtain The predicted classification is compared with the actual label, and the loss of external alignment is calculated using cross-entropy. ,
[0103] ;
[0104] Calculate the total loss of APN ,
[0105] ;
[0106] In the formula, and For the pre-set weight parameters,
[0107] Update the category prototype using the total loss of APN. .
[0108] Furthermore, comparisons can be made. With the updated category prototype ,
[0109] .
[0110] Preferably, during sampling, appropriate median values M and N can be selected based on statistical analysis results and empirical judgment of historical data corresponding to each system sample. Specifically, the first five tuples of network traffic are retained. Each packet is a separate packet, and the first few packets are intercepted. Bytes. And the packets after M and The subsequent content is completely truncated. The five-tuple network traffic includes the source IP, destination IP, source port, destination port, and protocol for a preset time period.
[0111] Preferably, to characterize the raw traffic information for processing by artificial intelligence models, image modality is used to represent the traffic. For each byte sequence of the traffic, header fields such as IP address and port number are preprocessed. Then, the byte sequence is read in hexadecimal, and each byte is converted into a number from 0 to 255, corresponding to a pixel in a grayscale image, with each 8 bits corresponding to a hexadecimal number. This method uses grayscale images to flatten channels, reducing the influence of prior relationships between channels and preserving the spatiotemporal structure of the original input information to the greatest extent. Specific operations include: first, rearranging the raw traffic to generate a pixel matrix of size W and H, satisfying that each pixel corresponds to a byte value, with the byte value being 0 to 255; therefore, the pixel matrix is visually a grayscale image. Linear arrangement is used to organize pixels; when the image width is reached, pixels continue to be arranged in the next row. If all pixels are arranged and there is still remaining image space, the image is filled with 0s.
[0112] In short, it involves truncating or masking the IP address and port of each byte sequence of network traffic, and converting each byte into a grayscale value in hexadecimal format; specifically, it involves rearranging... ,generate The pixel matrix; when At this time, each pixel in the pixel matrix corresponds to a byte value; when the number of bytes reaches the width of the pixel matrix, a row skipping arrangement is performed, and empty pixels are filled with 0.
[0113] To verify the technical effectiveness of the proposed solution, the inventors conducted the following experimental evaluation.
[0114] CIC-IDS2017 and CSE-CIC-IDS2018 were selected as benchmark datasets, and further reconstruction and validation were carried out based on small sample scenarios. IC-IDS2017 and CSE-CIC-IDS2018 are widely used in intrusion detection research and are currently the latest complete datasets. They have diverse network attack types, rich traffic sources, and reflect the characteristics of the real environment. They also provide raw traffic data, which can effectively evaluate the analytical capabilities of the method of this invention for full traffic information.
[0115] Dataset and metric design: Based on the setting of small sample scenarios, and based on two datasets, resampling was performed to maintain consistency with the original distribution. The number of samples in each category was controlled separately to construct small sample abnormal traffic datasets, named CIC-FS-IDS-2017 and CIC-FS-IDS-2018 respectively.
[0116] CIC-FS-IDS-2017 identified 9 types of anomalous traffic, while CIC-FS-IDS-2018 identified 7. The sampled data was divided into two parts: a training support set and a test set. Based on the size of the training and support samples, the datasets were categorized into three types: sufficient, standard, and limited. Sufficient indicates a sample size between 1000 and 2000, while standard indicates a sample size between 10 and 1000. Limited indicates a very small number of samples; under experimental conditions, depending on the K value, the sample size is 1, 5, or 10, and these samples are used only as support set samples during the testing phase; during training, the sample size is set to 0.
[0117] The experimental performance evaluation was conducted on the test set as a multi-class classification problem, and the metrics included accuracy, precision, recall, and F1 score. All metrics were calculated using a macro-means of the multi-class classification results to obtain the final values. Additionally, the experimental evaluation also reported the time used for model detection to demonstrate efficiency. All results were reported as a mean after 20 trials.
[0118] Performance comparison and analysis: This experiment first tested the 5-way 5-shot abnormal traffic classification task on the CIC-FS-IDS2017 dataset, and then tested the 4-way 5-shot classification task on the CSE-FS-IDS2018 dataset. The classification performance evaluation is shown in Table 1.
[0119] Table 1 Performance of Abnormal Traffic Classification
[0120]
[0121] The following findings were made from the classification and evaluation results:
[0122] (1) The Siamese network performs slightly better than the prototype network in classification, but is much slower. The results show that the Siamese network's classification performance is 1% higher than the prototype network, but its runtime is 10 times longer. The Siamese network compares test samples with all supporting samples, providing more information and richer comparison details, but the one-to-one comparison method leads to longer runtime and higher cost. Therefore, the Siamese network is difficult to meet the requirements of a real-time and effective anomaly classification system. Meanwhile, the prototype network only compares test samples with class prototypes, greatly reducing the runtime of feature extraction and similarity comparison.
[0123] (2) APN achieved the best classification results across tasks and all metrics. Under the 5-way 5-shot setting of CIC-FS-IDS2017, accuracy, recall, precision, and F1 scores were all improved, with improvements ranging from 3% to 5%. The model achieved a final accuracy and recall of 98%, maintaining high detection accuracy while reducing false positives.
[0124] In the 4-way 5-shot setup of CSE-FS-IDS2018, APN also outperformed existing methods in terms of accuracy, recall, precision, and F1, with accuracy improving across the board by approximately 0.5% to 3.5%, achieving the best results.
[0125] FC Net and Siamese Capsule Network enhance the backbone network for feature extraction and reconstruct similarity metrics, but they do not consider the deep utilization of supervised information and constantly changing environments, thus their adaptability and generalization performance for small sample data scenarios remain limited. Meanwhile, APN will support feature alignment between the support set and the query set to leverage supervised knowledge, reduce feature bias, and ultimately improve representation and comparison capabilities.
[0126] (3) APN inherits the advantage of the prototype network's fast running speed, outperforming other methods. In these two tasks, APN reduces the running time by approximately 1 / 10 and 1 / 15 respectively, and can complete the abnormal traffic classification task within a time range of 1-2 seconds, meeting the requirements of a real-time and efficient classification system. It is evident that the prototype network's comparison method reduces the number of comparisons, significantly improving operational efficiency.
[0127] The backbone used in this experiment is as simple as a 2-layer Conv2D, which reduces the cost of feature extraction compared to the backbones of FC Net and Siamese Capsule Net. Furthermore, since the IA and EA modules proposed by APN are inherently computationally low and fast, they do not impose additional runtime overhead.
[0128] The experimental evaluation of this invention further compares and discusses the effectiveness of the proposed internal alignment and external alignment modules, and explores the sensitivity of APN in more small sample scenarios.
[0129] As shown in Table 1, compared to the original prototype network with classification accuracies of 93.39% and 92.58% on the CIC-FS-IDS2017 and CSE-IC-IDS2018 datasets, respectively, APN improves accuracy by 3%-5%. It is noteworthy that among all methods listed in the table, the original prototype network has the lowest accuracy but the shortest processing time. The method proposed in this invention adds only a small amount of time in a balanced manner, resulting in better classification performance.
[0130] Comparing the results of "APN(IA)" and "APN", it can be found that the external alignment module provides more improvement than the internal alignment module. On the CIC-FS-IDS-2017 dataset, the APN using EA achieves an accuracy of 97.35%, a significant improvement of 3.96% compared to the original prototype network's 93.39% accuracy. Recall, accuracy, and F1 score also show significant improvements of 3.96%, 3.46%, and 4.85%, respectively. On the other hand, IA brings improvements of 3.19%, 3.19%, 3.22%, and 2.27%.
[0131] Meanwhile, the APN with both IA and EA achieved the best performance, improving accuracy, recall, precision, and F1 score by 4.68%, 4.68%, 3.46%, and 4.85%, respectively, with a 0.15s increase in runtime. Results on the CSE-IC-IDS2018 dataset yielded the same conclusion. The APN with EA improved accuracy by 2.51% and IA by 2.24%. With the APN using both modules, a 0.04s increase in runtime resulted in significant improvements in accuracy, recall, precision, and F1 score, increasing by 3.20%, 3.20%, 2.92%, and 3.37%, respectively.
[0132] Both results demonstrate the effectiveness of the two modules. The external alignment module considers the characteristics of samples in a dynamic environment, resulting in more significant benefits. The internal alignment module only improves the utilization of supporting samples, while some samples are already included in the construction of the class prototype. Therefore, its information gain is relatively small.
[0133] Figure 4 This impact will be verified from a qualitative visualization perspective. Figure 4 The feature map is represented by T-SNE in a dimensionality reduction manner and drawn in a two-dimensional space to analyze the distribution relationship between class prototypes and test samples under the CIC-FS-IDS-2017 5-Way 5-shot setting.
[0134] pass Figure 4 The comparison reveals that after introducing internal and external alignment modules, the internal distance between classes increases, and the distance between class clusters also increases. This provides a clearer decision boundary, making the boundary's characteristics more inclusive of the class's internal structure and reducing interference from noise points. The distinction between different class clusters becomes even more pronounced. Furthermore, the corrected prototype's distance is closer to the core sample instance because, after aligning with the query sample, it is less affected by outliers.
[0135] Effect verification and data analysis: Figure 5 and Figure 6The above conclusion was also verified by comparing the distances. Figure 5 and Figure 6 It is a distance calculated in the original feature space. Figure 5 This represents the average distance between test samples within a category and the class prototype. Figure 6 This represents the distance between class prototypes.
[0136] from Figure 5 As can be seen, the distance within each category has increased significantly, but the increase varies to different degrees. This may be due to the different granularities of the categories. Some categories have coarser granularity and cover a wider range of attack characteristics; or in the current network environment, the relevant sample features of this category vary greatly, which further expands the radiation boundary of the final generated class prototype.
[0137] In contrast, the distances within categories in the original prototype network are more consistent and fluctuate less, indicating that the radiation range of the statically generated class prototypes is relatively fixed. Therefore, it loses its adaptive ability in dynamically changing network environments. Figure 6 As can be seen, the distance between classes has also increased to varying degrees, and the boundaries between classes have been widened. Among them, the distance between classes related to class4 has increased significantly, indicating that this class is significantly different from other classes, thus forming a more distant decision boundary.
[0138] Performance robustness verification: As shown in Table 2, this experiment further explores the model's performance under different conditions to verify the model's robustness in different scenarios, mainly including more classes and fewer support samples.
[0139] Table 2. Experimental results of clustering accuracy and efficiency in real-world environments.
[0140]
[0141] For the CIC-FS-IDS-2017 dataset, the model was trained with N=5, and then tested with N=5 and N=9 respectively. The performance of the proposed method and the original prototype network was compared. Table 2 shows that the performance of both methods decreased from N=5 to N=9, but the original prototype network experienced an accuracy decrease of approximately 5%, while the proposed method only experienced a 1.5% decrease in accuracy. For the CSE-CIC-IDS2018 dataset, the model was trained with N=4, and then tested with N=4 and N=7 respectively. The performance of the proposed method and the original prototype network was compared. Table 2 shows that the performance of both methods decreased from N=4 to N=7, but the original prototype network experienced an accuracy decrease of approximately 6%, while the proposed method only experienced a 1.31% decrease in accuracy.
[0142] Experimental results show that the method proposed in this invention suffers less performance loss when introducing new categories, indicating that the method of this invention has more stable and robust performance when dealing with a dynamic increase in the number of categories, and can meet the needs of real systems.
[0143] Another scenario involves a reduction in the number of support samples. As the number of small sample categories increases, the number of samples for some particularly novel categories may be extremely small, leading to one-shot errors. Therefore, we fix the number of support samples during training and choose not to reduce or reduce the number of support samples during the testing phase to verify the model's generalization ability when the number of support samples is reduced. For the CIC-FS-IDS-2017 dataset, we trained the model with K=5, and then tested with K=5 and K=1 respectively, comparing the performance of the proposed method and the original prototype network. Table 2 shows that both methods exhibit significant performance degradation, but the original prototype network experienced a nearly 20% drop in accuracy, while the proposed method only experienced a 15% drop, slightly better than the original prototype network. For the CSE-CIC-IDS2018 dataset, we again trained the model with K=5, and then tested with K=5 and K=1 respectively. The original prototype network experienced an approximately 16% drop in accuracy, while the proposed method only experienced a 12% drop in accuracy. Experiments have shown that the method proposed in this invention results in less performance loss when the number of supporting samples is reduced.
[0144] Experiments in two scenarios verified that the method proposed in this invention has a small performance loss when introducing new classes or fewer supporting samples, indicating that the method has more stable and robust performance when facing dynamic changes in abnormal traffic increments or limited labeling capabilities to meet the needs of actual systems.
[0145] As can be seen, this method, based on the prototype network framework, can extract prototype representations of categories and achieve high-performance classification with a very small number of samples. The introduction of internal and external alignment can avoid supervision collapse, generate more dynamic and accurate category prototypes, and adjust the feature extraction and category prototype characterization of novel abnormal traffic. Together with the prototype network framework, it can achieve effective and efficient sparse abnormal traffic classification.
[0146] In addition to achieving the aforementioned beneficial effects, each preferred scheme also achieves the following beneficial effects: updating the category prototype of the query set samples based on the loss of the APN network can improve accuracy, recall, precision, and F1 score; comparing the samples in the query set with the updated category prototype can verify the accuracy of the updated category prototype; sampling and image representation of network traffic can make subsequent data processing more efficient and accurate.
[0147] The above are merely preferred embodiments of the present invention and are not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the invention.
Claims
1. A method for classifying small-sample abnormal traffic based on aligned prototype networks, characterized in that, include: Historical samples with actual labels are used as the support set. and query set , ; ; In the formula, C represents the category. The set, for The samples in for Corresponding categories K is Quantity; for The samples in for Corresponding categories , for The quantity; among which, the categories have been pre-classified into normal traffic categories and abnormal traffic categories; Through the APN backbone network Will and Convert to a one-dimensional representation and average all The feature vectors yield the category prototype for each category. , ; By distance function calculate and prototypes of various categories The distance between them is then calculated using SoftMax. Probability of belonging to each category , ; In the formula, for Any category in, for The category prototype; right The migration weight is , ; Correcting category prototypes through transfer weights Obtain the internally aligned category prototype. , ; In the formula, To correct the threshold, ; Calculate the sample and category prototypes in the query set Cosine similarity measure between , ; Calculate category prototype Weights required to migrate to query set space , ; Adjusting the category prototype based on the transfer vector from the category prototype space to the query set space Obtain the externally aligned category prototype , ; In the formula, This indicates element-wise multiplication; network traffic Traffic extraction, sampling, and image characterization are performed to form a set X of samples to be detected; By distance function Calculate the samples in set X and prototypes of various categories The distance between them is then used to calculate the sample using SoftMax. The probability of belonging to each category is used to select the category with the highest probability as the sample. The system categorizes traffic and classifies abnormal traffic based on these categories.
2. The method for classifying small-sample abnormal traffic based on aligned prototype networks as described in claim 1, characterized in that, It also includes category prototypes for samples in the update query set: By distance function calculate The distance between the prototype and each category is then calculated using SoftMax. Probability of belonging to each category Obtain the corresponding predicted classification , ; ; In the formula, for The actual label, for belong The probability of the corresponding category; Entropy loss function renew Tags; ; In the formula, for A set; Calculated using SoftMax The probability of belonging to each category, obtain The predicted classification is compared with the actual label, and the loss for internal alignment is calculated using cross-entropy. ; In the formula, for A set; Calculated using SoftMax The probability of belonging to each category, obtain The predicted classification is compared with the actual label, and the loss for external alignment is calculated using cross-entropy. ; Calculate the total loss of APN. ; In the formula, and For the pre-set weight parameters, Update the category prototype using the total loss of APN. .
3. The method for classifying small-sample abnormal traffic based on aligned prototype networks as described in claim 2, characterized in that, Also includes: Compare With the updated category prototype , 。 4. The method for classifying small-sample abnormal traffic based on aligned prototype networks as described in claim 1, characterized in that, The sampling includes: Preserving the network traffic of the five-tuple Each packet is a separate packet, and the first few packets are intercepted. byte; The five-tuple network traffic includes the source IP, destination IP, source port, destination port, and protocol within a preset time period.
5. The method for classifying small-sample abnormal traffic based on aligned prototype networks as described in claim 1, characterized in that, The image representation includes truncating or masking the IP address and port of each byte sequence of network traffic, and converting each byte into a grayscale value in hexadecimal format; specifically: Rearrange ,generate Pixel matrix; when At that time, each pixel in the pixel matrix corresponds to a one-byte value; When the number of bytes reaches the width of the pixel matrix, a skip row arrangement is performed, and empty pixels are filled with 0.
