# TDLearning: Trusted Distributed Collaborative Learning Based on Blockchain Smart Contracts
## 3 Method
### Model-Fusion Method Based on Feature Fusion  
Based on the above blockchain smart contract collaboration architecture and transfer learning [31], we propose a model-fusion method based on feature fusion to enable collaborative model training to aggregate dispersed data resources. The method consists of the following two steps:  
1. Submodel pretraining: data node \(i\) (_i_\(\in\) [1, _n_]) develops a pretrained model \(i\) by using its local data. Model fusion and fine tuning: The task-publishing node uses its local data to perform parallel-feature extraction from \(n\) pretrained submodels and then uses an attention mechanism to fuse the extracted features from the submodels to generate global features, which are finally used as the input to the classifier to obtain the global model. Figure 5 depicts the global-model-development process for the collaborative-learning mechanism proposed in this paper, with steps 5 and 8 corresponding to the submodel pretraining, model fusion and fine-tuning steps, respectively. Figure 6 illustrates the model-fusion architecture. As shown in this architecture, in order to develop a global model, features from all pretrained submodels need to be integrated to generate global features. Define the global model input as \(x\), the \(i\)th submodel feature extraction layer as a function \(f_{i}\), \(E_{i}\) as the features extracted by submodel \(i\), \(F\) as the feature-fusion operator and \(V\) as the global features. Then, the attention-based feature-fusion process can be formulated by Equations (10) and (11), where \(E_{i}\in\mathbb{R}^{\mathbb{C}\times H\times W}\), \(E\in\mathbb{R}^{n\times C\times H\times W}\) and \(V\in\mathbb{R}^{\mathbb{C}\times H\times W}\). \[\left\{ \begin{aligned} E_{i}=f_{i}(x)\\ E=F_{concat}(E_{1},E_{2},...,E_{n})\end{aligned} \right. \tag{10}\]  
\[V=F_{attention}\big{(}E,f_{1}(x),f_{2}(x),...,f_{n}(x)\big{)} \tag{11}\]  
To elaborate on \(F_{attention}\), \(n\) is taken to be 3, i.e., 3 pretrained submodels are fused, as shown in the corresponding framework for the Attention Layer in Figure 6. Naturally, the present architecture can also be very easily extended to scenarios where \(n\) is greater than 3. The merged feature map \(E\) contains feature information extracted from all submodels, and the global feature information is embedded in the vector \(T\) (\(T\in\mathbb{R}^{\mathbb{C}\times 1\times 1}\)) by using global average pooling, as shown in Equation (12). After the above steps are completed, the vector \(T\) is fed to the fully connected layer \(fc\), which adaptively fuses the features further. In addition, to reduce the model computation, the number of fc neurons is set to \(d\) (\(d\leq C\)):  
\[T=AvgPool(E)=\frac{\sum_{i=1}^{H}\sum_{j=1}^{W}E(i,j)}{H\times W} \tag{12}\]  
\[D=fc(T) \tag{13}\]  
The global feature information is further extracted by vector \(D\). Subsequently, a soft attention mechanism is introduced in order to calculate the fusion weights of the features extracted by the different submodels. Corresponding to the three pretrained submodels, the fully connected layer \(fc\) connects each of the three fully connected layers, i.e., the three branches of the model: \(fc\_1\), \(fc\_2\), \(fc\_3\). Finally, the output vectors of the different fully connected layers are used to calculate the fusion weights of the features extracted by the different submodels. Figure 5: The process of collaborative training of the model based on blockchain. connected layers are normalised by the softmax function to generate the feature attention vectors \(w1\), \(w2\) and \(w3\).