# Deep Contrastive Learning-Based Model for ECG Biometrics
## 2 Materials and Methods
### Proposed Method
#### 2.2.1 Features Extraction Backbone  
In the features extraction block (see Figure 4), we aim to extract rich discriminative features that highly represent the input ECG signals. It is well known that pre-trained CNN architectures provide very effective deep feature representations. Although these architectures are designed to work for images, it is possible to convert the 1D ECG signal into an image [2; 33].  
Given an input of a raw ECG heartbeat signal or time series, the backbone feature extraction block first converts the 1D ECG signal into 2D images, using the STFT operation followed a set of convolutional layers. Given a subject \(i\), the conversion sub-block takes as input the time-series ECG signals of dimension \(n_{i}\times 740\), where \(n_{i}\) represents the number of heartbeats for the \(i\)th subject while 740 is the length of the heartbeat. Then, we randomly select five beats from the \(n_{i}\) beats to create an input with a fixed size of \(5\times 740\). We apply the STFT on the \(5\times 740\) signal to generate a spectral image by extracting the time-frequency spectrogram and then paspassing through trainable convolutional layers. As a result, the conversion sub-block inputs a signal with size \(5\times 740\) and outputs an image of size \(3\times 32\times 32\).  
The second sub-block is a pre-trained EfficientNet module used to extract highly discriminative features. One of the key features of EfficientNet model is that it performs scaling in all three dimensions (depth, width, and image resolution) in a principled way [34]. The authors of EfficientNet demonstrated that scaling ConvNets in one of the three dimensions (depth, width, or image resolution) leads to the saturation of the network's gain as the network gets bigger. In order to overcome this, they proposed a compound scaling mechanism that uniformly scales the three dimensions of the network using fixed scaling coefficients. Additionally, they confirmed the significance of balancing a network in all dimensions by proposing the baseline network EfficientNet-B0 and scaling up this baseline network to get other EfficientNets variants (i.e., B1-B7). These architectures significantly beat other ConvNet architectures on the ImageNet classification while reducing the number of trainable parameters and inference time, which are important properties for real-time applications such as biometric systems. Furthermore, these models can learn features that are transferable and can achieve remarkable results on a variety of image classification problems.  
Figure 4: The feature extraction backbone, which is composed of two sub-blocks, 1D ECG signal to 2D image conversion block and 2D feature map generation block.  
Figure 5 shows the mobile inverted bottleneck layer, which is the main building block used in EfficientNet-B0. This layer is composed of an inverted residual block combined with squeeze-and-excitation (SE) blocks. The input feature map is projected into higher dimensional space using the inverted residual, then a depth-wise convolution operation is applied in the new space. Then, a point-wise convolution (\(1\times 1\) convolution) operation with linear activation is applied to project back the new feature map to a low dimensional space. In the end, a residual connection from the input is added to the output of the point-wise convolution, which generates an output feature map. The model learns the weights of the channels of a feature map using the SE blocks. In the SE block, the input feature map is converted to a feature vector of size c (the number of channels) and then it is fed to two consecutive FC layers. Later, the output of FC layers, which is a vector of size c, is used to scale the channels according to their importance. Moreover, other aspects were considered while designing the baseline network by taking into account accuracy and real-world latency on mobile devices. By applying a compound scaling to the baseline network, a family of seven EfficientNet models was generated (EfficientNet-B1 to B7).