Abstract
<title>Abstract</title> <p>Class-agnostic counting (CAC) aims to count objects of any class with only a few prompts or even no prompts at all. Existing methods have made remarkable progress by using visual exemplars as prompts, yet this paradigm requires bounding boxes to annotate the target exemplars for counting. The inherent geometric constraints of bounding boxes inevitably make it difficult to precisely fit the actual contours of the exemplars, which leads to the unavoidable inclusion of irrelevant background information in the selected visual exemplars. This background noise may induce pseudo-activations as the network depth increases, which further undermines the matching between visual exemplars and the query image. Furthermore, although existing work adopts the Extract-and-Match paradigm to perform feature extraction and similarity modeling for both query and visual example features, no work analyzes its superiority from a theoretical perspective. Therefore, in this paper, we theoretically analyze the Extract-and-Match paradigm and propose a novel Perceptual Prior Similarity-guided Network (PPSNet) for class-agnostic counting. Specifically, PPSNet incorporates two elaborately designed modules: Perceptual Prior Construction Module (PPCM) and Similarity-guided Weighting Module (SWM). PPCM constructs a perceptual prior by leveraging scale information to emphasize the distribution of visual exemplars within the regions selected via bounding boxes, and it also alleviates the loss of scale information in visual exemplars caused by the resizing operation. SWM leverages the principle of contrastive learning to perform patch-level supervision on the similarity map between visual exemplars and the query image by constructing a foreground mask of visual exemplars. It then weights the query features with this similarity map to enhance the response of query features to the distribution of visual exemplars. In addition, we extend PPSNet into a general counting model, which can complete class-agnostic counting with visual prompts, text prompts, or no prompts at all. Extensive experiments conducted on the FSC-147, CARPK, and COCO datasets demonstrate that our proposed method achieves superior performance. Code has been released in https://github.com/Jissaww/PPSNet.</p>