Segment-Everything-Everywhere-All-At-Once项目部署记录

项目地址

https://github.com/UX-Decoder/Segment-Everything-Everywhere-All-At-Once

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

本次部署不使用docker,而是直接部署到本地
注意:请看完本文章,以了解部署实际需要的软件版本

环境部署过程

https://github.com/IDEA-Research/Grounded-Segment-Anything#install-without-docker

注意CUDA位置

1
2
export CUDA_HOME=/path/to/cuda-11.3/
#这个为自己的CUDA位置

部署到OSX出现问题

注意Install osx:

1
2
3
git submodule update --init --recursive
cd grounded-sam-osx && bash install.sh
#install.sh可能会出现问题一直卡在building

查看出问题的脚本,一条条执行查找问题

1
2
3
4
5
6
#install.sh文件
#!/bin/bash
pip install openmim
mim install mmcv-full==1.7.1 #Building...
pip install -r requirements.txt
cd transformer_utils && python setup.py install

主要问题出现在mmcv-full上
查看torch版本

1
python -c 'import torch;print(torch.__version__)'

输出

1
2.0.1+cu117

解决方法

官方文档
https://mmcv.readthedocs.io/zh_CN/1.x/get_started/installation.html

官方文档中提到
如果发现上述的安装命令没有使用预编译包(以 .whl 结尾)而是使用源码包(以 .tar.gz 结尾)安装,则有可能是我们没有提供和当前环境的 PyTorch 版本、CUDA 版本相匹配的 mmcv-full 预编译包,此时,你可以源码安装 mmcv-full。
所以官方没有提供与当前环境匹配的预编译包,执行的时候需要自己编译,但是等了半个多小时依然没有编译完成,所以我这里直接更换环境。

原环境: 2.0.1+cu117
更改后: 1.13.1+cu117
这里是改用pytorch==1.13.1

INSTALLING PREVIOUS VERSIONS OF PYTORCH

https://pytorch.org/get-started/previous-versions/

本次使用cuda11.7,我是使用pip安装,根据个人需求选择

1
2
3
4
5
6
7
conda
# CUDA 11.7
conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.7 -c pytorch -c nvidia

wheel
# CUDA 11.7
pip install torch==1.13.0+cu117 torchvision==0.14.0+cu117 torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/cu117

完成后执行bash install.sh即可.
OSX安装完毕.

部署Tag2Text出现问题

Install Tag2Text:

1
2
git submodule update --init --recursive
cd Tag2Text && pip install -r requirements.txt

执行pip install -r requirements.txt出现问题

1
2
3
4
5
6
7
8
9
...
running build_ext
running build_rust
error: can't find Rust compiler
...
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for tokenizers
Failed to build tokenizers
ERROR: Could not build wheels for tokenizers, which is required to install pyproject.toml-based projects

根据提示来看是没有找到Rust的编译环境
参考文档:https://learnku.com/rust/wikis/29019
本次部署环境在Linux中,Windows同理,安装Rust编译环境并且添加到系统的环境变量即可.

1
curl https://sh.rustup.rs -sSf | sh

选择1,等待安装完成后的提示

1
2
3
4
5
6
7
8
9
10
  stable-x86_64-unknown-linux-gnu installed - rustc 1.70.0 (90c541806 2023-05-31)

Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, run:
source "$HOME/.cargo/env"

执行命令,将rust环境添加到用户环境变量中

1
source "$HOME/.cargo/env"

验证环境

1
2
user1@tesla-m40:~$ rustc -V
rustc 1.70.0 (90c541806 2023-05-31)

重新安装Tag2Text的pip依赖

1
pip3 install -r requirements.txt

这里可以看到编译完成,等待install完成

1
2
3
Building wheel for tokenizers (pyproject.toml) ... done
...
Successfully installed fairscale-0.4.4 pycocoevalcap-1.2 sacremoses-0.0.53 timm-0.4.12 tokenizers-0.10.3 transformers-4.15.0

Tag2Text安装完成

部署项目中的DEMO

额…部署之后忘记录了。运行webui的脚本就可以了。
运行后查看nvidia-smi,显存大概占用8G.