MCPcopy
hub / github.com/ttengwang/Caption-Anything

github.com/ttengwang/Caption-Anything @main sqlite

repository ↗ · DeepWiki ↗
258 symbols 784 edges 21 files 48 documented · 19%
README
<img src="https://github.com/ttengwang/Caption-Anything/raw/main/assets/caption_anything_logo.png" height="160" />

Open in Colab

Caption-Anything is a versatile image processing tool that combines the capabilities of Segment Anything, Visual Captioning, and ChatGPT. Our solution generates descriptive captions for any object within an image, offering a range of language styles to accommodate diverse user preferences. It supports visual controls (mouse click) and language controls (length, sentiment, factuality, and language). * Visual controls and language controls for text generation * Chat about selected object for detailed understanding * Interactive demo

Along the River During the Qingming Festival (清明上河图)

:rocket: Updates

  • 2023/04/30: support caption everything in a paragraph
  • 2023/04/25: We are delighted to introduce Track-Anything, an inventive project from our lab that offers a versatile and user-friendly solution for video object tracking and segmentation.
  • 2023/04/23: support langchain + VQA, better chatbox performance
  • 2023/04/20: add mouse trajectory as visual control (beta)
  • 2023/04/13: add Colab Tutorial Open in Colab
  • 2023/04/11: Release code

:joystick: Demo

Explore the interactive demo of Caption-Anything, which showcases its powerful capabilities in generating captions for various objects within an image. The demo allows users to control visual aspects by clicking on objects, as well as to adjust textual properties such as length, sentiment, factuality, and language.




:hammer_and_wrench: Getting Started

Linux

# Clone the repository:
git clone https://github.com/ttengwang/caption-anything.git
cd caption-anything

# Install dependencies (python version >= 3.8.1):
pip install -r requirements.txt

# Configure the necessary ChatGPT APIs
export OPENAI_API_KEY={Your_Private_Openai_Key}

# Run the Caption-Anything gradio demo.
python app_langchain.py --segmenter huge --captioner blip2 --port 6086  --clip_filter  # requires 13G GPU memory
#python app_langchain.py --segmenter base --captioner blip2 # requires 8.5G GPU memory
#python app_langchain.py --segmenter base --captioner blip # requires 5.5G GPU memory

# (Optional) Use the pre-downloaded SAM checkpoints
wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth ./sam_vit_h_4b8939.pth
python app_langchain.py --segmenter huge --captioner blip2 --port 6086 --segmenter_checkpoint ./sam_vit_b_01ec64.pth  # requires 11.7G GPU memory

Windows(powershell)

Tested in Windows11 using Nvidia 3070-8G.

# Clone the repository:
git clone https://github.com/ttengwang/caption-anything.git
cd caption-anything

# Install dependencies:
pip install -r requirements.txt

# Download the [base SAM checkpoints](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth).
Invoke-WebRequest https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth -OutFile ./sam_vit_b_01ec64.pth

# Configure the necessary ChatGPT APIs
$env:OPENAI_API_KEY = '{Your_Private_Openai_Key}'

# Run the Caption-Anything gradio demo.
python app_langchain.py --captioner blip --port 6086 --segmenter base # better chatbox via langchain + VQA
python app_langchain.py --captioner blip --port 6086 --segmenter base --segmenter_checkpoint ./sam_vit_b_01ec64.pth  # Use the pre-downloaded SAM checkpoints
python app.py --captioner blip --port 6086 --segmenter base 

:computer: Usage

from caption_anything import CaptionAnything, parse_augment
args = parse_augment()
visual_controls = {
    "prompt_type":["click"],
    "input_point":[[500, 300], [1000, 500]],
    "input_label":[1, 0], # 1/0 for positive/negative points
    "multimask_output":"True",
}
language_controls = {
    "length": "30",
    "sentiment": "natural", # "positive","negative", "natural"
    "imagination": "False", # "True", "False"
    "language": "English" # "Chinese", "Spanish", etc.
}
model = CaptionAnything(args, openai_api_key)
out = model.inference(image_path, visual_controls, language_controls)

:book: Citation

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

@article{wang2023caption,
  title={Caption anything: Interactive image description with diverse multimodal controls},
  author={Wang, Teng and Zhang, Jinrui and Fei, Junjie and Ge, Yixiao and Zheng, Hao and Tang, Yunlong and Li, Zhe and Gao, Mingqi and Zhao, Shanshan and Shan, Ying and Zheng, Feng},
  journal={arXiv preprint arXiv:2305.02677},
  year={2023}
}

Acknowledgements

The project is based on Segment Anything, BLIP/BLIP-2, ChatGPT, Visual ChatGPT, GiT. Thanks for the authors for their efforts.

Contributor

Our project wouldn't be possible without the contributions of these amazing people! Thank you all for making this project better.

Teng Wang @ Southern University of Science and Technology & HKU & Tencent ARC Lab \ Jinrui Zhang @ Southern University of Science and Technology \ Junjie Fei @ Xiamen University \ Zhe Li @ Southern University of Science and Technology \ Yunlong Tang @ Southern University of Science and Technology \ Mingqi Gao @ Southern University of Science and Technology & University of Warwick \ Hao Zheng @ Southern University of Science and Technology

Core symbols most depended-on inside this repo

load_image
called by 16
caption_anything/utils/utils.py
inference
called by 12
caption_anything/model.py
generate
called by 9
caption_anything/captioner/modeling_blip.py
create_bubble_frame
called by 8
caption_anything/utils/image_editing_utils.py
parse
called by 7
caption_anything/text_refiner/text_refiner.py
mask_painter
called by 6
caption_anything/utils/utils.py
transpose_for_scores
called by 5
caption_anything/captioner/modeling_git.py
filter_caption
called by 5
caption_anything/captioner/base_captioner.py

Shape

Method 138
Function 68
Class 48
Route 4

Languages

Python100%

Modules by API surface

caption_anything/captioner/modeling_git.py78 symbols
caption_anything/captioner/modeling_blip.py56 symbols
caption_anything/utils/utils.py19 symbols
app_langchain.py17 symbols
app.py14 symbols
caption_anything/utils/chatbot.py13 symbols
caption_anything/model.py13 symbols
caption_anything/captioner/base_captioner.py13 symbols
caption_anything/text_refiner/text_refiner.py6 symbols
caption_anything/segmenter/base_segmenter.py4 symbols
caption_anything/captioner/git.py4 symbols
caption_anything/captioner/blip.py4 symbols

Dependencies from manifests, versioned

langchain0.0.101 · 1×
opencv-python4.5.5.64 · 1×
torch1.10.1 · 1×
torchaudio0.10.1 · 1×
torchvision0.11.2 · 1×

For agents

$ claude mcp add Caption-Anything \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact