# Multiscale Dynamic Attention and Hierarchical Spatial Aggregation for Few-Shot Object Detection
## 3 Methodology
### Hierarchical Adaptive-Pyramid Pooling  
To enhance detection performance, we designed a hierarchical adaptive-pyramid pooling (HAPP) framework based on SPP structure, as illustrated in Figure 4. This framework includes two convolutional layers tailored to the input and output channel numbers, four pooling layers with different pooling methods and sizes, and a forward propagation mechanism. \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Index** & **Layer Name** & **Input Size** & **Output Size** \\ \hline  
\hline \hline \end{tabular}
\end{table} 
Table 1: Structure of feature extraction network. Here, Conv3-xxx indicates a convolutional layer with a 3 \(\times\) 3 kernel and xxx channels, FC-xxx indicates a fully connected layer with xxx nodes, and A-xxx indicates MultiScale-DynaAttention with xxx input channels. Before introducing HAPP, the input channel numbers (\(C_{1}\)) and output channel numbers (\(C_{2}\)) should first be determined. The first convolutional layer, using a \(1\times 1\) kernel, reduces the input channels to \(C_{1}/2\). The second convolutional layer, also using a \(1\times 1\) kernel, maps the features from the spatial pyramid pooling to the output channels. Pooling layers are designed to extract features at different scales: two max-pooling layers with \(3\times 3\) and \(5\times 5\) kernels and two average-pooling layers with \(3\times 3\) and \(5\times 5\) kernels. To maintain the feature dimensions (height and width), all pooling layers use a stride of 1, with padding parameters of 1 for the \(3\times 3\) kernel and 2 for the \(5\times 5\) kernel. In the forward propagation process, the input features are first reduced in dimensionality by the first convolutional layer. These reduced features are then passed through the four pooling layers, resulting in feature maps on different scales. The output from the first convolutional layer is concatenated with the four pooled feature maps. This concatenated feature map is then passed through the second convolutional layer to produce the final output features. The computation for the five-branch HAPP structure is as follows:  
\[X=\text{conv}1(X_{\text{in}}), \tag{12}\]  
\[Y_{1}=\text{MaxPool}1(X), \tag{13}\]  
\[Y_{2}=\text{MaxPool}2(X), \tag{14}\]  
\[Y_{3}=\text{AvgPool}1(X), \tag{15}\]  
\[Y_{4}=\text{AvgPool}2(X), \tag{16}\]  
\[X_{\text{out}}=\text{conv}2(\text{concat}(X,Y_{1},Y_{2},Y_{3},Y_{4})), \tag{17}\]  
where \(X_{\text{in}}\) is the input feature map. Given \(X_{\text{in}}\) with dimensions \(C\times H\times W\), the output tensor \(X\) from the first convolutional layer has dimensions \(\frac{C}{2}\times H\times W\). \(Y_{1}\), \(Y_{2}\), \(Y_{3}\), and \(Y_{4}\) are the outputs of the four pooling layers, each with dimensions \(\frac{C}{2}\times H\times W\). The concatenated feature map thus has dimensions of \(\frac{C}{2}\times H\times W\), and, after the second  
Figure 4: The structure of HAPP. convolutional layer, the output channels are mapped to the specified number of channels. In this implementation, the HAPP structure's input channel count was 256, and the output channel count was 512. To strengthen the detection architecture's capability in capturing multiscale features, the hierarchical adaptive-pyramid pooling structure is incorporated into a newly designed detection head branch and seamlessly integrated into the existing network structure. As illustrated in Figure 5, features are extracted from an intermediate layer of the feature extraction network (the last convolutional layer with an output channel count of 256 in the VGG16 network in this implementation). These features are fed into the optimized five-branch HAPP structure, whose output serves as the feature representation passed to the RoI pooling module, mapping the features into fixed-sized visual representations.