A blockchain distributed federated learning method, system, and terminal for connected vehicles
Through the blockchain distributed federated learning framework, the problems of data imbalance and privacy protection in intelligent connected vehicles are solved, efficient and secure model training and data sharing are achieved, data privacy and training efficiency are ensured, and single point failures are avoided.
Patent Information
- Application Number
- CN202310972846.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-03
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2043-08-03
AI Technical Summary
Traditional centralized federated learning suffers from data imbalance, low communication efficiency, privacy protection loopholes and single point failure problems, making it difficult to effectively collaborate and train models, especially in intelligent connected vehicles.
Adopting the blockchain distributed federated learning framework, the model training and aggregation functions are distributed across the device layer, device management layer, and blockchain layer through a hierarchical structure. By utilizing the decentralization and immutability of blockchain, combined with smart contracts and consensus algorithms, blockchain nodes with high computing power are selected for model aggregation to ensure data privacy and training efficiency.
It enables efficient and secure model training in intelligent connected vehicles, protects data privacy, reduces communication overhead, avoids single points of failure, improves model accuracy and training efficiency, and ensures fairness and transparency.
Smart Images

Figure CN117196010B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of information technology service technology, and in particular relates to a blockchain distributed federated learning method, system and terminal for connected vehicles. Background Art
[0002] Federated learning is essentially a distributed machine learning framework that enables data sharing and collaborative modeling, effectively resolving data silos while ensuring data privacy, security, and legal compliance. Its core concept is that when multiple data sources participate in model training, joint model training occurs only through the interaction of intermediate model parameters, without transferring the original data. This approach achieves a balance between data privacy protection and data sharing and analysis, creating a data application model where "data is available but not visible."
[0003] Centralized federated learning is a machine learning approach designed to address data privacy and data center centralization. Traditional machine learning methods typically require data to be centralized on a single server for training, which can pose risks to data security and privacy. Centralized federated learning, on the other hand, pushes model training to distributed client devices, allowing them to train locally and then aggregate the updated model parameters to a central server, enabling model updates and improvements while protecting user data privacy.
[0004] The core idea of centralized federated learning is to share model updates while keeping the data local. This approach avoids the direct transmission of sensitive data, reducing the risk of data leakage and privacy violations. Furthermore, federated learning can better handle large datasets because all data does not need to be transferred to a central server for training.
[0005] However, centralized federated learning also has some problems and defects:
[0006] (1) Data bias and imbalance: In federated learning, each client may have different data distribution and characteristics, which may lead to data bias and imbalance problems. If the data of some clients is more representative, while the data of other clients is less or unrepresentative, this may cause the model to perform well in some areas but poorly in other areas.
[0007] (2) Communication efficiency and bandwidth limitations: In federated learning, model updates need to be transmitted to a central server over the network. This can lead to challenges in communication efficiency and bandwidth limitations, especially in resource-constrained environments such as mobile devices. Large-scale model updates can result in high latency and high energy consumption, reducing training efficiency.
[0008] (3) Communication efficiency and bandwidth limitations: In federated learning, model updates need to be transmitted to a central server over the network. This can lead to challenges in communication efficiency and bandwidth limitations, especially in resource-constrained environments such as mobile devices. Large-scale model updates can result in high latency and high energy consumption, reducing training efficiency.
[0009] (4) Challenges in Federated Learning Algorithm Design: Federated learning algorithm design needs to address multiple issues, such as the aggregation method of model parameters, client selection strategy, model security and robustness, etc. Solving these issues requires comprehensive consideration of model performance, communication efficiency, privacy protection, and other aspects.
[0010] (5) Challenges in Federated Learning Algorithm Design: Federated learning algorithm design needs to address multiple issues, such as the aggregation method of model parameters, client selection strategy, model security and robustness, etc. Solving these issues requires comprehensive consideration of model performance, communication efficiency, privacy protection, and other aspects.
[0011] (6) Privacy protection vulnerabilities: Although centralized federated learning protects data privacy by training locally, there are still some privacy protection vulnerabilities. For example, some key information may be leaked through model parameter updates, allowing attackers to infer certain features or sensitive information of the original data.
[0012] Distributed federated learning has the following advantages:
[0013] (1) Anonymity: Each client can send model parameters to other clients anonymously, ensuring the privacy of the data.
[0014] (2) The client is only responsible for sending the global model, and the communication cost and computational overhead are small.
[0015] (3) The global model is updated on each device, which not only reduces the server's computational overhead but also improves the robustness of the system and avoids single points of failure.
[0016] Generally speaking, distributed federated learning has the following four steps:
[0017] 1. The server initializes the model parameters and then sends them to each client;
[0018] 2. The client uses local data to train the model and update local model parameters;
[0019] 3. The client selects some other clients, sends local intermediate parameters, and accepts intermediate parameters from other clients;
[0020] 4. Repeat steps 2 and 3 until the model converges.
[0021] The above analysis reveals the following problems and drawbacks of existing technologies: Traditional centralized federated learning suffers from data imbalance, significant communication overhead, and difficulty managing collaboration between participants. Data imbalance arises because each participant may possess varying amounts and quality of data. Some participants may have a large number of data samples, while others may have only a small number. This can lead to less impact on participants with less data during training, resulting in unfairness and performance degradation. Federated learning involves communication between participants to exchange model updates and parameters. This can result in significant communication overhead, especially when there are a large number of participants or when network bandwidth is limited. High latency and bandwidth consumption can affect training efficiency and real-time performance. The success of federated learning depends on the level of collaboration between participants. However, in real-world scenarios, participants may have different interests and goals and may be unwilling or inactive to collaborate. This can lead to uneven contributions from some participants or disruptions in collaboration, impacting overall model performance and convergence speed.
[0022] Distributed federated learning can address the problem of centralized storage. It can also employ sampling techniques to address data imbalance. Participants can sample data according to specific rules to ensure balanced data across categories during training, thereby mitigating performance degradation caused by data imbalance. Distributed federated learning can reduce communication overhead by using more efficient communication protocols and compression technologies. For example, differential privacy can be used to aggregate model updates, reducing the amount of data required for transmission. Furthermore, incremental learning can be employed, transmitting only incremental model updates rather than the entire model parameters. Distributed federated learning can employ appropriate incentive mechanisms and collaboration strategies to encourage active collaboration among participants. For example, a reward mechanism can be introduced to evaluate and reward participants' contributions to enhance their willingness to cooperate. Furthermore, appropriate protocols and negotiation mechanisms can be designed to resolve conflicts between participants. Integrating blockchain into distributed federated learning, leveraging its decentralization, transparency, and immutability, can effectively address the federated aggregation process required in centralized federated learning.
[0023] In the context of intelligent connected vehicles, federated learning is used as a method to apply this technology to the field. Intelligent connected vehicles (ICVs) use vehicle-to-vehicle (V2X) technology to connect vehicles to the internet, enabling data exchange and collaborative operations between vehicles and between vehicles and infrastructure. ICVs carry a large amount of sensor data, such as speed, acceleration, and location. This data can be used to train machine learning models, enhancing vehicle perception, decision-making, and control capabilities.
[0024] The basic idea behind federated learning for intelligent connected vehicle data is to improve the performance and security of the entire connected vehicle system by combining data from multiple vehicles for model training and knowledge sharing, while protecting data privacy. Specifically, federated learning for intelligent connected vehicle data typically involves the following steps:
[0025] 1. Data collection and preprocessing: The vehicle collects sensor data, such as images, sounds, and vehicle status data. This data is then preprocessed, such as through denoising, feature extraction, and data normalization.
[0026] 2. Model training and updating: Each vehicle uses its own data for model training on a local device. This means that each vehicle can independently learn from its own data to generate a local model.
[0027] 3. Model aggregation: By using federated learning algorithms, vehicles can aggregate the parameters of local models into a global model. This process enables communication between vehicles and sharing of updated model parameters.
[0028] 4. Model Application: The updated global model can be transmitted back to the vehicle for use in the perception, decision-making, and control tasks of the intelligent connected car. By sharing knowledge, vehicles can benefit from the data and experience of other vehicles, improving their own performance and intelligence.
[0029] Federated learning for intelligent connected vehicle data offers the advantages of protecting data privacy, reducing data transmission costs, improving model performance, and enhancing the overall security of intelligent connected vehicle systems. It enables collaborative learning between vehicles, collectively improving driving safety, traffic efficiency, and user experience. Summary of the Invention
[0030] In response to the problems existing in the existing technology, the present invention provides a blockchain distributed federated learning method, system and terminal for connected vehicles.
[0031] The present invention is implemented as follows: a blockchain distributed federated learning method for connected vehicles. The blockchain distributed federated learning method for connected vehicles adopts a distributed federated learning framework based on blockchain. Through a hierarchical structure, the framework is refined into three layers, namely the device layer, the device management layer, and the blockchain layer. The main function of the device layer is that the client is responsible for receiving the global model, performing local model training, and uploading the local model gradient to the base station end of the device management layer; the device management layer is responsible for receiving the model gradient of the managed client, and performing preliminary aggregation to obtain a preliminary aggregated model; finally, the blockchain layer performs the final global aggregation of this round, adopts the blockchain consensus algorithm designed in the present invention, and selects the blockchain node for aggregation operation; the consensus algorithm adopts a multiple selection mechanism, first of all, it is necessary to evaluate the computing power value of each blockchain node, because if the final aggregation process in this round is completed by a node with a lower computing power value, it will increase the training time and cause the training effect to deteriorate; secondly, the model gradients of different device management layers are evaluated, and the blockchain node with a higher model gradient is selected for the final model aggregation. Finally, the blockchain computing power value and the model gradient are comprehensively considered to select the blockchain node leader in this round for the final model aggregation; specifically including:
[0032] Step 1: Each node in the blockchain network runs a smart contract to determine its own computing power value and assigns a computing power weight to each node based on the computing power value. This is used in the initial stage of final node selection.
[0033] Step 2: Each client receives the training model from the server, performs local model training, and uploads the model gradient obtained from the local training to the base station;
[0034] Step 3: The base station will perform a preliminary aggregation of the local model gradients trained by each device in the group, and upload the aggregation results to the blockchain for public disclosure.
[0035] Step 4: Each node in the blockchain determines the training weights of different nodes by comparing the model gradients. In each round, the node with the highest weight is selected as the leader node for final global aggregation, and the final global aggregation result is broadcast on the blockchain network.
[0036] Furthermore, the blockchain distributed federated learning method for connected vehicles uses a consensus mechanism to compare the computing power values of each blockchain node. By running the same protocol on multiple nodes, the security and reliability of the data are maintained and verified. Different nodes in the blockchain network may have different computing power values. In a blockchain network, nodes with higher computing power values have higher weights in the consensus algorithm and greater influence in the blockchain network. The difference in computing power values of different nodes will lead to uneven node distribution in the network:
[0037] Furthermore, the blockchain distributed federated learning method for connected vehicles implements an algorithm for evaluating the computing power values of different nodes of the blockchain using a consensus mechanism by utilizing blockchain smart contracts. Specifically, the algorithm is as follows: using the blockchain smart contract, each time a node calls the mine function, the system generates a random number and calculates its hash value; if the first three digits of the hash value are 0, the blockchain node successfully finds the required random number; thereafter, the contract updates the number of random numbers calculated by the node, encrypts the random number, adds the ID value of the node to it, and then stores the encrypted random number; other nodes obtain the number of random numbers calculated by other nodes by calling the getMinedCount function, and can call the getEncryptedRandomNumber function to obtain the encrypted random number of the node; the node can obtain the random number of other nodes and verify it. If the first three digits of the verified hash random number are 0, the random number found by this node meets the requirements, and the computing power value announced by the node is true, and it is assigned a computing power weight.
[0038] Furthermore, the blockchain distributed federated learning method for connected vehicles uses smart contracts to achieve consensus among blockchain nodes. The designed algorithm specifically includes:
[0039] In the first round, any node in the blockchain is randomly selected to perform global aggregation using the aggregation algorithm of the smart contract. This ensures that all aggregation processes are public on the chain, thus ensuring the transparency of the aggregation process.
[0040] Starting from the second round, each blockchain node compares its uploaded model gradient with the global model gradient aggregated in the previous round, selects the node with the best training effect as the leader of the next round of aggregation, and aggregates the global model of the next round;
[0041] At the same time, based on the comparison results, each blockchain node is assigned an aggregation weight. Note that this weight is not a training weight, but only serves as the evaluation weight of the aggregation leader. At the same time, only blockchain nodes above the global model aggregation threshold are eligible for the final global aggregation of this round.
[0042] Assume that each device management layer calculates the model parameters uploaded by the device in this round and performs preliminary aggregation. Assume that there are four blockchain nodes A, B, C, and D:
[0043] A data → gradient A =(x A ,y A ,z A ),B data → gradient B =(xB ,y B ,z B );
[0044] C data → gradient C =(x C ,y C ,z C ),D data → gradient D =(x D ,y D ,z D );
[0045] The model gradient of the device management layer collected by A, B, C, and D is gradient A ,gradient B ,gradient C ,gradient D ;
[0046] Each blockchain node uses the model aggregation algorithm in the smart contract to aggregate the preliminary model gradients uploaded by all nodes to obtain a new model gradient g , and publicly:
[0047] gradient g =AVG(gradient A ,gradient B ,gradient C ,gradient D );
[0048] Compare the local model gradient of each blockchain node with the aggregated global model gradient result to obtain the model gradient difference θ:
[0049] θ A =cos(gradient g ,gradient A ),θ B =cos(gradient g ,gradient B );
[0050] θ C =cos(gradient g ,gradient C ),θ D =cos(gradient g ,gradient D );
[0051] Since the model gradient difference θ ranges from [-1,1], the model mean is defined as Normalize it; define its model gradient mean as Only the device management end with the model gradient above the threshold is eligible for model aggregation; the final node is selected as the node with the largest computing power weight that satisfies the model aggregation result above the threshold, and the training weight calculation formula is w i for:
[0052]
[0053] Another object of the present invention is to provide a blockchain distributed federated learning system for connected vehicles that applies the blockchain distributed federated learning method for connected vehicles. The blockchain distributed federated learning system for connected vehicles includes:
[0054] Device layer: In federated learning, each device is called a client or a device end. It owns a portion of the dataset and is responsible for performing some model update operations. A device end is a role in federated learning, usually referring to some terminal devices or computer servers, used for tasks such as storing local data, performing local model update operations, and communicating with the central server.
[0055] Device management layer: There is a base station managed by a group of device terminals, so that the base station can be trusted by all the device terminals under it; the device management layer is composed of multiple base stations, each base station receives the model gradient from the device terminal, and after preliminary aggregation, it can obtain a preliminary model gradient specific to each device layer managed by this base station; the base station serves as a public platform for collecting the local training results of each device terminal. Each device terminal uses local data to train the model and uploads the trained model parameters to the base station. The device management layer performs a preliminary aggregation in advance to obtain the aggregated model gradient trained on each device terminal connected to the device management layer, and uploads the trained model gradient to the blockchain node for subsequent node selection operations; after the device management layer undergoes preliminary aggregation, the source of the obtained model parameters will no longer be known;
[0056] Blockchain layer: It can realize peer-to-peer transactions, coordination and collaboration based on decentralized credit in a distributed system where nodes do not need to trust each other by using data encryption, timestamps, distributed consensus and economic incentives.
[0057] Furthermore, the device side also participates in model training. Several devices work together as a group to train a global model by uploading locally updated model gradients to the base station. All devices together form the device layer.
[0058] Furthermore, the blockchain node layer, as an aggregation and public layer, utilizes the decentralized characteristics, immutability, and openness and transparency of the blockchain to ensure the verifiability of aggregation during the federated learning process and the fairness of the elected nodes; the functions that the blockchain layer needs to implement are mainly reflected in two aspects, namely computing power value verification and the federated aggregation process.
[0059] Another object of the present invention is to provide a computer device, which includes a memory and a processor. The memory stores a computer program. When the computer program is executed by the processor, the processor executes the steps of the blockchain distributed federated learning method for connected vehicles.
[0060] Another object of the present invention is to provide a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the processor executes the steps of the blockchain distributed federated learning method for connected vehicles.
[0061] Another object of the present invention is to provide an information data processing terminal, which is used to implement the blockchain distributed federated learning system for connected vehicles.
[0062] In combination with the above technical solutions and the technical problems solved, the advantages and positive effects of the technical solutions to be protected by the present invention are as follows:
[0063] First, in view of the technical problems existing in the above-mentioned prior art and the difficulty of solving these problems, we closely combine the technical solutions to be protected by the present invention and the results and data during the research and development process, and conduct a detailed and in-depth analysis of how the technical solutions of the present invention solve the technical problems and some creative technical effects brought about by solving the problems. The specific description is as follows:
[0064] In response to the problems existing in the prior art, the present invention discloses a blockchain distributed federated learning framework for connected vehicles. It removes the federated aggregation function of the central server in the traditional federated learning framework, applies its aggregation function to the blockchain, and uses the openness, transparency and immutability of the blockchain to complete each round of the federated aggregation process. At the same time, in order to avoid privacy leakage when each client transmits the model gradient during the training process, the present invention introduces a base station, that is, a device management layer, into the framework. Each base station preliminarily aggregates the model gradients of each device end managed by its lower layer, and uploads the aggregation results to the blockchain. Through the blockchain smart contract consensus algorithm, the computing power value of each blockchain node is calculated, and the advantages and disadvantages of the model gradients of different blockchain nodes are taken into consideration. The leader node of this round is selected, the final model aggregation is performed and the aggregation results are made public, solving the single point failure problem of the federated learning central server from the source.
[0065] The consensus algorithm uses a multi-selection mechanism. First, the hashrate of each blockchain node is evaluated. This is because if the final aggregation process in this round is completed by a node with lower hashrate, training time will increase and training results will be reduced. Secondly, the model gradients of different device management layers are evaluated, and the blockchain node with higher model gradients is selected for the final model aggregation. Finally, the blockchain node leader in this round is selected for the final model aggregation based on a comprehensive consideration of the blockchain hashrate and model gradients.
[0066] The specific training process is as follows: First, each blockchain node calculates its computing power using the consensus algorithm designed in this invention. This is because, in a blockchain network, a node's computing power generally refers to its contribution to the consensus algorithm, specifically its contribution to data verification and recordkeeping within the blockchain. Nodes with higher computing power have higher weights in the consensus algorithm, thus exerting greater influence within the blockchain network. Differences in computing power among different nodes can lead to uneven node distribution within the network, so ensuring network fairness and security is crucial when designing blockchain systems. After all nodes run the consensus smart contract, they obtain a computing power evaluation metric—a hashed random number that meets certain requirements. At this point, other blockchain nodes can also verify the authenticity of the computing power value broadcast by that node. Specifically, each node publishes its own random number. Other nodes can verify the hash value by calling a function in the smart contract to determine whether the random number meets certain requirements and, therefore, the authenticity of its computing power value. A computing power weight is assigned to each node based on its runtime.
[0067] Subsequently, the client at the device layer receives the global model and trains the model using its own local data source, obtaining local trained model gradients. Once all clients have completed training, the base station collects the model gradients from each client under its management and performs a preliminary aggregation operation to obtain a preliminary aggregated model gradient. Due to the unique nature of the base station, the source of the model gradients obtained after the preliminary aggregation at the device management layer is unknown, thus ensuring data privacy to a certain extent. The preliminary aggregated model gradients are then uploaded to the blockchain node and made public. The blockchain consensus mechanism then scores the model gradients of each node, selecting the node with the best model gradient and assigning it an aggregation weight.
[0068] Finally, the node computing power value and model gradient are integrated to select the final blockchain node to complete the final model aggregation operation, thus ending this round of federated training.
[0069] Second, considering the technical solution as a whole or from the perspective of the product, the technical effects and advantages of the technical solution to be protected by the present invention are described in detail as follows:
[0070] This invention employs a criterion for evaluating model gradients collected from blockchains to base stations. By analyzing and comparing the model gradients of different blockchain nodes, training weights for these nodes are derived. Blockchains leverage their inherent characteristics and a consensus algorithm to achieve behavioral consistency among multiple nodes, thereby ensuring blockchain security and reliability. In this method, each blockchain is pre-assigned an ID value. Within the designed consensus algorithm, if a node ID that has passed the consensus algorithm is found, the model gradient aggregation operation is performed on that node. Aggregation operations are not performed on the remaining nodes. This method ensures the transparency of federated aggregation results while reducing computational overhead for the blockchain.
[0071] At the same time, the framework adopts a distributed federated training framework, which first solves the single point failure problem caused by the attack of the central server in centralized federated learning from the source. This is because the blockchain itself is a distributed framework with the characteristics of openness, transparency and immutability, which can effectively solve the single point failure problem.
[0072] The framework introduces a device management layer, with the base station responsible for receiving data from clients in the device layer under its management. The base station serves as a public platform for collecting local training results from each client. Each client first trains its model using a local data source and uploads the trained model parameters to the base station. The device management layer then performs a preliminary aggregation to obtain the aggregated model gradients trained on each client connected to the device management layer. These trained model gradients are then uploaded to the blockchain node for subsequent node selection. Furthermore, to ensure that the client's model parameters are not known to others, after the initial aggregation at the device management layer, the source of the obtained model parameters cannot be known, thus ensuring data privacy to a certain extent.
[0073] In addition, according to the system consensus algorithm, blockchain nodes with large computing power and better model gradients are comprehensively selected for the final model aggregation operation. While reducing the aggregation time of federated learning, it can also ensure the openness, transparency and accuracy of the federated training results to a certain extent, thereby improving the training effect of federated training.
[0074] Third, as auxiliary evidence for the inventiveness of the claims of the present invention, it is also reflected in the following important aspects:
[0075] (1) The expected benefits and commercial value of the technical solution of the present invention after transformation are:
[0076] 1. Privacy Protection and Data Security: The federated learning framework performs local model training at the device level, avoiding the centralized storage and transmission of raw data, thereby protecting user privacy and data security. This solution is expected to attract privacy-conscious individuals and organizations, providing them with a secure way to collaborate on data.
[0077] 2. Efficient model training: The federated learning framework allows devices to perform model training locally and aggregate it through distributed aggregation at the device management and blockchain layers, ultimately generating a global model. This distributed training approach reduces data transmission and computational complexity, improving training efficiency, especially for large datasets or devices with limited computing power.
[0078] 3. Shared Model Equity: The blockchain-level consensus algorithm and node selection mechanism ensure fairness and equity distribution. Node computing power and model gradients are comprehensively considered to select appropriate blockchain nodes for model aggregation, thus ensuring model accuracy and quality. This solution is likely to attract participants who wish to share model equity and receive fair returns.
[0079] 4. Business Partnership Opportunities: This technical solution may create new business opportunities. For example, the device management layer can provide device management services, supporting client-side model training and uploads; the blockchain layer can provide consensus algorithms and node selection services to ensure the accuracy of model aggregation. These services may become commercial opportunities, generating revenue for all parties involved.
[0080] (2) The technical solution of the present invention fills the technical gap in the industry at home and abroad:
[0081] The uniqueness of this technical solution lies in two aspects: computing power value verification and model gradient scoring:
[0082] First, computing power verification evaluates the computing power of blockchain nodes to select appropriate nodes for model aggregation. This innovation addresses the imbalance in node computing power in the original federated learning framework. By considering node computing power and selecting nodes with higher computing power for the final model aggregation operation, training efficiency and model accuracy can be improved, reducing training time and resource consumption.
[0083] First, computing power verification evaluates the computing power of blockchain nodes to select appropriate nodes for model aggregation. This innovation addresses the imbalance in node computing power in the original federated learning framework. By considering node computing power and selecting nodes with higher computing power for the final model aggregation operation, training efficiency and model accuracy can be improved, reducing training time and resource consumption.
[0084] Overall, this technical solution's innovations in the field of federated learning lie in computing power verification and model gradient scoring. These innovations address the issues of node computing power imbalance and contribution assessment in the original federated learning framework, thereby improving model training efficiency, model quality, and fairness among participants, providing a more reliable and efficient solution for federated learning applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0085] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments of the present invention. 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 these drawings without any creative work.
[0086] Figure 1 This is a flowchart of blockchain distributed federated learning training for connected vehicles provided by an embodiment of the present invention;
[0087] Figure 2 This is a flowchart of local training of each client and uploading to the base station provided by an embodiment of the present invention;
[0088] Figure 3 This is a flowchart of the interaction between a base station and a blockchain node provided by an embodiment of the present invention;
[0089] Figure 4 This is a schematic diagram of the Fisco Bcos environment provided by an embodiment of the present invention;
[0090] Figure 5 This is a schematic diagram of the running time of two processors provided by an embodiment of the present invention, each processor core being 1;
[0091] Figure 6 This is a schematic diagram of the running time of 4 processors provided by an embodiment of the present invention, each processor core is 1;
[0092] Figure 7 The embodiment of the present invention provides Figure 3 This is a schematic diagram of the running time of 8 processors provided by an embodiment of the present invention, each processor core is 1;
[0093] Figure 8 This is a schematic diagram of the running time of 4 processors with 2 cores each provided by an embodiment of the present invention;
[0094] Figure 9 Schematic diagram of the average training loss values of CNN and IID in CIFAR-10 provided by an embodiment of the present invention;
[0095] Figure 10Schematic diagram of the average training loss value in the MLP of CIFAR-10 with IID provided by an embodiment of the present invention;
[0096] Figure 11 Schematic diagram of the average training loss of CNN in MNIST and non-IID according to an embodiment of the present invention;
[0097] Figure 12 Schematic diagram of the average training loss of the MLP in MNIST and non-IID provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0098] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0099] In response to the problems existing in the prior art, the present invention provides a blockchain distributed federated learning method, system, and terminal for connected vehicles. The present invention is described in detail below with reference to the accompanying drawings.
[0100] In response to the problems existing in traditional centralized federated learning, such as higher risk of privacy leakage, high communication costs, high risk of single point failure, and insufficient scalability, the distributed federated learning method proposed in this invention can solve the problem of storage centralization from the source; and by adding a blockchain structure to distributed federated learning and utilizing the decentralization, transparency, and immutability of the blockchain, it can effectively solve the federated aggregation process required in centralized federated learning, including designing a consensus algorithm for the computing power value of blockchain nodes and the quality of model gradients, which can more effectively ensure the security and robustness of federated learning.
[0101] The application principle of the present invention is described in detail below with reference to the accompanying drawings.
[0102] like Figure 1 As shown, the blockchain distributed federated learning framework for connected vehicles provided by the embodiment of the present invention includes the following steps:
[0103] Step 1: Each node in the blockchain network runs a smart contract to determine its own computing power value and assigns a computing power weight to each node based on the computing power value. This is used in the initial stage of final node selection.
[0104] Step 2: Each client receives the training model from the server, performs local model training, and uploads the model gradient obtained from the local training to the base station;
[0105] Step 3: The base station will perform a preliminary aggregation of the local model gradients trained by each device in the group, and upload the aggregation results to the blockchain for public disclosure.
[0106] Step 4: Each node in the blockchain determines the training weights of different nodes by comparing the model gradients. In each round, the node with the highest weight is selected as the leader node for final global aggregation, and the final global aggregation result is broadcast on the blockchain network.
[0107] Preferably, an embodiment of the present invention provides a blockchain distributed federated learning system for connected vehicles, which is divided into three parts: device layer, device management layer, and blockchain layer.
[0108] Device layer: In federated learning, each device is called a client (or client). They own a portion of the dataset and are responsible for performing some model updates. A client is a role in federated learning, typically referring to a terminal device (such as a smartphone, tablet, or sensor) or a computer server. It is responsible for tasks such as storing local data, performing local model updates, and communicating with the central server.
[0109] In this embodiment of the present invention, the device side is also a participant in model training. Several device sides are grouped together to train a global model by uploading locally updated model gradients to the base station. All device sides together constitute the device layer.
[0110] Device Management Layer: In the present invention, there is a base station jointly managed by a group of device terminals, which allows the base station to be trusted by all the device terminals under it. The device management layer is composed of multiple base stations. Each base station receives model gradients from the device terminals. After preliminary aggregation, it can obtain preliminary model gradients specific to each device layer managed by this base station. The purpose of this is to ensure the distribution of federated learning training and avoid the single point of failure problem of server-side attacks. At the same time, the base station serves as a public platform for collecting local training results from each device terminal. Each device terminal uses local data to train the model and uploads the trained model parameters to the base station. The device management layer pre-performs a preliminary aggregation to obtain the aggregated model gradients trained on each device terminal connected to the device management layer. The trained model gradients are then uploaded to the blockchain node for subsequent node selection operations. In order to ensure that the model parameters of the device terminal are not known to others, after the device management layer undergoes preliminary aggregation, the source of the obtained model parameters will be unknown, thereby ensuring data privacy to a certain extent.
[0111] Blockchain layer: The core advantage of blockchain technology is decentralization. By using data encryption, timestamps, distributed consensus, and economic incentives, it can achieve peer-to-peer transactions, coordination, and collaboration based on decentralized credit in a distributed system where nodes do not need to trust each other. This provides a solution to the high cost, low efficiency, and insecure data storage problems commonly found in centralized institutions.
[0112] In this embodiment of the present invention, the blockchain node layer serves as the aggregation and public layer. Leveraging the decentralized, tamper-proof, and transparent nature of blockchain, it ensures verifiability of aggregation and fairness in node elections during federated learning. The blockchain layer primarily implements two functions: computing power verification and the federated aggregation process.
[0113] The following is combined with Figure 2 The application principle of the present invention is further described.
[0114] The embodiment of the present invention describes a specific distributed federated learning training process, in which the participants mainly include: clients 1-12; base stations m, n, o, p; and blockchain nodes A, B, C, D.
[0115] Blockchain nodes A, B, C, and D first need to evaluate their respective computing power values. In this embodiment, this is specifically manifested in that all blockchain nodes run the same smart contract together. Using the blockchain's smart contract, each time a node calls a function, the system will generate a random number and calculate its hash value. If the first three digits of the hash value are 0, it proves that this blockchain node has successfully found the required random number. After that, the contract will update the number of random numbers calculated by this node, encrypt this random number, add the ID value of the node to it, and then store the encrypted random number. Other nodes can obtain the number of random numbers calculated by other nodes by calling a function, and can call a function to obtain the random number encrypted by the node. The node can obtain the random number of other nodes and verify it. If the first three digits of the verified hash random number are 0, it can be proved that the random number found by this node meets the requirements, then the computing power value announced by the node is true, and the four blockchain nodes are given a computing power weight C. A , C B , C C ,C D .
[0116] Each client is responsible for implementing federated learning for local training. The client first obtains a portion of data from the local data set, which is collected or saved by the device itself. The client initializes a machine learning model locally. In this embodiment, each client jointly trains the neural network model. Using local data, the client executes the model training algorithm locally. This includes inputting data into the model, calculating the loss function of the model, calculating the gradient of the model parameters according to the loss function, and then using stochastic gradient descent to update the parameters of the model. The model gradient is then uploaded to each base station. In this embodiment, clients 1-3 upload to base station m, clients 4-6 upload to base station n, clients 7-9 upload to base station o, and clients 10-12 upload to base station p.
[0117] First, the embodiments of the present invention utilize a consensus mechanism to compare the computing power of each blockchain node. Blockchain is a decentralized technology that maintains and verifies data security and reliability by running the same protocol across multiple nodes. Different nodes in a blockchain network may have varying computing power, depending on their hardware, software, and network resources. In a blockchain network, a node's computing power typically refers to its contribution to the consensus algorithm—that is, its contribution to data verification and accounting on the blockchain. Nodes with higher computing power have a higher weight in the consensus algorithm, thus exerting greater influence within the blockchain network. This discrepancy in computing power can lead to an uneven distribution of nodes within the network, necessitating consideration of network fairness and security when designing blockchain systems.
[0118] The specific algorithm is:
[0119]
[0120]
[0121] This algorithm utilizes blockchain smart contracts to implement a consensus-based mechanism for evaluating the computing power of different blockchain nodes. Specifically, each time a node calls the "mine" function, the system generates a random number and calculates its hash value. If the last two digits of the hash value are 0, the node successfully finds the required random number. The contract then updates the number of random numbers calculated by the node, encrypts the random number, adds the node's ID to the hash, and stores the encrypted random number. Other nodes can obtain the number of random numbers calculated by other nodes by calling the getMinedCount function and the encrypted random number of a node by calling the getEncryptedRandomNumber function. A node can obtain the random numbers of other nodes and verify them. If the last two digits of the verified hash value are 0, the node's random number meets the requirements and its reported computing power is authentic. The node is then assigned a computing power weight C.
[0122] Feasibility Analysis: In a blockchain, although each node runs the same smart contract, its random number is different because its local time, random seed, and other factors are different, ensuring the uniqueness of the random number. In addition, the results of each node's operation can be recorded on the blockchain, and other nodes can verify the records to ensure the correctness of the algorithm.
[0123] Second, the present invention adopts a criterion for judging the model gradients collected from the blockchain to the base station, and obtains the training weights of different blockchain nodes by analyzing and comparing the model gradients of different blockchain nodes.
[0124] Blockchains leverage their inherent characteristics and consensus algorithms to achieve consistent behavior among multiple nodes, thereby ensuring the security and reliability of the blockchain. In this invention, each blockchain is pre-assigned an identity value, or ID. Within the designed consensus algorithm, if a node ID that has passed the consensus algorithm is found, the model gradient aggregation operation is performed on that node, while the remaining nodes do not. This approach ensures the transparency of federated aggregation results while reducing the blockchain's computational overhead.
[0125] The following combination Figure 3 The application principle of the present invention is further described.
[0126] When all base stations have collected the model gradients uploaded by each client, they will then perform preliminary model aggregation. The purpose of this is to ensure the distribution of federated learning training and avoid the single point of failure problem of the server being attacked. At the same time, the base station serves as a public platform for collecting the local training results of each device. Each device uses local data to train the model and uploads the training model parameters to the base station. The device management layer will perform a preliminary aggregation in advance to obtain the aggregated model gradients trained on each device connected to the device management layer, and upload the trained model gradients to the blockchain node for subsequent node selection operations. In order to ensure that the model parameters of the device side are not known to others, after the device management layer undergoes preliminary aggregation, the source of the obtained model parameters will not be known, thereby ensuring the privacy of the data to a certain extent.
[0127] In this embodiment, base stations m, n, o, and p collect model gradients from clients 1-12 respectively, and perform preliminary aggregation to obtain the preliminary federated learning model gradient A , gradient B , gradient C , gradient D This invention uses smart contracts to achieve consensus between blockchain nodes. The designed algorithm is as follows:
[0128] First, in the first round, a random node in the blockchain is selected to perform global aggregation using the smart contract’s aggregation algorithm. This ensures that all aggregation processes are publicly available on the chain, thus ensuring the transparency of the aggregation process.
[0129] Starting from the second round, each blockchain node compares the model gradient uploaded by itself with the global model gradient aggregated in the previous round, selects the node with the best training effect as the leader of the next round of aggregation, and aggregates the global model of the next round.
[0130] At the same time, according to the comparison results, each blockchain node is given an aggregate weight w i Note that this weight is not a training weight, but only a weight for evaluating the aggregation leader. The following formula is used to calculate the aggregation weight w i It should also be noted that only blockchain nodes above the global model aggregation threshold are eligible for the final global aggregation of this round.
[0131] In this paper, a calculation formula for the gradient score T of different blockchain node models is designed. The calculation formula for T is as follows:
[0132] Assume that each device management layer calculates the model parameters uploaded by the device in this round and performs preliminary aggregation. In this example, it is assumed that there are four blockchain nodes A, B, C, and D.
[0133] A data → gradient A =(x A ,y A ,z A ),B data → gradient B =(x B ,y B ,z B )
[0134] C data → gradient C =(x C ,y C ,z C ),D data → gradient D =(x D ,y D ,z D )
[0135] The model gradient collected from A, B, C, and D to the device management layer is gradient A ,gradient B ,gradient C ,gradient D .
[0136] Each blockchain node uses the model aggregation algorithm in the smart contract to aggregate the preliminary model gradients uploaded by all nodes to obtain a new model gradient g , and make it public
[0137] gradient g =AVG(gradient A ,gradient B ,gradient C ,gradient D )
[0138] Compare the local model gradient of each blockchain node with the aggregated global model gradient result to obtain the model gradient difference θ:
[0139] θ A =cos(gradient g ,gradient A ),θ B =cos(gradient g ,gradient B )
[0140] θ C =cos(gradient g ,gradient C ),θ D =cos(gradient g ,gradient D )
[0141] Since the model gradient difference θ ranges from [-1, 1], in order to normalize it, the model mean is defined as:
[0142]
[0143] Define the model gradient mean as Only device management terminals whose model gradients are above the threshold are eligible for model aggregation.
[0144] The final node is selected to meet the model aggregation result above the threshold and the node with the largest computing power weight. The training weight calculation formula w i The final result is as follows:
[0145]
[0146] Select w i The largest node runs the final global aggregation model of this round,
[0147] ifselectId=blockId{
[0148] modelAVG(gradient_{A}, gradient_{B}, gradient_{C}, gradient_{D});
[0149] }else{
[0150] return null;
[0151] The final global aggregation result of this round is obtained and broadcast to all nodes in the blockchain node. It is then distributed to all clients. All clients accept the global aggregation model of the previous round and prepare for the next round of local training. This completes the training process of this round.
[0152] In order to prove the creativity and technical value of the technical solution of the present invention, this section provides application examples of the claimed technical solution on specific products or related technologies.
[0153] An application embodiment of the present invention provides a computer device, which includes a memory and a processor. The memory stores a computer program. When the computer program is executed by the processor, the processor executes the steps of the blockchain distributed federated learning method for connected vehicles.
[0154] An application embodiment of the present invention provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the processor executes the steps of the blockchain distributed federated learning method for connected vehicles.
[0155] An application embodiment of the present invention provides an information data processing terminal, which is used to implement the blockchain distributed federated learning system for connected vehicles.
[0156] 1. Fisco Bcos environment construction, such as Figure 4 As shown;
[0157] 2. Consensus algorithm simulation
[0158] By using the consensus algorithm designed in this invention and implementing it with blockchain smart contracts, we have preliminarily completed a simulation evaluation of different blockchain node computing power values. In the experiment, we indirectly modified the computer computing power by changing the number of computer processors and the number of cores inside the processor, thereby simulating the time it takes for blockchain nodes with different computing power values to run smart contracts. Figure 5-Figure 8 As shown;
[0159] As can be seen in the simulation experiment, when blockchain nodes have different computing power values, each node independently executes the code in the smart contract during the simulation and broadcasts the results to other nodes in the network for confirmation. Due to differences in network latency, computing power, and load between nodes, the runtime of the same smart contract on different nodes may vary.
[0160] 3. Federated Learning Simulation
[0161] Implement the FedAVG federated average algorithm, understand the specific federated training process and the final federated aggregation process, integrate the federated learning framework with the blockchain, and use it as a comparative experiment. Figures 9-12 As shown;
[0162] The loss_train variable stores the average loss value for each training round. In federated learning, each training round updates the global model parameters through local training on each participant (client). Each participant calculates the loss during training and passes it to the server for aggregation and global model update. The above shows how the average loss values vary across different training models and datasets, even with the same number of iterations.
[0163] It should be noted that the embodiments of the present invention can be implemented by hardware, software, or a combination of software and hardware. The hardware portion can be implemented using dedicated logic; the software portion can be stored in a memory and executed by an appropriate instruction execution system, such as a microprocessor or dedicated design hardware. Those skilled in the art will appreciate that the above-mentioned devices and methods can be implemented using computer-executable instructions and / or contained in processor control code, for example, such as a carrier medium such as a disk, CD or DVD-ROM, a programmable memory such as a read-only memory (firmware), or a data carrier such as an optical or electronic signal carrier. The devices and modules of the present invention can be implemented by hardware circuits such as very large-scale integrated circuits or gate arrays, semiconductors such as logic chips, transistors, or programmable hardware devices such as field programmable gate arrays, programmable logic devices, etc., can also be implemented by software executed by various types of processors, or can be implemented by a combination of the above-mentioned hardware circuits and software, such as firmware.
[0164] The above description is only a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any modifications, equivalent substitutions and improvements made by any technician familiar with this technical field within the technical scope disclosed by the present invention and within the spirit and principles of the present invention should be covered by the scope of protection of the present invention.
Claims
1. A blockchain distributed federated learning method for connected cars, characterized by: The blockchain-based distributed federated learning method for connected vehicles is based on a distributed federated learning framework based on blockchain. Through a hierarchical structure, the framework is refined into three layers: the device layer, the device management layer, and the blockchain layer. The device layer's main function is for the client to receive the global model, perform local model training, and upload the local model gradient to the base station at the device management layer. The device management layer is responsible for receiving the model gradients of the managed clients and performing preliminary aggregation to obtain a preliminary aggregated model. Finally, the blockchain layer performs the final global aggregation, adopting a blockchain consensus algorithm to select blockchain nodes for aggregation operations. The consensus algorithm uses a multi-selection mechanism. First, the computing power of each blockchain node is evaluated. Second, the model gradients of different device management layers are evaluated, and the blockchain node with the higher model gradient is selected for the final model aggregation. Finally, the blockchain computing power and model gradient are comprehensively considered to select the blockchain node leader in this round for the final model aggregation. The blockchain distributed federated learning method for connected vehicles specifically includes: Step 1: Each node in the blockchain network runs a smart contract to determine its own computing power value and assigns a computing power weight to each node based on the computing power value. This is used in the initial stage of final node selection. Step 2: Each client receives the training model from the server, performs local model training, and uploads the model gradient obtained from the local training to the base station; Step 3: The base station will perform a preliminary aggregation of the local model gradients trained by each device in the group, and upload the aggregation results to the blockchain for public disclosure; Step 4: Each node in the blockchain determines the training weights of different nodes by comparing the model gradients. In each round, the node with the highest weight is selected as the leader node for final global aggregation, and the final global aggregation result is broadcast on the blockchain network.
2. The blockchain distributed federated learning method for connected vehicles according to claim 1, characterized in that: The blockchain distributed federated learning method for connected vehicles uses a consensus mechanism to compare the computing power values of each blockchain node, and maintains and verifies the security and reliability of data by running the same protocol on multiple nodes. Different nodes in the blockchain network may have different computing power values. In a blockchain network, nodes with higher computing power values have higher weights in the consensus algorithm and greater influence in the blockchain network. The difference in computing power values of different nodes will lead to uneven distribution of nodes in the network.
3. The blockchain distributed federated learning method for connected vehicles according to claim 1, characterized in that: The blockchain-based distributed federated learning method for connected vehicles uses blockchain smart contracts to implement a consensus mechanism for evaluating the computing power of different nodes in the blockchain. Specifically, the algorithm uses blockchain smart contracts to generate a random number and calculate its hash value each time a node calls the mine function. If the first three digits of the hash value are 0, the blockchain node successfully finds the required random number; After that, the contract updates the random number calculated by this node, encrypts the random number, adds the node's ID value to it, and then stores the encrypted random number; Other nodes can obtain the number of random numbers calculated by other nodes by calling the getMinedCount function, and can call the getEncryptedRandomNumber function to obtain the random number encrypted by the node; the node can obtain the random number of other nodes and verify it. If the first three digits of the verified hash random number are 0, the random number found by this node meets the requirements, the computing power value announced by the node is true, and it is assigned a computing power weight.
4. The blockchain distributed federated learning method for connected vehicles according to claim 1, characterized in that: The blockchain distributed federated learning method for connected vehicles uses smart contracts to achieve consensus among blockchain nodes. The designed algorithm specifically includes: In the first round, any node in the blockchain is randomly selected to perform global aggregation using the aggregation algorithm of the smart contract. This ensures that all aggregation processes are public on the chain, thus ensuring the transparency of the aggregation process. Starting from the second round, each blockchain node compares its uploaded model gradient with the global model gradient aggregated in the previous round, selects the node with the best training effect as the leader of the next round of aggregation, and aggregates the global model of the next round; At the same time, based on the comparison results, each blockchain node is assigned an aggregation weight. Note that this weight is not a training weight, but only serves as the evaluation weight of the aggregation leader. At the same time, only blockchain nodes above the global model aggregation threshold are eligible for the final global aggregation of this round. Each device management layer calculates the model parameters uploaded by the device in this round and performs preliminary aggregation. There are four blockchain nodes A, B, C, and D: A data →gradient A =(x A ,y A ,z A ),B data →gradient B =(x B ,y B ,z B ); C data →gradient C =(x C ,y C ,z C ),D data →gradient D =(x D ,y D ,z D ); The model gradient of the device management layer collected by A, B, C, and D is gradient A , gradient B ,gradient C ,gradient D ; Each blockchain node uses the model aggregation algorithm in the smart contract to aggregate the preliminary model gradients uploaded by all nodes to obtain a new model gradient g , and publicly: gradient g =AVG(gradient A ,gradient B ,gradient C ,gradient D ); Compare the local model gradient of each blockchain node with the aggregated global model gradient result to obtain the model gradient difference θ: θ A =cos(gradient g ,gradient A ),θ B =cos(gradient g ,gradient B ); θ C =cos(gradient g ,gradient C ),θ D =cos(gradient g ,gradient D ); Since the model gradient difference θ ranges from [-1,1], the model mean is defined as Normalize it; define its model gradient mean as Only the device management end with the model gradient above the threshold is eligible for model aggregation; the final node is selected as the node with the largest computing power weight that satisfies the model aggregation result above the threshold, and the training weight calculation formula is w i for:
5. A blockchain distributed federated learning system for connected vehicles that applies the blockchain distributed federated learning method for connected vehicles as described in any one of claims 1 to 4, the blockchain distributed federated learning system for connected vehicles comprising: Device layer: In federated learning, each device is called a device or client, which owns a portion of the dataset and is responsible for performing some model update operations; The device side is a role in federated learning, usually referring to some terminal devices or computer servers, used for tasks such as storing local data, performing local model update operations, and communicating with the central server; Device management layer: There is a base station managed by a group of devices, so that the base station can be trusted by all the devices under it; The device management layer is composed of multiple base stations. Each base station receives model gradients from the device side. After preliminary aggregation, it can obtain a preliminary model gradient specific to each device layer managed by this base station. The base station serves as a public platform for collecting local training results of each device side. Each device side uses local data to train the model and uploads the trained model parameters to the base station. The device management layer performs a preliminary aggregation in advance to obtain the aggregated model gradients trained on each device side connected to the device management layer. The trained model gradients are then uploaded to the blockchain node for subsequent node selection operations. After the device management layer undergoes preliminary aggregation, the source of the obtained model parameters will no longer be known. Blockchain layer: It can realize peer-to-peer transactions, coordination and collaboration based on decentralized credit in a distributed system where nodes do not need to trust each other by using data encryption, timestamps, distributed consensus and economic incentives.
6. The blockchain distributed federated learning system for connected vehicles according to claim 5, characterized in that: The device side is also a participant in model training. Several devices work together as a group to train a global model by uploading the locally updated model gradients to the base station. All devices together form the device layer. The blockchain node layer serves as an aggregation and public layer. By leveraging the decentralized, tamper-proof, and transparent nature of blockchain, it can ensure the verifiability of aggregation during federated learning and the fairness of node elections. The functions that the blockchain layer needs to implement are mainly reflected in two aspects, namely computing power value verification and federal aggregation process.
7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the blockchain distributed federated learning method for connected vehicles as described in any one of claims 1 to 4.
8. A computer-readable storage medium storing a computer program, which, when executed by a processor, causes the processor to perform the steps of the blockchain distributed federated learning method for connected vehicles as described in any one of claims 1 to 4.
9. An information data processing terminal, which is used to implement the steps of the blockchain distributed federated learning method for connected vehicles as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Federal learning method based on fog calculation
CN113379066A
Federal learning member reasoning attack defense method and device based on block chain decentration
CN113467928A