# DMA-Net: Decoupled Multi-Scale Attention for Few-Shot Object Detection
## 3 Proposed Methods
### Module Architecture
#### 3.2.2 Detection Module  
In the detection module, we also added the support information for query features. The details of the detection module are shown in Figure 7. The entire module had three inputs: original features from the FPN, proposals from the RPN, and support attentions from the support branch. We sent all support images to the backbone for feature extraction and remodeled these features into attention. Specifically, we used Res1-3 blocks of ResNet50 for feature extraction and Res4 blocks for preliminary remodeling, we used global average pooling on support features to obtain remodeled features \(\mathcal{F}_{s}\in\mathbb{R}^{1\times 1\times 2048}\), and the attention vectors of positive support features and negative support features were obtained using sigmoid on \(\mathcal{F}_{s}\). We sent the proposals into the RoI alignment module for feature mapping and performed the RoI alignment operation to obtain a series of features of the same size, which was convenient for the subsequent classification and regression tasks. Specifically, we mapped the proposals to the original features generated by the FPN rather than the features that were added with the support information that was sent to the RPN. This operation reduced the loss of query information in the proposals. Because the subsequent detection tasks had contradictions mentioned previously, we processed the proposals and sent them into two parallel heads for box classification and box regression. For the box regression task, we fused positive support attentions with proposals using channel-wise multiplication, and then performed smooth \(L_{1}\) on them for regression loss. For box classification, we fused  
Figure 6: Decoupled gradient module. the proposals with positive support attentions and negative support attentions and used a matching method [35] on them for classification, enabling the network to recognize objects of the same class and distinguish objects of different classes simultaneously. The input of the support branch was 2-way 3-shot in the proposed experiments; thus, we obtained a query image \(I_{q}^{c}\); positive support images \(I_{p}^{c}\), which have objects of the same class \(c\); and negative support images \(I_{p}^{n}\), which have objects of different classes \(n\). Positive proposals \(P_{p}\) and negative proposals \(P_{n}\) were generated after attention fusion. For each task, we filtered out 512 proposals from the RPN module, and the ratio of positive samples to negative samples was \(1:3\). \(P_{p}\) was composed of \(P_{p}^{fg}\) and \(P_{p}^{bg}\), and \(P_{n}\) was composed of \(P_{n}^{fg}\) and \(P_{n}^{bg}\). We set the label of foreground \(P^{fg}=\left\{P_{p}^{fg},P_{n}^{fg}\right\}\) to 1 and the rest to 0. We sorted background proposals \(P^{bg}=\left\{P_{p}^{bg},P_{n}^{bg}\right\}\) in descending order based on their class scores. According to the ratio of \(P^{fg}\), \(P_{p}^{bg}\), and \(P_{n}^{bg}\) of \(1:2:1\), proposals were selected to reconstruct the positive samples and negative samples that were used to calculate class loss. The negative samples contained the negative proposals wrongly divided into the foreground, which can help the network to distinguish objects of different categories when matching objects of the same class. The loss of each image is defined as \(L=L_{matching}+L_{box}\), and the total loss is defined as:  
\[L_{total}=\big{(}\underbrace{L_{cls}+L_{box}}_{L_{rpn}}\big{)}+\eta\cdot( \underbrace{L_{cls}+L_{box}}_{L_{rcnn}}), \tag{7}\]  
which is the same as that in [3], except that the \(L_{cls}\) in \(L_{rcnn}\) is \(L_{matching}\) in this paper, the matching loss is the cross-entropy, and \(\eta\) is a balancing parameter. The pseudo-code of the proposed method is shown in Algorithm 2. ```
0: Base set \(D_{base}\), support images \(I_{s}\), query image \(I_{q}\), initialized RPN parameters \(\theta_{rpn}\), RCNN parameters \(\theta_{rcnn}\), and support branch parameters \(\theta_{sup}\).