Coder Social home page Coder Social logo

deokgyuhan / count-anything Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ylqi/count-anything

0.0 0.0 0.0 17.37 MB

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.

Python 100.00%

count-anything's Introduction

Count Anything

Count Anything
Liqi, Yan
ZJU-CV, Zhejiang University / Fudan Univerisity

Count Anything (CA) project is a versatile image processing tool that combines the capabilities of Segment Anything, Semantic-Segment-Anything, and CLIP. Our solution can count any object specified by users within an image.

🚐 Count Anything (CA) engine

The CA engine consists of three steps:

  • (I) Segement Anything. Following Semantic-Segment-Anything, CA engine crops a patch for each mask predicted by Segment Anything.
  • (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).
  • (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.

🚩Examples

πŸ’» Requirements

  • Python 3.7+
  • CUDA 11.1+

πŸ› οΈ Installation

conda env create -f environment.yaml
conda activate ca-env

πŸš€ Quick Start

1. Run Segment Anything to get segmentation jsons for each image:

Please use --convert-to-rle to save segmentation results as .json files.

python 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
python 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

2. Save the .jpg and .json in our data/examples folder:

β”œβ”€β”€ Count-Anything
|   β”œβ”€β”€ data
|   β”‚   β”œβ”€β”€ examples
|   β”‚   β”‚   β”œβ”€β”€ AdobeStock_323574125.jpg
|   β”‚   β”‚   β”œβ”€β”€ AdobeStock_323574125.json
|   β”‚   β”‚   β”œβ”€β”€ ...

3. Run our Count Anything engine with 1 GPU:

Please use --text_prompt [OBJ] to specify the customized class for counting.

python scripts/main.py --out_dir=output --world_size=1 --save_img --text_prompt="shirt" --data_dir=data/examples 
python scripts/main.py --out_dir=output --world_size=1 --save_img --text_prompt="person" --data_dir=data/crowd_examples/ 

The result is saved in output folder.

πŸ˜„ Acknowledgement

πŸ“œ Citation

If you find this work useful for your research, please cite our github repo:

@misc{yan2023count,
    title = {Count Anything},
    author = {Yan, Liqi},
    howpublished = {\url{https://github.com/ylqi/Count-Anything}},
    year = {2023}
}

count-anything's People

Contributors

ylqi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.