{"id":9534265,"url":"https://github.com/ylqi/Count-Anything","last_synced_at":"2025-08-23T20:32:35.171Z","repository":{"id":239506661,"uuid":"626941135","full_name":"ylqi/Count-Anything","owner":"ylqi","description":"This method uses Segment Anything and CLIP to ground and count any object that matches a custom text prompt, without requiring any point or box annotation.","archived":false,"fork":false,"pushed_at":"2023-04-22T06:26:56.000Z","size":17789,"stargazers_count":137,"open_issues_count":5,"forks_count":17,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-21T15:34:30.968Z","etag":null,"topics":["clip","count-anything","segment-anything"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ylqi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-12T13:16:53.000Z","updated_at":"2024-12-17T08:43:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"27ed2fb6-a401-446d-ac91-b58a056af7c4","html_url":"https://github.com/ylqi/Count-Anything","commit_stats":null,"previous_names":["ylqi/count-anything"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ylqi/Count-Anything","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ylqi%2FCount-Anything","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ylqi%2FCount-Anything/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ylqi%2FCount-Anything/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ylqi%2FCount-Anything/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ylqi","download_url":"https://codeload.github.com/ylqi/Count-Anything/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ylqi%2FCount-Anything/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271767988,"owners_count":24817592,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clip","count-anything","segment-anything"],"created_at":"2024-05-12T23:45:43.213Z","updated_at":"2025-08-23T20:32:35.160Z","avatar_url":"https://github.com/ylqi.png","language":"Python","funding_links":[],"categories":["Recent Works","Open Source Projects","🎨 \"Anything\" Projects Ecosystem"],"sub_categories":["Follow-up Papers","🎯 2023 Classic Projects"],"readme":"# Count Anything\n\n### [Official repo](https://github.com/ylqi/Count-Anything)\n\u003e **[Count Anything](https://github.com/ylqi/Count-Anything)**  \n\u003e Liqi, Yan                            \n\u003e ZJU-CV, Zhejiang University / Fudan Univerisity\n\n_**C**ount **A**nything (CA)_ project is a versatile image processing tool that combines the capabilities of [Segment Anything](https://segment-anything.com/), [Semantic-Segment-Anything](https://github.com/fudan-zvg/Semantic-Segment-Anything), and [CLIP](https://arxiv.org/abs/2103.00020).\nOur solution can count *any object* specified by users within an image.\n\n### 🚐 Count Anything (CA) engine\n![](./figures/CA_model.png)\nThe CA engine consists of three steps:\n- **(I) Segement Anything.** Following [Semantic-Segment-Anything](https://github.com/fudan-zvg/Semantic-Segment-Anything), CA engine crops a patch for each mask predicted by [Segment Anything](https://segment-anything.com/).\n- **(II) Class Mixer.** To identify the masks that match the user’s text prompt, we add the text prompt as an additional class into the class list from the close-set datasets (COCO or ADE20K). \n- **(III) CLIP Encoders.** The CA engine uses CLIP image encoder and text encoder to assess if the text prompt is the best option among other classes. If yes, this mask is considered as an instance of the class given by the text prompt, and the count number is incremented by 1.\n\n## 🚩Examples\n![](./figures/example_1.png)\n![](./figures/example_2.png)\n\n## 💻 Requirements\n- Python 3.7+\n- CUDA 11.1+\n\n## 🛠️ Installation\n```bash\nconda env create -f environment.yaml\nconda activate ca-env\n```\n## 🚀 Quick Start\n### 1. Run [Segment Anything](https://segment-anything.com/) to get segmentation jsons for each image:\nPlease use `--convert-to-rle` to save segmentation results as `.json` files.\n```bash\npython scripts/amg.py --checkpoint sam_vit_h_4b8939.pth --model-type vit_h --convert-to-rle --input examples/AdobeStock_323574125.jpg --output output --pred-iou-thresh 0.98 --crop-n-layers 0 --crop-nms-thresh 0.3 --box-nms-thresh 0.5 --stability-score-thresh 0.7\n```\n```bash\npython scripts/amg.py --checkpoint sam_vit_h_4b8939.pth --model-type vit_h --convert-to-rle --input examples/crowd_img.jpg --output output --pred-iou-thresh 0 --min-mask-region-area 0  --stability-score-thresh 0.8\n```\n### 2. Save the `.jpg` and `.json` in our `data/examples` folder:\n```none\n├── Count-Anything\n|   ├── data\n|   │   ├── examples\n|   │   │   ├── AdobeStock_323574125.jpg\n|   │   │   ├── AdobeStock_323574125.json\n|   │   │   ├── ...\n```\n\n### 3. Run our Count Anything engine with 1 GPU:\nPlease use `--text_prompt [OBJ]` to specify the customized class for counting.\n```bash\npython scripts/main.py --out_dir=output --world_size=1 --save_img --text_prompt=\"shirt\" --data_dir=data/examples \n```\n```bash\npython scripts/main.py --out_dir=output --world_size=1 --save_img --text_prompt=\"person\" --data_dir=data/crowd_examples/ \n```\nThe result is saved in `output` folder.\n\n## 😄 Acknowledgement\n- [Segment Anything](https://segment-anything.com/) provides the SA-1B dataset.\n- [HuggingFace](https://huggingface.co/) provides code and pre-trained models.\n- [Semantic-Segment-Anything](https://github.com/fudan-zvg/Semantic-Segment-Anything) provides code.\n- [CLIP](https://arxiv.org/abs/2103.00020) provide powerful semantic segmentation, image caption and classification models.\n\n## 📜 Citation\nIf you find this work useful for your research, please cite our github repo:\n```bibtex\n@misc{yan2023count,\n    title = {Count Anything},\n    author = {Yan, Liqi},\n    howpublished = {\\url{https://github.com/ylqi/Count-Anything}},\n    year = {2023}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fylqi%2FCount-Anything","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fylqi%2FCount-Anything","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fylqi%2FCount-Anything/lists"}