# Towards an Indoor Gunshot Detection and Notification System Using Deep Learning
## 3 Materials and Methods
### A Deep Learning Model for Gunshot Detection
#### 3.1.3 Convolutional Neural Network Architecture  
Several iterations are made to find a model that can fit the dataset well and also has sufficient capacity (i.e., parameters) to avoid overfitting. To find the right model capacity, first training is performed using a model with large parameters. The batch size is set as large as possible until memory issues are reported. Then, gradually the model capacity is reduced until fitting becomes difficult. The learning rate and learning rate decay parameters were reduced when the validation loss was not decreasing for a long-time during training. Finally, a deep learning model, as shown in Figure 3, is used to classify the sound as gunshot or as other. In this project, we convert the sounds to images as discussed in Section 3.1.2, and shown in Figure 2. The one-dimensional time-domain sound samples are converted to two-dimensional frequency domain MFCC image representation. These MFCC images are used as input of the deep-learning-based classifier to classify the MFCC images, which are actually representations of sounds. The different layers and the optimizer of the model are briefly described below. * MFCC Input Image: The MFCC image is structured as a tensor with dimensions of (32, 32, 1). To ensure compatibility with deep learning models, the pixel data type undergoes conversion to a floating-point format. For the purpose of pixel value normalization, we calculate and store the mean and standard deviation of the training dataset in a separate file. Subsequently, each pixel value in all dataset images is normalized by subtracting the mean and dividing by the standard deviation. * The Convolutional Layer: A 2-D convolutional layer applies sliding convolutional filters to the input data. It conducts convolution by sliding these filters along both the vertical and horizontal axes, computing the dot product between the weights and input, and then adding a bias term [39]. The proposed model incorporates two convolutional layers, each utilizing 3 \(\times\) 3 filters. These filters are initialized with random values and function as learnable network parameters. For example, in Figure 3, the conv2d layer comprises 2 filters, each sized 3 \(\times\) 3 with padding, resulting in 2 output layers having the same height and width as the input layer. Similarly, the conv2d_1 layer includes 2 filters, each sized 3 \(\times\) 3 with padding. * The Activation Layer: Non-linear activation functions, specifically the rectified linear unit (ReLU) [40], are applied after the convolutional and dense layers (except the last dense layer). The ReLU layer performs a threshold operation on each element, setting any value less than zero to zero. This activation function introduces non-linearity into the network, enabling it to capture intricate patterns and enhance its classification performance. * The Max Pooling Layer: This layer conducts down-sampling by partitioning. Here, the input is divided into 2 \(\times\) 2 size rectangular regions and the maximum number from each region is sampled [41]. * The Flatten Layer: The spatial dimensions of the input are collapsed here, and it converts it into a one-dimensional vector. It transforms the input tensor having dimensions of (8, 8, 1) into a 64 size single-dimensional vector. * The Dense Layer: The dot product between the input and a weight matrix is computed in this layer. Following this, a bias vector is added to the result [42; 43]. Random values are used to initialize both the weight matrix and bias, and they deserve as learnable parameters of the model. This layer is also known as the fully connected (FC) layer. * Loss Function and Optimizer: The last fully connected layer, dense_2, integrates the extracted features for image classification. Consequently, the last dense layer output size is set to one for binary classification. Then a score function, Sigmoid [44], is used. The agreement between predicted scores and the ground truth labels are quantified by the loss function.