# Improving Moving Insect Detection with Difference of Features Maps in YOLO Architecture
## 2 Materials and Methods
### Method  
Insets in natural environments can be small, camouflaged or partially occluded, making them difficult to detect. To enhance detection performance in real-world conditions, we extend the conventional still-image object detection framework by incorporating an adjacent frame as input. This design allows the network to extract motion cues that are not available in a single image. These cues are particularly useful for detecting insects under the mentioned challenging conditions, which may be undistinguishable from background in static images. By providing a dynamic context, the model can better localize and classify moving insects, leading to improved performance under field conditions. By incorporating these motion cues, the network can leverage motion cues to identify subtle motion patterns that help distinguish insects from the background  
In this work, our method is based on the YOLOv8 architecture, which is illustrated in Figure 5. We begin by introducing the proposed motion module, followed by a detailed description of its training procedure. The overall structure of the motion module is depicted in Figure 6.  
This module can be inserted after any layer in the YOLOv8 backbone, prior to the SPPF block. It takes as input two feature maps: the output from layer N at time \(t\) and the output from the same layer at time \(t-1\), denoted in Figure 6 as \(F_{t}\) and \(F_{t-1}\), respectively. To encode motion information, the module computes the difference between these consecutive feature maps and applies the absolute value operation, \(|F_{t}-F_{t-1}|\), then this absolute difference is normalized using batch normalization. We empirically evaluated both alternatives-using the raw residual and its absolute value-and found that the latter consistently led to better detection performance. The use of absolute value highlights the magnitude of changes regardless of direction, allowing the network to focus on relevant dynamic information without being sensitive to sign. Next, the original feature map \(F_{t}\) is concatenated with the normalized difference along the channel dimension. Assuming each input feature map has \(C\) channels, the concatenated feature map will have \(2C\) channels. To integrate the motion information and restore the channel count to \(C\), a \(1\times 1\) convolution is applied. This ensures compatibility with the subsequent layer in the network. Figure 4: Distribution of normalized bounding box sizes for pests dataset. This process is summarized in Equation (1). \[F_{M}(F_{t},F_{t-1})=\text{Conv}(\text{Concat}(F_{t},\text{BN}(|F_{t}-F_{t-1}|))) \tag{1}\]  
where:  
* \(F_{M}\) is the motion module. * \(F_{t}\) is the feature map up to layer \(N\) for image at time \(t\). * \(F_{t-1}\) is the feature map up to layer \(N\) for image at time \(t-1\). * \(\text{Conv}(\cdot)\) is a \(1\times 1\) convolution. * \(\text{Concat}(\cdot,\cdot)\) is the concatenation along the channel dimension operation. * \(\text{BN}(\cdot)\) is BatchNorm2D operation. Assuming that the dimensions of \(F_{t}\) and \(F_{t-1}\) are \((H,W,C)\), the output of the motion module, denoted as \(F_{M}(F_{t},F_{t-1})\), will also have dimensions \((H,W,C)\). This is ensured by the use of a \(1\times 1\) convolution, which reduces the concatenated feature map back to the original number of channels. As a result, the output of the module matches the expected input dimensions of layer \(N+1\). Figure 5: YOLOv8 network architecture. Having described the structure and functionality of the motion module, we now present the training procedure used to optimize its parameters within the YOLOv8 network. We begin with a YOLOv8 model pretrained on the COCO dataset, and fine-tune it for 100 epochs using one of the insect datasets presented in the previous section.