集成SAM,可以通過文本提示做檢測/分割等任務。
我們計劃通過結合 Grounding DINO 和 Segment Anything 來創(chuàng)建一個非常有趣的演示,旨在通過文本輸入檢測和分割任何內容! 并且我們會在此基礎上不斷完善它,創(chuàng)造出更多有趣的demo。
我們非常愿意幫助大家分享和推廣基于Segment-Anything的新項目,更多精彩的demo和作品請查看社區(qū):亮點擴展項目。 您可以提交新問題(帶有項目標簽)或新拉取請求以添加新項目的鏈接。
該項目背后的核心思想是結合不同模型的優(yōu)勢,構建一個非常強大的管道來解決復雜問題。 值得一提的是,這是一個組合強專家模型的工作流程,其中所有部件都可以單獨或組合使用,并且可以替換為任何相似但不同的模型(例如用 GLIP 或其他探測器替換 Grounding DINO / 替換 Stable- 使用 ControlNet 或 GLIGEN 進行擴散/與 ChatGPT 結合)。
一、Preliminary Works
在這里,我們提供了一些您在嘗試演示之前可能需要了解的背景知識。
- Segment-Anything:
強大的基礎模型旨在分割圖像中的所有內容,這需要提示(如框/點/文本)來生成掩模
2. Grounding DINO:
強大的零樣本檢測器,能夠生成帶有自由格式文本的高質量框和標簽。
3. OSX
一種強大而高效的單階段運動捕捉方法,可從單目圖像生成高質量的 3D 人體網(wǎng)格。 OSX還發(fā)布了大規(guī)模上半身數(shù)據(jù)集UBody,用于更準確地重建上半身場景。
4. Stable-Diffusion
超強大的開源潛在文本到圖像擴散模型。
5. RAM
RAM is an image tagging model, which can recognize any common category with high accuracy.
- BLIP
A wonderful language-vision model for image understanding.
- Visual ChatGPT
A wonderful tool that connects ChatGPT and a series of Visual Foundation Models to enable sending and receiving images during chatting.
- Tag2Text
An efficient and controllable vision-language model which can simultaneously output superior image captioning and image tagging.
- VoxelNeXt
A clean, simple, and fully-sparse 3D object detector, which predicts objects directly upon sparse voxel features.
二、Highlighted Projects
在這里,我們提供了一些您可能會感興趣的令人印象深刻的作品:
2.1 Semantic-SAM
通用圖像分割模型,能夠以任何所需的粒度分割和識別任何內容.
2.2 SEEM: Segment Everything Everywhere All at Once
強大的提示分割模型支持使用各種類型的提示(文本、點、涂鴉、引用圖像等)以及提示的任意組合進行分割。
2.3 OpenSeeD
一個用于開放詞匯分割和檢測的簡單框架,支持通過框輸入生成掩模的交互式分割.
2.4 LLaVA
Visual instruction tuning with GPT-4.
三、Installation
該代碼需要 python>=3.8,以及 pytorch>=1.7 和 torchvision>=0.8。 請按照此處的說明安裝 PyTorch 和 TorchVision 依賴項。 強烈建議安裝支持 CUDA 的 PyTorch 和 TorchVision。
3.1 Install with Docker
Open one terminal:
make build-image
make run
就是這樣。
如果您想允許跨 docker 容器進行可視化,請打開另一個終端并輸入:
xhost +
3.2 Install without Docker
如果您想為Grounded-SAM構建本地GPU環(huán)境,您應該手動設置環(huán)境變量,如下所示:
export AM_I_DOCKER=False
export BUILD_WITH_CUDA=True
export CUDA_HOME=/path/to/cuda-11.3/
安裝Segment Anything:
python -m pip install -e segment_anything
安裝 DINO 接地:
python -m pip install -e GroundingDINO
安裝擴散器:
pip install --upgrade diffusers[torch]
Install osx:
git submodule update --init --recursive
cd grounded-sam-osx && bash install.sh
Install RAM & Tag2Text:
git submodule update --init --recursive
cd Tag2Text && pip install -r requirements.txt
以下可選依賴項對于掩模后處理、以 COCO 格式保存掩模、示例筆記本以及以 ONNX 格式導出模型是必需的。 運行示例筆記本還需要 jupyter。
pip install opencv-python pycocotools matplotlib onnxruntime onnx ipykernel
四、GroundingDINO: Detect Everything with Text Prompt
以下是運行 GroundingDINO 演示的分步教程:
4.1 Download the pretrained weights
cd Grounded-Segment-Anything
# download the pretrained groundingdino-swin-tiny model
wget https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth
4.2 Running the demo
python grounding_dino_demo.py
4.3 Running with Python
from groundingdino.util.inference import load_model, load_image, predict, annotate
import cv2
model = load_model("GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py", "./groundingdino_swint_ogc.pth")
IMAGE_PATH = "assets/demo1.jpg"
TEXT_PROMPT = "bear."
BOX_THRESHOLD = 0.35
TEXT_THRESHOLD = 0.25
image_source, image = load_image(IMAGE_PATH)
boxes, logits, phrases = predict(
model=model,
image=image,
caption=TEXT_PROMPT,
box_threshold=BOX_THRESHOLD,
text_threshold=TEXT_THRESHOLD
)
annotated_frame = annotate(image_source=image_source, boxes=boxes, logits=logits, phrases=phrases)
cv2.imwrite("annotated_image.jpg", annotated_frame)
如果您想使用 Grounding DINO 在一個句子中檢測多個物體,我們建議用 分隔每個名稱。 。 一個例子:貓。 狗 。 椅子 。
4.4 Check the annotated image
帶注釋的圖像將保存為./annotated_image.jpg。文章來源:http://www.zghlxwxcb.cn/news/detail-766490.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-766490.html
到了這里,關于【計算機視覺 | 目標檢測 | 圖像分割】Grounded Segment Anything:Grounding DINO + Segment Anything Model (SAM)介紹的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!