Personalized federal learning method and system based on adaptive prototype aggregation, and medium
Through the adaptive prototype aggregation mechanism, the performance degradation problem of personalized federated learning in scenarios with unknown data heterogeneity is solved, and good performance and reduced communication overhead are achieved under different data heterogeneity, which is suitable for IoT devices.
Patent Information
- Application Number
- CN202510484151.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-17
- Publication Date
- 2025-09-12
AI Technical Summary
The performance of existing personalized federated learning methods degrades when the data distribution tends to IID, and traditional federated prototype learning fails to effectively solve the problem of unknown data heterogeneity, resulting in increased communication overhead and training burden.
An adaptive prototype aggregation mechanism is adopted to extract local feature vectors through the neural network model, calculate the local prototype, and aggregate it on the server side. Combined with dynamic weight updates, adaptive aggregation of local prototypes and global prototypes is achieved, reducing communication overhead and improving model performance.
It significantly improves model performance in different data heterogeneity scenarios, reduces communication overhead, adapts to client data distribution, and is suitable for IoT devices with limited resources.
Smart Images

Figure CN120633769A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a personalized federated learning method, system and medium based on adaptive prototype aggregation, and belongs to the technical field of federated learning. Background Art
[0002] With the rapid development of the Internet of Things (IoT), tens of billions of smart devices continuously generate massive amounts of data, providing a data foundation for machine learning applications in areas such as smart homes, smart healthcare, and industrial monitoring. However, traditional centralized machine learning requires data to be centrally processed on servers, which poses communication bottlenecks and privacy risks. Federated Learning (FFL) effectively alleviates these issues through its distributed training paradigm of "data fixed, model moving." However, it faces challenges with data heterogeneity and the balance between performance and resources. In FFL, data heterogeneity refers to the fact that client data distribution is often non-independent and identically distributed (Non-IID). This means that different clients have different data distributions and do not meet the same distributional properties. This discrepancy can arise from a variety of factors, such as the client's environment and the data collection method. Personalized Federated Learning (PFL) can improve performance in Non-IID scenarios by training personalized models on the client.
[0003] Existing personalized federated learning methods typically focus on optimizing for extreme non-IID scenarios. However, their performance degrades as the data distribution approaches IID. In reality, client data distributions are unknown and not always extremely non-IID. Specifically, when client data distributions are not extremely non-IID, existing personalized federated learning methods often experience significant performance degradation and fail to achieve satisfactory performance. Some methods address this issue by attempting to improve algorithm performance under varying data heterogeneity. However, these methods typically require training additional full models, which incurs additional training overhead and burden, making them unacceptable for the large number of resource-constrained devices in the IoT. Federated prototype learning requires only the transfer of prototypes, rather than the full model parameters, effectively reducing communication overhead during training. However, existing federated prototype learning methods use aggregated global prototypes for inference and fail to account for unknown data heterogeneity. Summary of the Invention
[0004] In view of this, the present invention provides a personalized federated learning method, device, system and storage medium based on adaptive prototype aggregation, which realizes the adaptive aggregation of local prototypes and global prototypes by introducing a dynamic weight aggregation mechanism in the federated prototype learning framework, effectively solving the model performance optimization problem in scenarios with unknown data heterogeneity, while significantly reducing communication overhead.
[0005] The first object of the present invention is to provide a personalized federated learning method based on adaptive prototype aggregation.
[0006] The second object of the present invention is to provide a personalized federated learning device based on adaptive prototype aggregation.
[0007] The third object of the present invention is to provide a personalized federated learning system based on adaptive prototype aggregation.
[0008] A fourth object of the present invention is to provide a computer-readable storage medium.
[0009] The first object of the present invention can be achieved by adopting the following technical solutions:
[0010] A personalized federated learning method based on adaptive prototype aggregation, the method comprising:
[0011] Extracting a local data set through a neural network model to obtain a feature vector, and calculating a category prototype for the feature vector as a local prototype, wherein the neural network model includes a feature extractor and a classifier;
[0012] Upload the local prototypes and corresponding category labels to the server, so that after collecting the local prototypes and category labels of all clients, the server aggregates the local prototypes to obtain the global prototype, and sends the global prototype back to all clients;
[0013] Receive the global prototype sent back by the server and perform adaptive aggregation on the local prototype and the global prototype;
[0014] Train the neural network model and update the neural network model parameters;
[0015] Use the trained neural network model and the aggregated prototype to perform label value inference on the data samples to be inferred.
[0016] Furthermore, the extraction of the local data set by the neural network model to obtain a feature vector and calculation of the category prototype for the feature vector specifically includes:
[0017] The local dataset is passed through the feature extractor f i Perform forward propagation to obtain the feature vector φ i =f i (xi ), so that the eigenvector φ i After classifier g i , and get the predicted output v i =g i (φ i );
[0018] Calculate the category prototype for the feature vector as follows:
[0019]
[0020] in, represents the local prototype of the m-th category of node i, D i,m Represents the local dataset D of node i i A subset of , representing the training data belonging to category m in the local dataset of node i.
[0021] Furthermore, the local prototypes are aggregated to obtain the global prototype, as shown in the following formula:
[0022]
[0023] in, represents the global prototype of the m-th category, represents the local prototype of the m-th category of node i, Represents the set of all nodes with category m data, N m Indicates the total number of samples of category m data for all nodes, D i,m Represents the local dataset D of node i i A subset of , representing the training data belonging to category m in the local dataset of node i.
[0024] Furthermore, the adaptive aggregation of the local prototype and the global prototype specifically includes:
[0025] Use a weight parameter W with exactly the same dimensions as the global prototype i , perform element-level aggregation on global prototypes and local prototypes as follows:
[0026]
[0027] Among them, ⊙ represents the element-wise product, 1 represents a product with W i Matrices with the same dimensions and all values are 1, P i represents a local prototype, Represents the global prototype;
[0028] In each training round, the weight parameter W i Perform iterative updates to update the aggregate prototype.
[0029] Furthermore, the weight parameter W is adjusted in each training round. i Perform iterative updates, including:
[0030] In training round t, for the local dataset D i Randomly sample s% of the data, denoted as Use this part of data to pass the model's feature extractor g i , get the sample characteristics Use L2 distance to measure the distance between the sample feature and the current aggregate prototype And adaptively update the weight parameters through the gradient descent method:
[0031] Furthermore, the updating of the neural network model parameters is completed based on the supervision loss error and the distance between the prototypes as the optimization target, as shown in the following formula:
[0032]
[0033] Among them, M represents the total number of categories in the data set, λ represents the importance weight used to balance the supervised learning loss and the regularization loss, and Loss ce Represents the cross entropy loss function, which is used to calculate the supervised learning loss; Loss d is a regularization term used to measure the distance.
[0034] Furthermore, the use of the trained neural network model and the aggregate prototype to perform label value inference on the data sample to be inferred specifically includes:
[0035] For a data sample x to be inferred i , through the feature extractor f i Get the data sample x i The eigenvector f i (x i );
[0036] Calculate the eigenvector f i (x i ) and the L2 distance inference of the aggregated prototype to obtain the label value As follows:
[0037]
[0038] in, Represents the aggregate prototype of the m-th category of node i.
[0039] The second object of the present invention can be achieved by adopting the following technical solutions:
[0040] A personalized federated learning device based on adaptive prototype aggregation, the device comprising:
[0041] A first training module is configured to extract a local data set through a neural network model to obtain a feature vector and calculate a category prototype for the feature vector as a local prototype, wherein the neural network model includes a feature extractor and a classifier;
[0042] Aggregation module, used to upload local prototypes and corresponding category labels to the server, so that after collecting the local prototypes and category labels of all clients, the server aggregates the local prototypes to obtain the global prototype, and sends the global prototype back to all clients;
[0043] The adaptive prototype aggregation module is used to receive the global prototype sent back by the server and adaptively aggregate the local prototype and the global prototype;
[0044] The second training module is used to train the neural network model and update the neural network model parameters;
[0045] The inference module is used to use the trained neural network model and the aggregate prototype to perform label value inference on the data samples to be inferred.
[0046] The third object of the present invention can be achieved by adopting the following technical solutions:
[0047] A personalized federated learning system based on adaptive prototype aggregation, the system comprising N clients and a server, wherein the server is connected to the N clients respectively;
[0048] The client is used to execute the personalized federated learning method described above;
[0049] The server is used to aggregate the local prototypes and category labels of all clients to obtain a global prototype, and send the global prototype back to all clients.
[0050] The fourth object of the present invention can be achieved by adopting the following technical solutions:
[0051] A computer-readable storage medium stores a program, which, when executed by a processor, implements the personalized federated learning method described above.
[0052] The present invention has the following beneficial effects compared to the prior art:
[0053] 1. In the field of personalized federated learning, this invention takes into account the scenarios in reality where data heterogeneity is unknown and not always extremely non-IID, which is more in line with real-life application scenarios.
[0054] 2. The present invention designs an adaptive prototype aggregation module (APA), through which global prototypes and local prototypes can be adaptively aggregated, so that the inferred prototype is more consistent with the local data distribution of the client, thereby better adapting to different data heterogeneity.
[0055] 3. Compared with the traditional federated prototype learning method, this invention achieves significant performance improvement with a lightweight design through adaptive prototype aggregation; compared with the traditional personalized federated learning method, it significantly reduces the communication overhead.
[0056] 4. The present invention demonstrates good performance under different data heterogeneity conditions and significantly reduces communication overhead, and has broad application prospects in personalized federated learning scenarios in the Internet of Things. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying any creative work.
[0058] Figure 1 This is a schematic diagram of the personalized federated learning system architecture based on adaptive prototype aggregation according to Example 1 of the present invention.
[0059] Figure 2 This is a flowchart of a personalized federated learning method based on adaptive prototype aggregation according to Example 1 of the present invention.
[0060] Figure 3 This is a schematic diagram of the adaptive prototype aggregation principle of Example 1 of the present invention.
[0061] Figure 4 This is a structural block diagram of a personalized federated learning device based on adaptive prototype aggregation according to Example 2 of the present invention. DETAILED DESCRIPTION
[0062] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0063] Example 1:
[0064] like Figure 1 As shown, this embodiment provides a personalized federated learning system based on adaptive prototype aggregation, which includes N clients and a server S. The server S is a central server connected to N clients respectively. The N clients constitute a client set C. The client numbered i has a local data set D. i ={x i ,y i}, where x i represents the data sample set, y i Represents the corresponding category label set; in order to learn the classification task, each client also has a neural network model, which includes a feature extractor f i and classifier g i .
[0065] like Figure 2 As shown, this embodiment also provides a personalized federated learning method based on adaptive prototype aggregation, which is mainly implemented through the client of the above system and specifically includes the following steps:
[0066] S201. Extract the local data set through a neural network model to obtain a feature vector, and calculate the category prototype of the feature vector as the local prototype.
[0067] In this embodiment, all clients pass their local datasets through the feature extractor f i Perform forward propagation to obtain the feature vector φ i =f i (x i ), so that the eigenvector φ i After classifier g i , and get the predicted output υ i =g i (φ i ); Calculate the category prototype for the feature vector as follows:
[0068]
[0069] in, represents the local prototype of the m-th category of node i, D i,m Represents the local dataset D of node i i A subset of , representing the training data belonging to category m in the local dataset of node i.
[0070] S202: Upload the local prototype and the corresponding category label to the server.
[0071] In this embodiment, all clients upload their local prototypes and corresponding category labels to the server. After collecting the local prototypes and category labels of all clients, the server aggregates the local prototypes to obtain a global prototype and sends the global prototype back to all clients.
[0072] Among them, the local prototypes are aggregated to obtain the global prototype, as shown in the following formula:
[0073]
[0074] in, represents the global prototype of the m-th category, Represents the set of all nodes with category m data, N m Indicates the total number of samples of category m data for all nodes.
[0075] S203: Receive the global prototype sent back by the server, and perform adaptive aggregation on the local prototype and the global prototype.
[0076] like Figure 3 As shown in the figure, after all clients receive the global prototype sent back by the server, they execute the adaptive prototype aggregation module to adaptively aggregate the local prototype and the global prototype. The specific process is as follows:
[0077] Use a weight parameter W with exactly the same dimensions as the global prototype i , perform element-level aggregation on global prototypes and local prototypes as follows:
[0078]
[0079] Among them, ⊙ represents the Hadamard Product, 1 represents a i Matrices with the same dimensions and all values are 1, P i represents a local prototype, Represents the global prototype;
[0080] In each training round, the weight parameter W i Perform iterative updates. Specifically, in training round t, the local dataset D i Randomly sample s% of the data, denoted as Use this part of data to pass the model's feature extractor f i , get the sample characteristics Use L2 distance to measure the distance between the sample feature and the current aggregate prototype And adaptively update the weight parameters through the gradient descent method:
[0081]
[0082] By adjusting the weight parameter W i The iterative update of the aggregation prototype is realized, so that the updated aggregation prototype can better fit the local sample feature distribution of the node.
[0083] S204: Train the neural network model and update the neural network model parameters.
[0084] In this embodiment, updating the neural network model parameters is completed based on the supervision loss error and the distance between prototypes as the optimization target, as shown in the following formula:
[0085]
[0086] Among them, M represents the total number of categories in the data set, λ represents the importance weight used to balance the supervised learning loss and the regularization loss, and Loss ce Represents the cross entropy loss function, which is used to calculate the supervised learning loss; Loss d It is a regularization term used to measure the distance. In this embodiment, the L2 distance is used.
[0087] S205 , using the trained neural network model and the aggregate prototype to perform label value inference on the data sample to be inferred.
[0088] Specifically, for a data sample x to be inferred i , through the feature extractor f i Get the data sample x i The eigenvector f i (x i );Calculate the eigenvector f i (x i ) and the L2 distance inference of the aggregated prototype to obtain the label value As follows:
[0089]
[0090] in, Represents the aggregate prototype of the mth category of node i
[0091] Repeat the above steps S201 to S205 until convergence.
[0092] It should be noted that although the method operations of the above embodiments are described in a particular order, this does not require or imply that the operations must be performed in that particular order, or that all of the illustrated operations must be performed to achieve the desired results. Rather, the depicted steps may be performed in a different order. Additionally or alternatively, certain steps may be omitted, multiple steps may be combined into a single step, and / or a single step may be broken down into multiple steps.
[0093] Example 2:
[0094] like Figure 4 As shown, this embodiment provides a personalized federated learning device based on adaptive prototype aggregation, which includes a first training module 401, an aggregation module 402, an adaptive prototype aggregation module 403, a second training module 404, and an inference module 405. The specific functions of each module are as follows:
[0095] A first training module 401 is configured to extract a local data set using a neural network model to obtain a feature vector and calculate a category prototype for the feature vector as a local prototype. The neural network model includes a feature extractor and a classifier.
[0096] Aggregation module 402, for uploading local prototypes and corresponding category labels to the server, so that after collecting local prototypes and category labels of all clients, the server aggregates the local prototypes to obtain a global prototype, and sends the global prototype back to all clients;
[0097] The adaptive prototype aggregation module 403 is used to receive the global prototype sent back by the server and adaptively aggregate the local prototype and the global prototype;
[0098] The second training module 404 is used to train the neural network model and update the neural network model parameters;
[0099] The inference module 405 is configured to use the trained neural network model and the aggregate prototype to perform label value inference on the data sample to be inferred.
[0100] It should be noted that the device provided in this embodiment is only illustrated by the division of the above-mentioned functional modules. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure can be divided into different functional modules to complete all or part of the functions described above.
[0101] Example 3:
[0102] This embodiment provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the personalized federated learning method of the above-mentioned embodiment 1 is implemented as follows:
[0103] A local data set is extracted through a neural network model to obtain a feature vector, and a category prototype is calculated for the feature vector as a local prototype, wherein the neural network model includes a feature extractor and a classifier; the local prototype and the corresponding category label are uploaded to a server, so that after the server collects the local prototypes and category labels of all clients, the local prototypes are aggregated to obtain a global prototype, and the global prototype is sent back to all clients; the global prototype sent back by the server is received, and the local prototype and the global prototype are adaptively aggregated; the neural network model is trained, and the neural network model parameters are updated; and the trained neural network model and the aggregated prototype are used to infer the label value of the data sample to be inferred.
[0104] It should be noted that the computer-readable storage medium of the present embodiment may be a computer-readable signal medium or a computer-readable storage medium or any combination thereof. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor device, apparatus or component, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof.
[0105] In this embodiment, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution device, apparatus, or device. Furthermore, in this embodiment, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable program. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable storage medium other than a computer-readable storage medium that can transmit, propagate, or transfer a program for use by or in conjunction with an instruction execution device, apparatus, or device. The computer program contained on a computer-readable storage medium may be transmitted using any suitable medium, including but not limited to wires, optical cables, RF (radio frequency), etc., or any suitable combination thereof.
[0106] The computer readable storage medium can be written in one or more programming languages or a combination thereof to execute the computer program for performing the present embodiment, including object-oriented programming languages such as Java, Python, C++, and conventional procedural programming languages such as C or similar programming languages. The program can be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect via the Internet).
[0107] In summary, the present invention performs element-level weighted aggregation on the client's local prototype and the global prototype, so that the aggregated prototype can adapt to the client's data distribution, thereby achieving good performance under different data heterogeneity.
[0108] The foregoing description is merely a preferred embodiment of the present invention. It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention. Therefore, the embodiments should be considered in all respects as illustrative and non-restrictive. The scope of the present invention is defined by the appended claims, not the foregoing description, and all variations that come within the meaning and range of equivalents of the claims are intended to be included within the present invention.
Claims
1. A personalized federated learning method based on adaptive prototype aggregation, characterized by: The method comprises: Extracting a local data set through a neural network model to obtain a feature vector, and calculating a category prototype for the feature vector as a local prototype, wherein the neural network model includes a feature extractor and a classifier; Upload the local prototypes and corresponding category labels to the server, so that after collecting the local prototypes and category labels of all clients, the server aggregates the local prototypes to obtain the global prototype, and sends the global prototype back to all clients; Receive the global prototype sent back by the server and perform adaptive aggregation on the local prototype and the global prototype; Train the neural network model and update the neural network model parameters; Use the trained neural network model and the aggregated prototype to perform label value inference on the data samples to be inferred.
2. The personalized federated learning method according to claim 1, characterized in that: The method of extracting the local data set through the neural network model to obtain a feature vector and calculating the category prototype of the feature vector specifically includes: The local dataset is passed through the feature extractor f i Perform forward propagation to obtain the feature vector φ i =f i (x i ), so that the eigenvector φ i After classifier g i , and get the predicted output v i =g i (φ i ); Calculate the category prototype for the feature vector as follows: Among them, P i (m) represents the local prototype of the m-th category of node i, D i,m Represents the local dataset D of node i i A subset of , representing the training data belonging to category m in the local dataset of node i.
3. The personalized federated learning method according to claim 1, characterized in that: The local prototypes are aggregated to obtain the global prototype, as shown in the following formula: in, represents the global prototype of the mth category, P i (m) represents the local prototype of the m-th category of node i, Represents the set of all nodes with category m data, N m Indicates the total number of samples of category m data for all nodes, D i,m Represents the local dataset D of node i i A subset of , representing the training data belonging to category m in the local dataset of node i.
4. The personalized federated learning method according to claim 1, characterized in that: The adaptive aggregation of the local prototype and the global prototype specifically includes: Use a weight parameter W with exactly the same dimensions as the global prototype i , perform element-level aggregation on global prototypes and local prototypes as follows: Among them, ⊙ represents the element-wise product, 1 represents a product with W i Matrices with the same dimensions and all values are 1, P i represents a local prototype, Represents the global prototype; In each training round, the weight parameter w i Perform iterative updates to update the aggregate prototype.
5. The personalized federated learning method according to claim 4, characterized in that: In each training round, the weight parameter W i Perform iterative updates, including: In training round t, for the local dataset D i Randomly sample s% of the data, denoted as Use this part of data to pass the model's feature extractor f i , get the sample characteristics Use L2 distance to measure the distance between the sample feature and the current aggregate prototype And adaptively update the weight parameters through the gradient descent method:
6. The personalized federated learning method according to claim 1, characterized in that: The updating of the neural network model parameters is completed based on the supervision loss error and the distance between the prototypes as the optimization target, as follows: Among them, M represents the total number of categories in the data set, λ represents the importance weight used to balance the supervised learning loss and the regularization loss, and Loss ce Represents the cross entropy loss function, which is used to calculate the supervised learning loss; Loss d is a regularization term used to measure the distance.
7. The personalized federated learning method according to claim 1, characterized in that: The method of using the trained neural network model and the aggregate prototype to perform label value inference on the data sample to be inferred specifically includes: For a data sample x to be inferred i , through the feature extractor f i Get the data sample x i The eigenvector f i (x i ); Calculate the eigenvector f i (x i ) and the L2 distance inference of the aggregated prototype to obtain the label value As follows: in, Represents the aggregate prototype of the m-th category of node i.
8. A personalized federated learning device based on adaptive prototype aggregation, characterized in that: The device comprises: A first training module is configured to extract a local data set through a neural network model to obtain a feature vector and calculate a category prototype for the feature vector as a local prototype, wherein the neural network model includes a feature extractor and a classifier; Aggregation module, used to upload local prototypes and corresponding category labels to the server, so that after collecting the local prototypes and category labels of all clients, the server aggregates the local prototypes to obtain the global prototype, and sends the global prototype back to all clients; The adaptive prototype aggregation module is used to receive the global prototype sent back by the server and adaptively aggregate the local prototype and the global prototype; The second training module is used to train the neural network model and update the neural network model parameters; The inference module is used to use the trained neural network model and the aggregate prototype to perform label value inference on the data samples to be inferred.
9. A personalized federated learning system based on adaptive prototype aggregation, characterized by: The system includes N clients and a server, wherein the servers are connected to the N clients respectively; The client is used to execute the personalized federated learning method according to any one of claims 1 to 7; The server is used to aggregate the local prototypes and category labels of all clients to obtain a global prototype, and send the global prototype back to all clients.
10. A computer-readable storage medium storing a program, characterized in that: When the program is executed by a processor, the personalized federated learning method according to any one of claims 1 to 7 is implemented.