A personalized federated learning scrap steel detection method based on layer-by-layer direction guidance
By employing a personalized federated learning method with layer-by-layer directional guidance, and utilizing cosine similarity to calculate model similarity and perform layer-by-layer updates, the problem of data heterogeneity among scrap steel recycling sites is solved, thereby improving the accuracy and adaptability of the scrap steel detection model.
Patent Information
- Application Number
- CN202411517995.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2025-12-26
- Estimated Expiration
- 2044-10-29
AI Technical Summary
Existing federated learning methods cannot effectively address the data heterogeneity problem among scrap steel recycling sites, resulting in differences in the performance of the global model across different scrap steel recycling sites, which fails to meet the needs of scrap steel detection.
A layer-by-layer directional guidance personalized federated learning method is adopted. High-resolution industrial cameras are used to collect images of scrap steel for data preprocessing and local training. Cosine similarity is used to calculate model similarity, and the model is aggregated by combining the layer-by-layer directional guidance mechanism to update the personalized model layer by layer.
The detection accuracy and generalization ability of the scrap steel detection model at various scrap steel recycling sites have been improved, the performance degradation caused by data heterogeneity has been solved, and the model's efficient learning and adaptability at various sites have been ensured.
Smart Images

Figure CN119380101B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of metallurgy, in particular to a personalized federated learning scrap steel detection method based on layer-by-layer direction guidance. BACKGROUND
[0002] Scrap steel, as a renewable iron resource that can replace iron ore for steelmaking, plays an extremely important role and position in steel smelting. Scrap steel detection refers to the process of classifying and quality detecting scrap steel materials, which is divided into manual detection and automatic detection. Traditional manual detection relies on manual visual inspection and caliper measurement. Compared with automatic detection, traditional manual detection has been unable to meet the growing demand for scrap steel detection.
[0003] The existing federated learning is a distributed machine learning paradigm that allows clients to collaboratively train a global model with good generalization and high precision without exchanging raw data. Its approach can solve the problem of data silos. Moreover, due to the characteristic of federated learning that allows clients to upload model parameters rather than raw data, it can reduce data transmission costs and protect data privacy and security during scrap steel detection. However, traditional federated learning cannot solve the data heterogeneity problem caused by the difference in type and quantity of scrap steel data between different scrap steel recycling sites, as the global model will be biased towards a certain client during training, resulting in a decrease in the precision of the global model's overall performance.
[0004] The existing technology uses hierarchical fine-grained fusion federated learning technology to measure the similarity of each client model and the global model, calculates the weight of each client model, and aggregates and updates the global model. However, it cannot solve the data heterogeneity problem in the actual application scenario of scrap steel detection. On the one hand, there are different scrap steel recycling plants in real-world scenarios, and the scrap steel materials collected by each recycling plant are different. For example, industrial scrap steel recycling plants collect scrap steel that is biased towards a single or specific scrap steel material, while social scrap steel recycling plants collect a variety of scrap steel materials compared to industrial scrap steel recycling plants. On the other hand, there are differences in the quantity of scrap steel collected by different scrap steel recycling sites, which causes the global model to be biased towards scrap steel recycling sites with a large quantity of scrap steel during training, resulting in differences in the performance of the global model between different scrap steel recycling sites.
[0005] Therefore, the present application provides a personalized federated learning scrap steel detection method based on layer-by-layer direction guidance to solve the problems raised in the background art. SUMMARY
[0006] In view of the deficiencies of the prior art, the present application provides a personalized federated learning scrap steel detection method based on layer-by-layer direction guidance to solve the problems raised in the background art.
[0007] To achieve the above object, the application is implemented by the following technical solutions: A personalized federal learning scrap steel detection method based on layer-by-layer direction guidance, comprising the following steps:
[0008] S1, scrap steel picture collection and preprocessing:
[0009] Collect high-definition pictures of different types of scrap steel at different unloading points of each scrap steel recycling station as a training data set through a high-resolution industrial camera;
[0010] Label the collected image data;
[0011] Data preprocessing, including data cleaning, removing noise and duplicate images, and data cropping;
[0012] Divide the scrap steel image data set into a training set and a test set in a ratio of 8:2;
[0013] S2, initialize the model:
[0014] Deploy an initial model with the same parameters and structure at each scrap steel recycling station;
[0015] S3, local training:
[0016] Each client uses the scrap steel picture data set for local training;
[0017] Use random gradient descent combined with cross-entropy loss function for model optimization;
[0018] For random gradient descent, each round of local training uses a small batch of data sets for gradient calculation and updates the model parameters;
[0019] S4, aggregation weight method based on client model difference:
[0020] Each scrap steel recycling station uploads the local model parameters and loss value to the server;
[0021] The server calculates the model similarity of any client at the level by cosine similarity layer by layer;
[0022] Normalize the loss value and combine the model similarity of each client at the level to calculate the aggregation weight coefficient of the level between models;
[0023] S5, personalized model aggregation based on layer-by-layer direction guidance mechanism:
[0024] The personalized aggregation of the i-th client is performed using the layer-by-layer direction guidance mechanism;
[0025] Select the top k client models with larger aggregation weight coefficients through the aggregation weight coefficients obtained in step S4;
[0026] The direction vector of each client model is calculated by using the guidance of each client to the i-th client;
[0027] The server calculates the direction vector of each client model on the model level and broadcasts all the direction vectors to the corresponding clients;
[0028] After receiving the direction vector, each client updates its personalized model layer by layer;
[0029] The above local training, aggregated weight calculation and personalized model aggregation process is repeated until the preset training round is reached.
[0030] S1: The benefits of scrap steel picture collection and preprocessing: Ensure the high quality of input data, reduce noise interference in the model training process, and improve the learning efficiency and accuracy of the model; S2: The benefits of initializing the model: uniform initial conditions, avoid training result deviation caused by initial model differences; S3: The benefits of local training: each client model can better adapt to and learn local scrap steel data, improve local detection accuracy, and the random gradient descent combined with the cross-entropy loss function can ensure the efficiency and stability of the model training process; S4: The benefits of the aggregated weight method based on the differences between client models: accurately measure the similarity of each client model, avoid model bias towards specific client data during training, improve the overall generalization ability of the aggregated model, and enhance the model's performance on different client data; S5: The benefits of personalized model aggregation based on the layer-by-layer direction guidance mechanism: ensure that each client model can effectively absorb useful information from other client models, improve the generalization ability and accuracy of the model, and the layer-by-layer update mechanism ensures that the model is gradually optimized to achieve the preset training effect.
[0031] Preferably, in the S3 step, for the random gradient descent, each round of local training uses a small batch of data sets for gradient calculation and model parameter update, which is defined as:
[0032] wherein, is the model parameter, is the learning rate, represents the loss value of the nth sample.
[0033] Compared with batch gradient descent, random gradient descent only needs to calculate the gradient of a single or small number of samples during iteration, greatly reducing the amount of calculation and improving the training speed. Random gradient descent can quickly approach the minimum value of the loss function and avoid falling into local minimum. Since iteration only processes a single or small number of samples, random gradient descent requires less memory. In addition, due to the heterogeneity of scrap steel recycling site data, random gradient descent can improve the performance of the model on each data set, thereby improving the accuracy and generalization ability of the scrap steel detection model.
[0034] Preferably, in the S3 step, the cross-entropy loss function is defined as:
[0035] where N is the number of samples in the data set, K is the number of labels in the data set, represents the probability that the nth sample actually belongs to the kth label, represents the probability that the model predicts that the nth sample belongs to the kth label.
[0036] The cross-entropy loss function is very sensitive to the difference in probability distribution, can accurately reflect the subtle difference between the model prediction and the actual label, and effectively guide the optimization process of the model. The cross-entropy loss function is widely used in classification problems, especially in multi-class classification tasks, which can effectively handle complex classification tasks. The logarithmic function has good stability in numerical calculation, and through logarithmic operation, the problem of numerical overflow caused by extremely small or large probability can be avoided. At the same time, the cross-entropy loss function is based on probability, providing intuitive probability explanation, making the output of the model more interpretable and reliable, and facilitating understanding and application.
[0037] Preferably, in the S4 step, the parameters of each client model are defined as The server accepts the parameter set of each client model The client model can be divided into s layers, and the i-th client model parameter can be divided into The model similarity of any client at the layer level can be calculated according to the cosine similarity, and the function expression is:
[0038] where represents the similarity of the s-th layer of the i-th client model and the j-th client model.
[0039] The cosine similarity is a dimensionless quantification method, and the result is between -1 and 1, which can effectively measure the directional similarity of vectors. For the data heterogeneity of different scrap steel recycling sites, the cosine similarity can effectively compare the similarity of different client models, ignore the difference in data quantity and feature distribution, and through the calculation of the similarity of each layer, the model parameters with high similarity can be accurately identified, and they are given higher weights in aggregation, thereby improving the accuracy and generalization ability of the global model.
[0040] Preferably, in the S4 step, the loss value of each model is defined as The server receives the loss value set of each client The loss value is normalized, and the function expression is: ;
[0041] Depend on , The two yield the aggregate weights of each model level. , This represents the aggregation weight coefficient of client j on the s-th layer of the model for client i when performing a personalized model aggregation method based on a layer-by-layer directional guidance mechanism.
[0042] Normalization adjusts the loss values of different clients to the same scale, avoiding aggregation bias caused by dataset size or loss value range. Through normalization, the contribution of each client model can be fairly measured, ensuring that unfairness caused by excessively large or small loss values of individual clients is avoided during the aggregation process. At the same time, by combining cosine similarity and normalized loss values, the aggregation weights take into account the similarity of model parameters and the accuracy of each model, so as to comprehensively measure the contribution of each client model.
[0043] Preferably, the aggregation weighting coefficient The increase indicates that client j's contribution to the model of client i has increased, and the aggregate weight coefficients are... The model representing client j has a high degree of similarity to the model representing client i, and the model itself has high accuracy.
[0044] Preferably, in step S5, the direction vector of each client model to client i is calculated by utilizing the guidance effect of each client to client i through a layer-by-layer direction guidance mechanism. The function expression is: ,in, For client i in the first The direction vector of the selected layer participating in the personalized aggregation update of the client is used to guide the client model in the first layer. The direction of layer updates.
[0045] The layer-by-layer directional guidance mechanism enables more refined model updates, allowing for layer-by-layer adjustment of model parameters and improving the model's adaptability to local data. By considering the guidance from other clients, client i can absorb useful information from other client models and perform more precise optimization on local data, thereby improving the performance of the personalized model. At the same time, the directional vector, combined with guidance information from multiple clients, enables the personalized model to optimize for local data and learn from the data features of other clients to improve overall generalization ability.
[0046] Preferably, in step S5, after receiving the direction vector, each client updates its personalized model layer by layer, with the function expression as follows: .
[0047] This invention provides a personalized federated learning method for scrap steel detection based on layer-by-layer directional guidance. It has the following beneficial effects:
[0048] 1、The scheme adopts personalized federated learning based on layer-by-layer direction guidance mechanism, by utilizing the differences between client models, using layer-by-layer direction guidance mechanism to calculate the direction vector of each client at the level, to guide the update direction of each client personalized model, to customize the personalized model for each scrap steel recycling site, so that the personalized model can further learn the local data while ensuring to learn the data of other scrap steel recycling sites, and improve the performance of the model on the client.
[0049] 2、The personalized federated learning method based on layer-by-layer direction guidance makes the personalized model of each scrap steel recycling site learn the knowledge of other models related to itself layer by layer, and maximizes the use of data of other scrap steel recycling sites to further improve the performance of the personalized model, so as to solve the problem of performance degradation caused by data heterogeneity in scrap steel detection actual application scene. BRIEF DESCRIPTION OF DRAWINGS
[0050] Figure 1 The method flowchart of the present application;
[0051] Figure 2 The method framework diagram of the present application. DETAILED DESCRIPTION
[0052] In order to enable those skilled in the art to understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, other embodiments obtained by those skilled in the art without creative labor should be within the scope of protection of the present application.
[0053] The present application will be described in detail below with reference to the drawings:
[0054] Embodiment one:
[0055] Please refer to the drawings Figure 1 , the drawings Figure 2 , the present application provides a kind of personalized federated learning scrap steel detection method based on layer-by-layer direction guidance, comprising the following steps:
[0056] S1, scrap steel picture acquisition and pretreatment:
[0057] Use high-resolution industrial camera to collect scrap steel pictures at different unloading points of different scrap steel recycling stations, form high-definition image dataset;
[0058] Label the collected images, including scrap steel type and quality information;
[0059] Data preprocessing is performed, including data cleaning, denoising, removing duplicate images, and data cropping;
[0060] The scrap steel image dataset is divided into a training set and a test set in a ratio of 8:2;
[0061] S2, initialize the model:
[0062] An initial model with the same structure and parameters is deployed at each scrap steel recycling site;
[0063] S3, local training:
[0064] Each client uses the scrap steel picture dataset for local training;
[0065] The random gradient descent method combined with the cross-entropy loss function is used for model optimization;
[0066] Each round of local training uses a small batch of data sets for gradient calculation, and the model parameters are updated;
[0067] S4, aggregation weight method based on client model difference:
[0068] Each scrap steel recycling site uploads the local model parameters and loss value to the server;
[0069] The server calculates the similarity of each client model layer by layer through the cosine similarity, and calculates the model level aggregation weight;
[0070] Define the client model parameters, calculate the model similarity of the client at the level;
[0071] The loss value is normalized, and the aggregation weight coefficient of the model level is calculated;
[0072] S5, personalized model aggregation based on layer-by-layer direction guidance mechanism:
[0073] The layer-by-layer direction guidance mechanism is used for personalized aggregation of the i-th client;
[0074] Through the model level weight coefficient, the top k client models with larger aggregation weights are selected;
[0075] The guidance direction vector of each client to the i-th client is calculated;
[0076] The server calculates the direction vector and broadcasts it to the corresponding client;
[0077] After receiving the direction vector, each client updates the personalized model layer by layer;
[0078] Repeat the local training, aggregation weight calculation, and personalized model aggregation until the preset training round is reached.
[0079] In Example One, the layer-by-layer direction guidance mechanism calculates the similarity of the client models through cosine similarity and uses it to guide the layer-by-layer update of each client model, thereby optimizing the performance of the personalized models of each scrap steel recycling site and solving the data heterogeneity problem.
[0080] Example Two
[0081] Please refer to the attached Figure 1 , attached Figure 2 The embodiment of the application provides a personalized federated learning scrap steel detection method based on layer-by-layer direction guidance, which comprises the following steps:
[0082] S1, scrap steel picture collection and pretreatment:
[0083] A high-resolution industrial camera is used to collect scrap steel pictures at different unloading points of different scrap steel recycling sites to form a high-definition image dataset;
[0084] The collected images are labeled, including scrap steel type and quality information;
[0085] Data preprocessing is performed, including data cleaning, denoising, removing duplicate images and data cropping;
[0086] The scrap steel image dataset is divided into a training set and a test set in a ratio of 7:3;
[0087] S2, initialize the model:
[0088] Each scrap steel recycling site deploys an initial model with the same structure and parameters;
[0089] S3, local training:
[0090] Each client uses the scrap steel picture dataset for local training;
[0091] An Adam optimizer combined with a cross-entropy loss function is used for model optimization;
[0092] Each round of local training uses a small batch of data sets for gradient calculation and updates the model parameters;
[0093] S4, aggregation weight method based on client model difference:
[0094] Each scrap steel recycling site uploads the local model parameters and loss value to the server;
[0095] The server calculates the similarity of each client model layer by layer through Euclidean distance, and calculates the model level aggregation weight;
[0096] Define the client model parameters, calculate the model similarity of the client at the level;
[0097] The loss value is normalized to calculate the aggregation weight of the model level;
[0098] S5, personalized model aggregation based on layer-by-layer direction guidance mechanism:
[0099] The personalized aggregation of the i-th client uses the layer-by-layer direction guidance mechanism;
[0100] Through the model level weight coefficient, the first k client models with larger aggregation weight are selected;
[0101] The guidance direction vector of each client to the i-th client is calculated;
[0102] The server calculates the direction vector and broadcasts it to the corresponding client;
[0103] After each client receives the direction vector, the personalized model is updated layer by layer;
[0104] Repeat the local training, aggregation weight calculation and personalized model aggregation until the preset training round is reached.
[0105] Summary: Example two improves the aggregation mechanism by using Euclidean distance instead of cosine similarity to calculate the model similarity, and uses Adam optimizer to optimize the model. The method further enhances the adaptability of the model in the data heterogeneous environment and improves the performance of the personalized model.
[0106] Example three:
[0107] Please refer to the attached Figure 1 , attached Figure 2 The embodiment of the application provides a personalized federated learning scrap steel detection method based on layer-by-layer direction guidance, which comprises the following steps:
[0108] S1, scrap steel picture acquisition and pretreatment:
[0109] High-resolution industrial cameras are used to collect scrap steel pictures at different unloading points of different scrap steel recycling stations to form a high-definition image dataset;
[0110] The collected images are labeled, including scrap steel type and quality information;
[0111] Data preprocessing is performed, including data cleaning, denoising, removing duplicate images and data cropping;
[0112] The scrap steel image dataset is divided into a training set and a test set in a ratio of 7:3;
[0113] S2, initialize the model:
[0114] Each scrap steel recycling station deploys a convolutional neural network (CNN) initial model with the same structure and parameters;
[0115] S3, Local training:
[0116] Each client uses the scrap picture dataset for local training;
[0117] The Adam optimizer is used in combination with the cross-entropy loss function to optimize the model;
[0118] Each round of local training uses a small batch of data sets for gradient calculation and updates the model parameters;
[0119] S4, Aggregation weight method based on client model difference:
[0120] Each scrap recycling site uploads the local model parameters and loss value to the server;
[0121] The server calculates the similarity of each client model layer by layer through the cosine similarity, and calculates the model hierarchical aggregation weight;
[0122] Define the client model parameters, calculate the model similarity of the client at the level;
[0123] The loss value is normalized, and the hierarchical aggregation weight between the models is calculated;
[0124] S5, personalized model aggregation based on layer-by-layer direction guidance mechanism:
[0125] The layer-by-layer direction guidance mechanism is used for personalized aggregation of the i-th client;
[0126] Through the model level weight coefficient, the first k client models with larger aggregation weight are selected;
[0127] Calculate the guidance direction vector of each client to the i-th client;
[0128] The server calculates the direction vector and broadcasts it to the corresponding client;
[0129] After each client receives the direction vector, the personalized model is updated layer by layer;
[0130] Repeat the local training, aggregation weight calculation and personalized model aggregation until the preset training round is reached.
[0131] Summary: Example three uses a convolutional neural network (CNN) as the basic model, combined with a layer-by-layer direction guidance mechanism, to enhance the image data processing capability and improve the precision and efficiency of scrap steel detection.
[0132] Example four:
[0133] Please refer to the attached Figure 1 , attached Figure 2The embodiment of the application provides a personalized federal learning scrap steel detection method based on layer-by-layer direction guidance, which comprises the following steps:
[0134] S1, scrap steel picture collection and pretreatment:
[0135] High-resolution industrial cameras are used to collect scrap steel pictures at different unloading points of different scrap steel recycling stations to form a high-definition image dataset;
[0136] The collected images are labeled, including scrap steel type and quality information;
[0137] Data preprocessing is performed, including data cleaning, denoising, removing duplicate images and data cropping;
[0138] The scrap steel image dataset is divided into a training set and a test set according to a 6:4 ratio;
[0139] S2, initialization model:
[0140] An initial model with the same structure and parameters is deployed at each scrap steel recycling station;
[0141] S3, local training:
[0142] Each client uses the scrap steel picture dataset for local training;
[0143] An SGD optimizer is used in combination with a mean square error loss function to optimize the model;
[0144] Each round of local training uses a small batch of data sets to calculate gradients and update model parameters;
[0145] S4, aggregation weight method based on client model difference:
[0146] Each scrap steel recycling station uploads local model parameters and loss values to the server;
[0147] The server calculates the similarity of each client model layer by layer through cosine similarity, and calculates the model level aggregation weight;
[0148] Define the model parameters of each client, calculate the model similarity of the client at the level;
[0149] The loss value is normalized to calculate the aggregation weight of the model level;
[0150] S5, personalized model aggregation based on layer-by-layer direction guidance mechanism:
[0151] The personalized aggregation of the i-th client uses a layer-by-layer direction guidance mechanism;
[0152] Through the model level weight coefficient, the first k client models with larger aggregation weights are selected;
[0153] The direction vector of each client to the i-th client is calculated;
[0154] The server calculates the direction vector and broadcasts it to the corresponding client;
[0155] After each client receives the direction vector, the personalized model is updated layer by layer;
[0156] Repeat the local training, aggregated weight calculation and personalized model aggregation until the preset training round is reached.
[0157] Summary: Example four uses a training set and test set segmentation ratio of 6:4, and adopts a mean square error loss function, which can verify the generalization ability of the model under different data segmentation ratios.
[0158] Example five:
[0159] Please refer to the attached Figure 1 , attached Figure 2 , the embodiment of the application provides a personalized federal learning scrap steel detection method based on layer-by-layer direction guidance, comprising the following steps:
[0160] S1, scrap steel picture collection and pretreatment:
[0161] Use a high-resolution industrial camera to collect scrap steel pictures at different unloading points of different scrap steel recycling stations to form a high-definition image dataset;
[0162] Label the collected images, including scrap steel type and quality information;
[0163] Data preprocessing, including data cleaning, denoising, removing duplicate images and data cropping;
[0164] Divide the scrap steel image dataset into training set and test set according to the ratio of 8:2;
[0165] S2, initialize the model:
[0166] Deploy an initial model with the same structure and parameters at each scrap steel recycling site;
[0167] S3, local training:
[0168] Each client uses the scrap steel picture dataset for local training;
[0169] Use Adam optimizer combined with cross-entropy loss function for model optimization;
[0170] Each round of local training uses a small batch of data set for gradient calculation and updates the model parameters;
[0171] S4, aggregation weight method based on client model difference:
[0172] Each scrap recycling site uploads local model parameters and loss values to the server;
[0173] The server calculates the similarity of each client model layer by layer through the Euclidean distance, and calculates the model hierarchical aggregation weight;
[0174] Define the parameters of each client model, and calculate the model similarity of the client in the hierarchy;
[0175] The loss value is normalized, and the aggregation weight of the model hierarchy is calculated;
[0176] S5, personalized model aggregation based on layer-by-layer direction guidance mechanism:
[0177] The layer-by-layer direction guidance mechanism is used for personalized aggregation of the i-th client;
[0178] Through the model hierarchical weight coefficient, the first k client models with larger aggregation weight are selected;
[0179] Calculate the guidance direction vector of each client to the i-th client;
[0180] The server calculates the direction vector and broadcasts it to the corresponding client;
[0181] After each client receives the direction vector, the personalized model is updated layer by layer;
[0182] Repeat the local training, aggregation weight calculation and personalized model aggregation until the preset training round is reached.
[0183] Summary: Example five improves the similarity calculation method, and adopts the Euclidean distance instead of the cosine similarity. Through this way, the influence of different similarity calculation methods on the model aggregation effect can be explored to optimize the model performance.
[0184] Although the embodiments of the present application have been shown and described, it can be understood by those skilled in the art that various changes, modifications, replacements and variations can be made to these embodiments without departing from the principles and spirits of the present application, and the scope of the present application is defined by the appended claims and their equivalents.
Claims
1. A personalized federated learning scrap steel detection method based on layer-by-layer direction guidance, characterized in that, Comprising the following steps: S1, scrap steel picture collection and pretreatment: Collect high-definition pictures of different types of scrap steel at different unloading points of each scrap steel recycling station as training data set through high-resolution industrial camera; Label the collected image data; Data preprocessing, including data cleaning, removing noise and duplicate images, data cropping; Divide the scrap steel image data set into training set and test set according to the ratio of 8:2; S2, initialize model: Deploy the initial model with the same parameters and structure at each scrap steel recycling station; S3, local training: Each client uses the scrap steel picture data set for local training; Use random gradient descent combined with cross entropy loss function for model optimization; For random gradient descent, each round of local training uses small batch data set for gradient calculation and updates model parameters; S4, aggregation weight method based on client model difference: Each scrap steel recycling station uploads the local model parameters and loss value to the server; The server calculates the model similarity of any client at the level through cosine similarity; Normalize the loss value and combine the model similarity of each client at the level to calculate the aggregation weight coefficient of each model at the level; S5, personalized model aggregation based on layer-by-layer direction guidance mechanism: The personalized aggregation of the i-th client uses the layer-by-layer direction guidance mechanism; Select the top k client models with larger aggregation weight coefficients through the aggregation weight coefficients obtained in step S4; Calculate the direction vector of each client model using the guidance of each client to the i-th client; The server calculates the direction vector of each client model at the model level and broadcasts all direction vectors to the corresponding client; After receiving the direction vector, each client updates its personalized model layer by layer; Repeat the above local training, aggregation weight calculation and personalized model aggregation process until the preset training round is reached.
2. The method according to claim 1, wherein, In the S3 step, for random gradient descent, each round of local training uses small batch data set for gradient calculation and updates model parameters, which is defined as: wherein, are model parameters, is a learning rate, denotes the loss value for the nth sample.
3. The method of claim 1, wherein the method is a steel scrap detection method based on layer-by-layer direction guidance personalized federated learning. In the S3 step, for the cross entropy loss function, it is defined as: where N is the number of samples in the dataset, K is the number of labels of the dataset, denotes the probability that the nth sample actually belongs to the kth label, denotes the probability that the model predicts the nth sample belongs to the kth label.
4. The personalized federated learning scrap steel detection method based on layer-by-layer direction guidance according to claim 1, characterized in that, In the S4 step, each client model parameter is defined as Then the server accepts each client model parameter set The client model can be divided into s layers, and the i-th client model parameter can be divided into The model similarity of any client at the layer level can be calculated according to the cosine similarity, and the function expression is: wherein, represents the s-th client model and the j-th client model on the s-th layer of the model. represents the hierarchical similarity of the s-th client model and the j-th client model on the s-th layer of the model.
5. The personalized federated learning scrap steel detection method based on layer-by-layer direction guidance according to claim 4, characterized in that, The S4 step defines the loss value of each model as The server accepts the loss value set of each client The loss value is normalized, and the function expression is: ; By , , the aggregation weight coefficient of each model between layers wherein, , indicates the weight coefficient of client j to client i on the s-th layer of the model when the personalized model aggregation method based on the layer-by-layer direction guidance mechanism is performed.
6. The personalized federated learning scrap steel detection method based on layer-by-layer direction guidance according to claim 5, characterized in that, In the S5 step, the direction guidance mechanism is used to calculate the direction vector of each client model for client i by using the guidance of each client for client i, and the function expression is: wherein, is the direction vector of the selected participating client i in the kth round of personalized aggregation for the client i in the jth layer, and is the direction vector of the selected participating client i in the kth round of personalized aggregation for the client i in the jth layer, and is the direction vector of the selected participating client i in the kth round of personalized aggregation for the client i in the jth layer.
7. The personalized federated learning scrap steel detection method based on layer-by-layer direction guidance according to claim 6, characterized in that, In the S5 step, each client updates its personalized model layer by layer after receiving the direction vector, and the function expression is: .