Grounding Dino如何在pycharm上运行(成功完结)

首先一定要确保你的cuda版本与你虚拟环境安装的torch的cuda版本一致!!!!!我就因为这个问题又重新卸载安装了cuda

按照官网步骤走真的运行成功了,历经了好几天磨难!!!!!

首先使用git命令下载官网代码

git clone https://github.com/IDEA-Research/GroundingDINO.git

下载的时候你需要科学上网,下载如果报错的话移步我的另一篇文章:

项目bug-从github上git clone代码报错问题-CSDN博客

首先你肯定是要创建一个虚拟环境的,命令:conda create -n dino python==3.10

我的虚拟环境名称为dino,你可以改为你自己想要的名字。首先激活你创建的环境,conda activate dino

把目录切换到你刚刚下载好的文件夹下,cd  GroundingDINO

运行命令  (别忘了-e后面的一个点),我运行时候不知道为啥报错了,别放弃我又重新执行了两次命令,就成功了!

扩展: -e 后接 . 代表将当前项目以软链接并且可修改的形式安装到当前python环境中,一句话来说就是该命令会执行当前目录下的setup.py文件,具体做什么得看setup.py怎么写的, 安装完成后, 通过执行pip list,便可看到当前项目被安装到了python环境中。

pip install -e .

但是呢它会有一些爆红!!不影响,直接按照上面的爆红提示安装相应的包就可以了

分别为:

pip install pyasn1-modules==0.2.1 
pip install markdown==2.6.8
pip install werkzeug==1.0.1

然后在文件夹下创建一个weights文件夹,用来存放权重文件,权重文件下载链接:https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth

我看官网用一个命令来下载,但是pycharm说这wget不是内部命令,我就直接通过链接下载之后给他手动放到了weights文件夹下!!!

wget -q https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth

然后新建一个python文件,test.py用来测试一下项目,test.py代码:

from groundingdino.util.inference import load_model, load_image, predict, annotate
import cv2

#加载模型
model = load_model("groundingdino/config/GroundingDINO_SwinT_OGC.py", "weights/groundingdino_swint_ogc.pth")
#要预测的图片路径
IMAGE_PATH = ".asset/cat_dog.jpeg"
#要预测的类别提示,可以输入多个类中间用英文句号隔开
TEXT_PROMPT = "cat,dog"
BOX_TRESHOLD = 0.35
TEXT_TRESHOLD = 0.25

image_source, image = load_image(IMAGE_PATH)

boxes, logits, phrases = predict(
    model=model,
    image=image,
    caption=TEXT_PROMPT,
    box_threshold=BOX_TRESHOLD,
    text_threshold=TEXT_TRESHOLD
)

annotated_frame = annotate(image_source=image_source, boxes=boxes, logits=logits, phrases=phrases)
#保存预测的图片,保存到outputs文件夹中,名称为annotated_image.jpg
cv2.imwrite("annotated_image.jpg", annotated_frame)

 但是给我报错了,看原因应该是torch不是GPU版本的,我就pip list查看了一下torch包的版本,是CPU版本的,所以我有重新安装了GPU版本的torch

GPU版本torch安装:

pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 --index-url https://download.pytorch.org/whl/cu118

安装完成之后再次运行python test.py命令,再次出现以下报错

我在官网看了别人的解决方案,如下:

1.先把根目录切换到上一级文件夹

cd .. 

2.在运行以下命令

pip install -e GroundingDINO --no-build-isolation

3.再次运行python test.py就可以了

其中有以下三条警告,但是他不影响运行,再项目文件夹里就看到了生成的结果图片


 完结撒花:

之前运行的时候还遇到了这些问题,在此存档吧!!!

:pip install -e .   运行完我就出现了这个报错,找了很多解决办法,

不想安装visual的办法如下链接:(解决办法:conda install libpython m2w64-toolchain -c msys2
)参考:Microsoft Visual C++ 14.0 is required.-CSDN博客

但是最后我还是下载了vc工具,参考:pip错误“Microsoft Visual C++ 14.0 is required.”解决办法 - 知乎 (zhihu.com)

但是解决完之后又报了新的错误,头大啊!!!ok这个错误是一个小错误,不可以开着科学上网工具运行项目!!!关掉之后就没有这个错了:

  • 6
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Applies basic field behavior in circuit design and demonstrates how it relates to grounding and shielding requirements and techniques in circuit design This book connects the fundamentals of electromagnetic theory to the problems of interference in all types of electronic design. The text covers power distribution in facilities, mixing of analog and digital circuitry, circuit board layout at high clock rates, and meeting radiation and susceptibility standards. The author examines the grounding and shielding requirements and techniques in circuit design and applies basic physics to circuit behavior. The sixth edition of this book has been updated with new material added throughout the chapters where appropriate. The presentation of the book has also been rearranged in order to reflect the current trends in the field. Grounding and Shielding: Circuits and Interference, Sixth Edition: Includes new material on vias and field control, capacitors as transmission lines, first energy sources, and high speed designs using boards with only two layers Demonstrates how circuit geometry controls performance from dc to gigahertz Examines the use of multi-shielded transformers in clean-power installations Provides effective techniques for handling noise problems in analog and digital circuits Discusses how to use conductor geometry to improve performance, limit radiation, and reduce susceptibility to all types of hardware and systems Grounding and Shielding: Circuits and Interference, Sixth Edition is an updated guide for circuit design engineers and technicians. It will also serve as a reference for engineers in the semiconductor device industry.
根据提供的引用内容,Grounding DINO是一种结合了DINO和基于Transformer的检测器的模型,用于开放式目标检测。它的输入是图像和文本,输出是多个[物体框,名词短语]对。具体来说,Grounding DINO使用DINO模型对图像和文本进行编码,然后使用基于Transformer的检测器对编码后的特征进行检测,最终输出[物体框,名词短语]对。 下面是一个简单的示例代码,演示如何使用Grounding DINO进行开放式目标检测: ```python import torch from torchvision.models.detection import fasterrcnn_resnet50_fpn from transformers import ViTFeatureExtractor, ViTForImageClassification from transformers.models.dino.modeling_dino import DINOHead # 加载预训练的DINO模型和ViT模型 dino = ViTForImageClassification.from_pretrained('facebook/dino-vit-base') dino_head = DINOHead(dino.config) dino_head.load_state_dict(torch.load('dino_head.pth')) dino.eval() vit_feature_extractor = ViTFeatureExtractor.from_pretrained('google/vit-base-patch16-224') # 加载预训练的Faster R-CNN检测器 model = fasterrcnn_resnet50_fpn(pretrained=True) model.eval() # 输入图像和文本 image = Image.open('example.jpg') text = 'a person riding a bike' # 对图像和文本进行编码 image_features = vit_feature_extractor(images=image, return_tensors='pt')['pixel_values'] text_features = dino_head.get_text_features(text) image_embedding, text_embedding = dino(image_features, text_features) # 使用Faster R-CNN检测器进行目标检测 outputs = model(image_embedding) boxes = outputs[0]['boxes'] labels = outputs[0]['labels'] # 输出[物体框,名词短语]对 for i in range(len(boxes)): print([boxes[i], labels[i]]) ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值