# A Deep Similarity Metric Method Based on Incomplete Data for Traffic Anomaly Detection in IoT
## 3 Methodology
### Channel Attention Model for Siamese Architecture
The word vector \(W^{l}\) is a one-dimensional vector generated from a dictionary. Dictionaries of different hierarchies are randomly generated, and each dictionary has several row vectors, the number of which is the same as the number of categories defined for the anomaly objects. The dictionary is generic, it will be used together in both training and testing stages. Once the dictionaries are initialized, the values in it are determined and will not change again. The proposed model has four dictionaries for word embedding. In the training stage, when the inputs of the two branches are the same category, the word vectors are consistent with the image categories. When the inputs of the two branches are different categories, the word vectors are consistent with the image category of one branch. In the testing stage, one input of the network is a template image block and the other is an image block to be detected. The word vectors are consistent with the category of the template image block. The lengths of vectors in the dictionary are the same as the number of channels in the corresponding level feature map for subsequent channel-attentions calculations. The weight \(W^{l}_{k}\) is the \(k^{\prime}\)th value of the word vector corresponding to the \(k^{\prime}\)th feature map in raw features \(R\) after each block. Then, the attentional map can be calculated as:  
\[Att^{l}=\sigma\Big{(}CONV_{3\times 3}\left(W^{l}\oplus R1^{l}\oplus R2^{l} \right)\Big{)} \tag{2}\]  
The symbol \(\oplus\) denotes the element-wise summation. The summation of \(R1^{l}\) and \(R2^{l}\) represents the feature fusion of the two branches. The add \(\circ l^{\prime}\)th f \(W^{l}\) and \(R^{l}\) can be implemented as the summation of \(W^{l}_{k}\) and each element of \(R^{l}_{i,j,k^{\prime}},i\in[0,w-1],j\in[0,h-1]\), indicating that the word feature is embedded in the fused features. A \(3\times 3\) convolution is employed after these operations, meaning that each element \(Att^{l}_{i,j}\) on the map is generated from the \(3\times 3\times C\) neighbourhood pixels of the feature at the same location \((i,j)\) on \(R^{l}\). The values on the attention map reflect the influence power of the fusion feature to the contribution of prediction in the adjacent area. \(\sigma\) is the sigmoid activation function, it maps all the values to \([0,1]\). After that, the attentional features can be calculated as:  
\[Ratt1^{l}=R1^{l}\otimes Att^{l},Ratt2^{l}=R2^{l}\otimes Att^{l} \tag{3}\]  
The symbol \(\otimes\) denotes the element-wise multiplication, which can be implemented as the multiplication of \(Att^{l}_{i,j}\) and each element of \(R^{l}_{i,j,k^{\prime}},k\in[0,C-1]\). It indicates that the raw features are filtered by the attention map. Information that is useful for classification and discrimination is  
Figure 4: Architecture of multiresolution attention model. A word vector is embedded in the fused features of two branches for the generation of the shared attention map. Then, soft attention is implemented for both branches with the shared attention map. The same process is performed after each block. preserved, while useless information is suppressed. It is worth mentioning that the attention map is shared for both branches, and the areas that the model pays attention to are the same at each hierarchy. The parameters, kernel size, kernel stride and the feature dimensions of our deep similarity metric model have been illustrated in Table 1.