# Enhancing Smart City Safety and Utilizing AI Expert Systems for Violence Detection
## 2 Methodology
### Violence Object Detection Model (YOLO v7)  
In the above section, we showed how synthetic images and previous images are associated and how we created new datasets that were used in the violence detection model (YOLO v7) as shown in Figure 1. This is a one-stage detector abbreviated as \"You Only Look Once\". YOLO v7 [34; 35] is an object detection method in computer vision designed to address various challenges in real-time image processing. This algorithm maintains high accuracy during the real-time processing speed of 5 to 160 frames per second (FPS) and is the latest detection technique of this era that is highly in demand for using various kinds of solutions [36; 37]. Here, we are solving the problem of citizen safety in cities. In this research work, YOLO v7 is used to detect three kinds of objects: baseball bats, pistols, and knives, which are used here as violent object detection model training. The architecture of YOLO v7 is mainly divided into four subsections as follows:  
* **Input:** This is the initial stage of this model in which input comprising violent images is provided to an algorithm with the images' corresponding annotations; the size of each input image is 416 \(\times\) 416 and the images are RGB images that provide their output to the next backbone layer architecture.
* **Backbone:** The backbone layer networks are processed after input images and mainly comprise three subsections of these modules: MPI module, E-ELAN, and CBS. The MPI model is a combination of CBS processes and MaxPool, with bottom and top branches. The MaxPool model is at the top branches and is utilized to decrease the image's size in bisection, in both length and width. A CBS process with 128 channel outputs is also utilized to minimize the channel of image sum by fifty per cent and conversely CBS process with a stride and 1 \(\times\) 1 kernel divides the channels in half numbers. Afterwards, another 2 \(\times\) 2 stride and 3 \(\times\) 3 kernel CBS process divide the image dimension in half. Concatenation (Cat) is employed to incorporate the extracted features from that pair of branches. CBS handles the collection of the data from small-scale areas and MaxPool collects from localized locations. The integration techniques of the network raise the capacity to extract useful features from input images.  
\begin{table}
\begin{tabular}{c c} \hline \hline
**Class Label** & **Number of Images (Real + Generated)** \\ \hline Baseball bat & 700 + 300 \\ Gun & 700 + 300 \\ Knife & 700 + 300 \\ Total & 3000 \\ Training size & 2100 (70\%) \\ Validation size & 900 (30\%) \\ \hline \hline \end{tabular}
\end{table}
Table 1: Dataset.  
Figure 2: Generated synthetic image samples of image-to-image stable diffusion.  
* **Neck:** This section of YOLO layer architecture consists of FPN structure (stands for feature pyramid network structure) that employs PAN design structure. The network is composed of many convolutional networks, SiLU activation (CBS Block), and Batch normalization along with spatial pyramid pooling (SPP) and the convolutional spatial pyramid (CSP) that improves outcomes of layers, and this network structure extends Maxpool2 (MP2) and efficient layer aggregation network (ELAN). The number of output channels is always the same in both the MP blocks--the output of this neck layer network transfers to the next prediction module.
* **Prediction:** The prediction stage is the final stage of this detection algorithm and has a couple of rep structures. The confidence, anchor, and category are evaluated or predicted using a \(1\times 1\) convolutional layer. The inspiration for this kind of rep structure is VGG or Darknet, which decreases the model complexity without reducing its prediction performance. For training this model, the main specifications are mentioned as follows: CPU was Intel(R) Core (TM) i7-9700k speed @ 3.60 Hz, installed RAM was 16 GB, and graphics card was NVIDIA GeForce RTX 2080 Ti.