[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-83935":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":19,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":22,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":32,"readmeContent":33,"aiSummary":10,"trendingCount":16,"starSnapshotCount":16,"syncStatus":34,"lastSyncTime":35,"discoverSource":36},83935,"count-anything","Mengqi-Lei\u002Fcount-anything","Mengqi-Lei","Code and implementation guidelines for the paper Counting Anything. Project Page: https:\u002F\u002Fmengqi-lei.github.io\u002Fcount-anything-projectpage\u002F","",null,"Python",101,4,5,3,0,17,36,70,83.7,"Apache License 2.0",false,"main",true,[26,5,27,28,29,30,31],"computer-vision","object-counting","object-detection","open-vocabulary","vision-foundation-model","vision-language-model","2026-06-12 04:01:42","\u003Ch1 align=\"center\">Count Anything\u003C\u002Fh1>\n\n\u003Cp align=\"center\">\n  \u003Cstrong>Text-guided object counting across domains with instance-grounded point predictions\u003C\u002Fstrong>\n\u003C\u002Fp>\n\n\u003Cp align=\"center\">\n  \u003Ca href=\"https:\u002F\u002Fmengqi-lei.github.io\u002Fcount-anything-projectpage\u002F\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FProject-Page-purple\" alt=\"Project Page\">\u003C\u002Fa>\n  \u003Ca href=\"https:\u002F\u002Fhuggingface.co\u002FMengqiLei\u002Fcount-anything\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FHugging%20Face-Model-yellow\" alt=\"Hugging Face Model\">\u003C\u002Fa>\n  \u003Ca href=\"https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FMengqiLei\u002Fcount-anything-demo\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FHugging%20Face-Demo-orange\" alt=\"Hugging Face Demo\">\u003C\u002Fa>\n  \u003Ca href=\"https:\u002F\u002Farxiv.org\u002Fabs\u002F2605.30846\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FarXiv-2605.30846-b31b1b\" alt=\"arXiv Paper\">\u003C\u002Fa>\n  \u003Ca href=\"assets\u002Fpaper\u002FCount-Anything.pdf\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPaper-PDF-blue\" alt=\"Paper PDF\">\u003C\u002Fa>\n  \u003Ca href=\"mailto:mengqi-lei@163.com\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FContact-Email-green\" alt=\"Contact Email\">\u003C\u002Fa>\n\u003C\u002Fp>\n\n\u003Cp align=\"center\">\n  \u003Ca href=\"README.md\">English\u003C\u002Fa> |\n  \u003Ca href=\"README_CN.md\">中文\u003C\u002Fa>\n\u003C\u002Fp>\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"assets\u002Freadme\u002Fcount_anything_poster.jpg\" alt=\"Count Anything poster\" width=\"100%\">\n\u003C\u002Fp>\n\n\u003Cp align=\"center\">\n  \u003Cstrong>✨Play with the demo: \u003Ca href=\"https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FMengqiLei\u002Fcount-anything-demo\">🔗Huggingface Demo\u003C\u002Fa>\u003C\u002Fstrong>\n\u003C\u002Fp>\n\n## Overview\n\nThis repository introduces **Count Anything**, a generalist model for text-guided object counting across domains. Given an image and a natural-language query, Count Anything returns an instance-grounded set of target points whose cardinality gives the count. This formulation unifies category-conditioned counting with interpretable spatial localization.\n\n### Cross-domain Text-guided Counting\n\n- Study text-guided object counting across domains, where users specify the target with a category name or a natural-language query.\n- Construct **CLOC**, a Cross-domain Large-scale Object Counting dataset that reorganizes diverse public data sources into a unified counting benchmark.\n- Cover six visual domains: General Scene, Remote Sensing, Histopathology, Cellular Microscopy, Agriculture, and Microbiology.\n\n### Dual-granularity Instance Enumeration\n\n- Adopt discrete instance points as the final prediction form, rather than using density maps as the final output.\n- Use a **Region-level Sparse Counter (RSC)** to provide object-level anchoring for large and sparse targets.\n- Use a **Pixel-level Dense Counter (PDC)** to capture small, crowded, and weakly bounded targets through dense point prediction.\n\n### Point-centric Supervision and Complementary Fusion\n\n- Convert heterogeneous annotations, including boxes, points, polygons, masks, rotated boxes, and label maps, into counting points with optional boxes.\n- Use point-centric supervision so every valid instance is supervised by a point, while bounding boxes are used only when reliable box annotations exist.\n- Combine RSC and PDC with **Complementary Count Fusion (CCF)** in a parameter-free manner, suppressing duplicate counts while preserving their complementarity.\n\nCount Anything is trained and evaluated on CLOC, which contains about 220K images, 619 categories, and 15M object instances. Extensive experiments show that Count Anything achieves strong counting accuracy and multi-domain generalization, substantially outperforming existing open-world counting methods.\n\n## Main Results\n\n![Main CLOC comparison table from the paper](assets\u002Freadme\u002Fmain_results_cloc_table.jpg)\n\n## Visualizations\n\n\u003Cp align=\"center\">\n  \u003Ca href=\"assets\u002Freadme\u002Fcount_anything_visualizations.jpg\">\n    \u003Cimg src=\"assets\u002Freadme\u002Fcount_anything_visualizations.jpg\" alt=\"Count Anything qualitative visualizations\" width=\"100%\">\n  \u003C\u002Fa>\n\u003C\u002Fp>\n\n## Quick Start\n\n### 1. Environment Setup\n\nCreate a conda environment and install the required dependencies:\n\n```bash\nconda create -n countanything python=3.12 -y\nconda activate countanything\npip install -r requirements.txt\n```\n\nThe dependency list is intentionally kept minimal. If the default pip resolver does not select the CUDA build you need, please install the PyTorch and torchvision builds that match your local CUDA version.\n\n### 2. Weight Preparation\n\nFor inference, validation, or test-only reproduction, only the released CountAnything checkpoint is required. Download `count_anything.pt` from [Hugging Face](https:\u002F\u002Fhuggingface.co\u002FMengqiLei\u002Fcount-anything).\n\nAfter downloading, place the file at:\n\n```text\ncheckpoints\u002Fcount_anything.pt\n```\n\nThe standalone validation and test configurations load `checkpoints\u002Fcount_anything.pt` directly.\n\nIf you want to train or fine-tune CountAnything from the SAM3 initialization, please also download the official SAM3 pretrained weights. Due to license and redistribution restrictions, this repository does not directly provide the official SAM3 pretrained weights. Please visit the official SAM3 Hugging Face page:\n\n[Hugging Face](https:\u002F\u002Fhuggingface.co\u002Ffacebook\u002Fsam3)\n\nDownload the SAM3 pretrained weight file `sam3.pt`, and place it at:\n\n```text\npretrained\u002Fsam3.pt\n```\n\nPlease make sure to download the **SAM3** weights, not SAM3.1 weights. The expected file name is:\n\n```text\nsam3.pt\n```\n\nBy default, the training configuration initializes the model from `pretrained\u002Fsam3.pt`.\n\n### 3. Data Preparation\n\nThis repository uses the CLOC dataset by default. The dataset preparation guide explains how to download the CLOC annotation archive, the distributable augmented-image archive, and the raw images of each source dataset. Please prepare the dataset following that guide before running training or evaluation.\n\n💡 **Dataset availability note.** Because some source datasets used by CLOC are subject to license and redistribution restrictions, we cannot directly release the complete CLOC image set and can only reference those data sources. We release the CLOC annotation files produced by our re-annotation process and the subset of augmented images that can be redistributed. To reproduce the complete CLOC dataset, please download the original source images and follow the preprocessing, rebuilding, and audit steps in [data\u002FREADME.md](data\u002FREADME.md). **We can also provide a processed, ready-to-use copy of the complete CLOC dataset upon request; please contact us by email for access.**\n\nThe default configurations expect the train, validation, and test annotations at:\n\n```text\ndata\u002Fannotations\u002Ftrain_split_expanded_by_class.json\ndata\u002Fannotations\u002Fval_split_expanded_by_class.json\ndata\u002Fannotations\u002Ftest_split_expanded_by_class.json\n```\n\nEach sample corresponds to one image-category counting task. The annotation files provide the image path, category text, and the point \u002F bbox annotations for the corresponding category. The actual image location is specified by the `image_path` field in each annotation record.\n\nThe dataset directory is organized as follows:\n\n```text\ndata\u002F\n  annotations\u002F        # CLOC train\u002Fval\u002Ftest JSON files\n  images\u002F             # Raw dataset download and extraction directories\n  augmented\u002F          # Augmented images referenced by CLOC annotations\n  tools\u002F              # Data conversion, augmented-image rebuilding, and audit scripts\n  README.md           # English dataset preparation guide\n```\n\nFor the full dataset construction workflow, including raw dataset downloads, format conversion, augmented-image rebuilding, and path auditing, please refer to [data\u002FREADME.md](data\u002FREADME.md).\n\nIf your dataset paths differ from the default layout, please edit:\n\n```text\nconfig\u002Fcount_anything_train_cloc.yaml\nconfig\u002Fcount_anything_val_cloc.yaml\nconfig\u002Fcount_anything_test_cloc.yaml\n```\n\nand update `paths.train_annotation_file` and `paths.val_annotation_file` so they point to your local annotation files.\n\n### 4. Training\n\nStart training with `train.sh`:\n\n```bash\nCUDA_VISIBLE_DEVICES=0,1,2,3 \\\nNUM_GPUS=4 \\\nbash train.sh\n```\n\nBy default, `train.sh` uses:\n\n```text\nconfig\u002Fcount_anything_train_cloc.yaml\n```\n\nThis configuration corresponds to the main model setting in the paper: it initializes from SAM3 pretrained weights, enables RSC, PDC, and CCF, and trains the LoRA parameters together with the counting branch. The LoRA learning rate is `1e-3`; the learning rate follows a 30-epoch cosine schedule with `min_lr_ratio=0.1`.\n\nValidation after each epoch uses:\n\n```text\ndata\u002Fannotations\u002Fval_split_expanded_by_class.json\n```\n\nThe default training parameters include:\n\n- `train_batch_size=18`\n- `val_batch_size=40`\n- `max_epochs=30`\n- `val_epoch_freq=1`\n- `visualize_val_every_n_epochs=5`\n\nAfter training starts, logs, visualizations, and checkpoints are saved by default to:\n\n```text\nexp\u002Fcount_anything_train_cloc\u002F\n```\n\nTo change data paths, batch size, number of epochs, or the output directory, edit:\n\n```text\nconfig\u002Fcount_anything_train_cloc.yaml\n```\n\n### 5. Validation\n\nRun standalone validation with `val.sh`:\n\n```bash\nCUDA_VISIBLE_DEVICES=0,1,2,3 \\\nNUM_GPUS=4 \\\nbash val.sh\n```\n\nBy default, `val.sh` uses:\n\n```text\nconfig\u002Fcount_anything_val_cloc.yaml\n```\n\nThis configuration loads:\n\n```text\ncheckpoints\u002Fcount_anything.pt\n```\n\nand evaluates on the CLOC validation split:\n\n```text\ndata\u002Fannotations\u002Fval_split_expanded_by_class.json\n```\n\nValidation logs and prediction statistics are saved by default to:\n\n```text\nexp\u002Fcount_anything_val_cloc\u002F\n```\n\nTo validate another checkpoint or another validation set, edit:\n\n```text\nconfig\u002Fcount_anything_val_cloc.yaml\n```\n\nand update the checkpoint path and `paths.val_annotation_file`.\n\n### 6. Testing\n\nEvaluate a checkpoint with `test.sh`:\n\n```bash\nCUDA_VISIBLE_DEVICES=0,1,2,3 \\\nNUM_GPUS=4 \\\nbash test.sh\n```\n\nBy default, `test.sh` uses:\n\n```text\nconfig\u002Fcount_anything_test_cloc.yaml\n```\n\nThis configuration loads:\n\n```text\ncheckpoints\u002Fcount_anything.pt\n```\n\nand evaluates on the CLOC test split:\n\n```text\ndata\u002Fannotations\u002Ftest_split_expanded_by_class.json\n```\n\nEvaluation logs and prediction statistics are saved by default to:\n\n```text\nexp\u002Fcount_anything_test_cloc\u002F\n```\n\nTo evaluate another checkpoint or another test set, edit:\n\n```text\nconfig\u002Fcount_anything_test_cloc.yaml\n```\n\nand update the checkpoint path and `paths.val_annotation_file`.\n\n## Repository Structure\n\n```text\nCountAnything\u002F\n  train.sh                         # Default training entry point\n  val.sh                           # Default validation entry point\n  test.sh                          # Default test entry point\n  requirements.txt                 # Python dependencies\n  config\u002F\n    count_anything_train_cloc.yaml # CLOC training configuration\n    count_anything_val_cloc.yaml   # CLOC validation configuration\n    count_anything_test_cloc.yaml  # CLOC test configuration\n  count_anything\u002F\n    model\u002F                         # CountAnything model components\n    train\u002F                         # Trainer, losses, and matcher\n    eval\u002F                          # Post-processing and counting evaluation\n  sam3\u002F                            # SAM3-based image-language backbone components\n  pretrained\u002F\n    sam3.pt                        # Place the SAM3 pretrained weights here\n  checkpoints\u002F\n    count_anything.pt               # Place the CountAnything checkpoint here\n  data\u002F                            # CLOC dataset annotations and preparation tools\n  exp\u002F                             # Training and evaluation outputs\n```\n\n## Questions and Support\n\nIf you encounter any difficulty with dataset preparation, model weights, training, validation, or evaluation, please feel free to contact us and we will do our best to help.\n\n## Citation\n\nIf you find Count Anything useful in your research, please consider citing:\n\n```bibtex\n@article{lei2026count_anything,\n  title={Count Anything},\n  author={Lei, Mengqi and Cheng, Shuokun and Bao, Wei and Du, Shaoyi and Yong, Jun-Hai and Li, Siqi and Gao, Yue},\n  journal={arXiv preprint arXiv:2605.30846},\n  year={2026}\n}\n```\n",2,"2026-06-11 04:11:50","CREATED_QUERY"]