# Hybrid-Margin Softmax for the Detection of Trademark Image Similarity
###### Abstract
Another research idea in metric learning is loss-driven training methods such as recent works on face recognition (FR) [14; 15]. Instead of building a large-scale dataset for training, these metric learning methods transformed the softmax function to conduct a margin penalty on the decision boundary, aiming to develop the discrimination ability of SNNs. The typical SphereFace [16], CosFace [17; 18], and ArcFace [19] are all designed to expand intraclass space and reduce interclass space. Some of the reasons are that the performance of a data-driven model relies on the quality of information contained in training data excessively, and manual annotation is a major expenditure of human efforts. Furthermore, the SNN trained on close-set data shows bad performance in generalizing on open-set data [19]. More specifically, for the TMISD task, [PERSON] proposed a TM similarity analysis system to conduct the 'likelihood of confusion' test with three models [20]. Global and local shape feature descriptors, i.e., Zernike moment and an edge gradient co-occurrence matrix are used to extract TM image features. Euclidean distance is used to compute similarity. On this basis, [PERSON] introduced SNNs into the feature extraction of TM images [21]. VGG16 is used to build an SNN. [PERSON] used pre-trained CNNs to build an SNN including VGG16 and ResNet50 [22]. Most of these works focused on data-driven metric learning methods. However, the training database encounters a great challenge of annotation and covering the rapid growth in new TM designs. We choose to research the TMISD task from the perspective of a loss-driven metric learning method. Here is a brief introduction to the frequently used loss function, i.e., the softmax function in the classification. The expression of softmax is as follows:  
\[L_{1}=-\frac{1}{N}\sum\limits_{i=1}^{N}\log\frac{e^{W_{x_{i}}^{T}x_{i}+y_{i}}}{ \sum\limits_{j=1}^{n}e^{W_{x_{i}}^{T}x_{i}+b_{j}}} \tag{1}\]  
where \(N\) is the class number, \(W\) and \(b\) are weight and bias terms, \(x_{i}\) is the embedded feature vector belonging to the \(y_{i}\)-th class, and \(W_{j}\) is the \(j\)-th column of the weight \(W\). Then, by fixing the weight \(\|W\|=1\) and feature \(\|x_{i}\|=1\) by \(\ell_{2}\) normalization, and by fixing the bias \(b_{j}=0\), the decision boundary is transferred to the angular space. The transformed softmax function is as follows:  
\[L_{2}=-\frac{1}{N}\sum\limits_{i=1}^{N}\log\frac{e^{\cos\theta_{y_{i}}}}{e^{ \cos\theta_{y_{i}}}+\sum\limits_{j=1,j\
eq y_{i}}^{n}e^{\cos\theta_{j}}} \tag{2}\]  
where \(\theta\) is the included angle between the normalized weight and feature vector. The prediction will depend only on the angle, and the decision boundary can be optimized by margin penalties. The main contributions of this study are as follows:  
1. We researched the TMISD task with prevalent methods in metric learning including data-driven and loss-driven. The performance of these methods was investigated from several evaluation aspects regarding the TMISD task, including accuracy, F1 score, training cost, and generalization ability. 2. According to the peculiarity of TM images, a hybrid-margin softmax (HMS) is proposed. Two additive margins are attached to the cosine term and the angular term of softmax, respectively, to expand the decision boundary in the angular space. The magnitudes of the weight and feature vector are preserved to retain the input information as much as possible. The metric function used to calculate the similarity is replaced by a classifier, i.e., a fully connected layer. 3. Experiments indicate that the detection model penalized by HMS can be trained on small numbers of annotated data and reaches high detection accuracy with fewer layers of SNN. Furthermore, the HMS detection model trained completely on TM data generalizes well on the face recognition (FR) task, which indicates that the model trained on HMS has great input image discrimination ability.