赞
踩
注:放入项目对应文件夹即可.
注:这一步一定要确保完成,CUDA_HOME 更换成你自己的路径,要不然就会出现NameError: name ‘_C’ is not defined,这个错误折磨作者将近两天了,终于解决了(哭~).
$env:CUDA_HOME
注:虽说不知道在 GitBash 中再设置一次环境变量是否有必要,但作者是这样的,所以为了避免报错,建议大家做好这一步.
export AM_I_DOCKER=False
export BUILD_WITH_CUDA=True
export CUDA_HOME=/c/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v12.2
注:在 Bash 终端中,路径中的空格需要用反斜杠
\
转义.
echo $CUDA_HOME
python -m pip install -e segment_anything
python -m pip install -e GroundingDINO
cd GroundingDINO
python setup.py build
python setup.py install
pip install --upgrade diffusers[torch]
cd grounded-sam-osx
pip install openmim
mim install mmcv-full==1.7.1
pip install -r requirements.txt
cd transformer_utils
python setup.py install
注:其实可以在终端输入
./install.sh
命令的,但这样会导致运行完之后命令打开的 GitBash 窗口自动关闭,看不到到底有没有报错,所以这里建议 一步步手动 在终端运行 install.sh 中的命令.
transformers
的版本号为 4.29.0(4.15.0 会报错):timm==0.4.12
transformers==4.29.0
fairscale==0.4.4
pycocoevalcap
torch
torchvision
Pillow
scipy
cd Tag2Text
pip install -r requirements.txt
pip install opencv-python pycocotools matplotlib onnxruntime onnx ipykernel
from groundingdino.util.inference import load_model, load_image, predict, annotate, Model
import cv2
CONFIG_PATH = "GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py"
CHECKPOINT_PATH = "./groundingdino_swint_ogc.pth"
DEVICE = "cuda"
IMAGE_PATH = "assets/demo1.jpg" # 修改
TEXT_PROMPT = "bear." # 修改
BOX_TRESHOLD = 0.35
TEXT_TRESHOLD = 0.25
image_source, image = load_image(IMAGE_PATH)
model = load_model(CONFIG_PATH, CHECKPOINT_PATH)
boxes, logits, phrases = predict(
model=model,
image=image,
caption=TEXT_PROMPT,
box_threshold=BOX_TRESHOLD,
text_threshold=TEXT_TRESHOLD,
device=DEVICE,
)
annotated_frame = annotate(image_source=image_source, boxes=boxes, logits=logits, phrases=phrases)
cv2.imwrite("annotated_image.jpg", annotated_frame)
python grounding_dino_demo.py
注:Connection to huggingface.co:需要科学上网,即可消除这个警告.
python -m pip install -e GroundingDINO
cd GroundingDINO
python setup.py build
python setup.py install
python setup.py build
和python setup.py install
命令后,才看见的报错信息(人麻了).Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。