Grounded-Segment-Anything 本地测试,win11+Anaconda3+torch==1.10.0+torchvision==0.11.0环境

做这玩意比较郁闷,错误一大堆,搞了快一周,才勉强调通额,终于看到点效果

写出来,以便自己总结,也给大家一个参考,亲测有效,直接上干货,后面还有最新版的python =3.11.4 的配套安装,已经成功,看下一篇文章

一、安装环境:

Anaconda3-2020.07-Linux-x86_64  (Index of /anaconda/archive/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
python =3.8.3
torch==1.10.0
torchvision==0.11.0
torchaudio==0.10.0

二、安装Anaconda

Anaconda3-2023.07-2-Windows-x86_64

windows11 直接安装,没啥可说的,一直next,最后一步,两个都别选,选了也米关系,就是闹心啊

三、配置环境变量

C:\Users\Administrator\anaconda3;

C:\Users\Administrator\anaconda3\Scripts;

C:\Users\Administrator\anaconda3\Library\bin;

C:\Users\Administrator\anaconda3\Library\mingw-w64\bin

这个大家都懂的,多句嘴,系统变量里的path,

配置完成cmd重启一下就行了,电脑不需要重启

四、配置清华源

开始配置了阿里的,效果不明显,该超时还是超时,这个不错

删除之前的镜像源,恢复默认状态
conda config --remove-key channels

#添加镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2

#显示检索路径
conda config --set show_channel_urls yes

#显示镜像通道
conda config --show channels

五、Grounded-Segment-Anything源码下载,然后一顿操作

因为这个需要c++的什么支持,网上有很多解决办法,大部分都没说到点子上

我有一次安装只是安装了几个包,就可以了,但是还是安装一下rustup-init,这是个安装程序,

直接运行即可,其实就是安装c++的什么支持,可以先安装,后面python =3.11.4环境时时必须装的

1、下载源码(下载之前记得安装git)


git clone https://github.com/IDEA-Research/Grounded-Segment-Anything.git

获取osx,Tag2Text:

修改下Grounded-Segment-Anything目录下的.gitmodules
改为

[submodule "grounded-sam-osx"]
    path = grounded-sam-osx
    url = https://github.com/linjing7/grounded-sam-osx.git
[submodule "VISAM"]
    path = VISAM
    url = https://github.com/BingfengYan/VISAM.git
[submodule "Tag2Text"]
    path = Tag2Text
    url = https://github.com/xinyu1205/recognize-anything.git

然后执行

cd C:\work\Grounded-Segment-Anything
git submodule update --init --recursive

2、创建虚拟环境

conda create -n env_123==3.8.3

进入虚拟环境之前

conda init cmd.exe
conda init powershell

否则会出错

conda activate env_123

3、安装torch+torchvision

pip install torch==1.10.0+cu113 torchvision==0.11.0+cu113 torchaudio==0.10.0 -f https://download.pytorch.org/whl/torch_stable.html
 

4、安装Grounded-Segment-Anything

安装之前,来几个包

conda install libpython m2w64-toolchain -c msys2
conda install -c conda-forge pycocotools(有效)

cd D:\work\Grounded-Segment-Anything

装Segment Anything:
python -m pip install -e segment_anything

安装GroundingDINO:
python -m pip install -e GroundingDINO

安装diffusers:
pip install --upgrade diffusers[torch]

'bash' 不是内部或外部命令,也不是可运行的程序或批处理文件,安装m2-base解决

conda install m2-base

cd grounded-sam-osx && bash install.sh
出错,安装scipy scipy
conda install scipy
继续bash install.sh

bash install.sh 有时候在运行期间会出现numpy的问题,进anaconda3\\envs\\env_grounded_segment_anything\\lib\\site-packages 将numpy*****两个文件夹删掉即可,重新来过即可

Install RAM & Tag2Text:

cd Tag2Text && pip install -r requirements.txt

回到项目目录

cd D:\work\Grounded-Segment-Anything

pip install  -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

六、测试

下载检测点,太大太大

groundingdino_swint_ogc.pth
sam_vit_h_4b8939.pth
sam_hq_vit_h.pth
ram_swin_large_14m.pth 
tag2text_swin_14m.pth 

只测试一个,后面升级py3.11后的会测试详细一点,我就喜欢用新的开发环境

运行

python grounding_dino_demo.py

运行之前干点活,进去修改

无gpu,将DEVICE 值改为 cpu
有gpu,无需修改参数

有些问题,大家参考

问题一:遇到错误
ModuleNotFoundError: No module named 'chardet'

pip install chardet -i https://pypi.tuna.tsinghua.edu.cn/simple

问题二:遇到警告:

UserWarning: torch.meshgrid: in an upcoming release, it will be required to …

在报错的文件中将

return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
1
修改为

return _VF.meshgrid(tensors, **kwargs, indexing = ‘ij’) # type: ignore[attr-defined]

问题三
ValueError: Connection error, and we cannot find the requested files in the cached path. Please try again or make sure your Internet connection is on.

这问题时模型太大,下载超时了很难啊,自己下下来放在本地

下载地址    bert-base-uncased at main (huggingface.co)

按需下载,我留了5个文件,听说只要3个,没有去细究

config.json,pytorch_model.bin,vocab,tokenizer_config.json,tokenizer.json

在Grounded-Segment-Anything下建个目录bert-base-uncased,你懂的,放进去就可以了

再运行

python grounding_dino_demo.py

如果不出错,运行的结果在

cd D:\work\Grounded-Segment-Anything目录下的annotated_image.jpg就是结果,

grounding_dino_demo.py可以自己看看,文字可改改

结束了,谢谢大家,最新的在后面,已经调试通过了,整理后给大家参考,

错误又不一样了

就是这效果,感觉还可以啊

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值