# Effective Strategies for Enhancing Real-Time Weapons Detection in Industry
## 3 Materials and Methods
### Scale Match  
When dealing with CCTV systems, where cameras are typically installed at a considerable height, weapons may exhibit a reduced aspect ratio. The utilisation of most public datasets might not be suitable, as the majority of images feature weapons in the foreground, deviating from real-world scenarios. Although [PERSON] et al. [1] contributed to the development of a CCTV-based dataset, it might not be adequate. Therefore, the public datasets outlined in Section 3.1 are employed.  
A notable challenge arises from the fact that, since most images depict weapons in close proximity to the camera lens, the detector's ability to recognise smaller weapons may be compromised without appropriate adjustments. [PERSON] et al. [27] introduced an approach called Scale Match to enhance the accuracy of detectors in detecting small objects by addressing the scale mismatch between the pre-training dataset and the TinyPerson dataset. This approach involves taking a target dataset \(D\) and an additional dataset \(E\). By sampling the size distribution of both datasets, denoted as \(P_{size}(D)\) and \(P_{size}(E)\), respectively, the method  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Dataset** & **Class** & **No. of Images** & **No. of Instances** & **\% of Low-Ambient-Light** \\ \hline \multirow{2}{*}{FP-Dataset} & Gun & - & - & 0.0 \\  & Others & 36,000 & - & \\ \multirow{2}{*}{Disarm-Dataset} & Gun & 60,081 & 64,994 & \\  & Others & 2650 & - & \\ \hline \hline \end{tabular}
\end{table}
Table 2: _Cont._  
\begin{table}
\begin{tabular}{c c c c} \hline \hline
**Model** & **Input Size** & \
\begin{tabular}{c} **N\({}^{\circ}\)** \\ **Parameters** \\ **(M)** \\ \end{tabular} &
\begin{tabular}{c} **Inference** \\ **Time** \\ **(ms)** \\ \end{tabular} \\ \hline YOLOv5s & 640 & 7.2 & 6.4 \\ YOLOv5m & 640 & 21.2 & 8.2 \\ YOLOv5l & 640 & 46.5 & 10.1 \\ YOLOv5x & 640 & 86.7 & 12.1 \\ YOLOv7 & 640 & 36.9 & 6.21 \\ YOLOv7-X & 640 & 71.3 & 8.77 \\ YOLOv7-W6 & 1280 & 70.4 & 11.9 \\ YOLOv7-E6 & 1280 & 97.2 & 17.85 \\ YOLOv7-D6 & 1280 & 154.7 & 22.72 \\ YOLOv7-E6E & 1280 & 151.7 & 27.77 \\ YOLOv8n & 640 & 3.2 & 0.99 \\ YOLOv8s & 640 & 11.2 & 1.20 \\ YOLOv8m & 640 & 25.9 & 1.83 \\ YOLOv8l & 640 & 43.7 & 2.39 \\ YOLOv8x & 640 & 68.2 & 3.53 \\ \hline \hline \end{tabular}
\end{table}
Table 3: Overview of YOLO models (retrieved from the official website of each version). It should be noted that, in both YOLOv5 and YOLOv7, the authors used an NVIDIA v100 for training, while in YOLOv8, they used an Amazon instance (EC2 P4d), which uses an NVIDIA A100.  
transforms the size distribution of the additional dataset to align with that of the target dataset, as illustrated below:  
\[P_{size}(T(E))\approx P_{size}(D) \tag{1}\]  
where \(T\) is the scale transform. Initially, one could scale solely the bounding boxes of the images, although this would compromise the image's composition. Therefore, the complete image is resized by taking the average of the objects in the picture equal to the size of \(s\). This study utilises a variation that applies a monotone function introduced by [PERSON] et al. (Monotone Scale Match) to prevent extreme cases where a very tiny object can generate an exceedingly large image or vice versa. The method is as follows. First, \(P_{size}(D)\) and \(P_{size}(E)\) are estimated with a rectified histogram. Then, for each bounding box in \(E\), the mean size of its bounding boxes \(\hat{s}\) is calculated. Subsequently, a random sample size \(s\) is drawn from D, and the image is resized using a monotonic function to reach an average size of \(s\). Furthermore, another method was devised in which, instead of up-scaling or down-scaling the images, the bounding box of the object is obtained and then re-scaled and pasted into another image with no weapons. In Section 4.2.2, the experiments executed will determine whether the use of Scale Match is advantageous for this particular case and which method fits the best.