下载vision mamba github上的项目后,解压,进入文件夹项目,然后配环境
unzip Vim-main.zip
cd Vim-main
conda create -n mamba python=3.10.13
conda activate mamba
pip install torch==2.1.1 torchvision==0.16.1 torchaudio==2.1.1 --index-url https://download.pytorch.org/whl/cu118
pip install -r vim/vim_requirements.txt
这里就不采用官方项目给的pip install -e causal_conv1d>=1.1.0 mamba-1p1p1方法,因为我怎么也安装不成功,经典错误:
“TypeError: Mamba.init() got an unexpected keyword argument ‘bimamba_type’“
“ERROR: causal_conv1d is not a valid editable requirement. It should either be a path to a local project or a VCS URL (beginning with bzr+http, bzr+https, bzr+ssh, bzr+sftp, bzr+ftp, bzr+lp, bzr+file, git+http, git+https, git+ssh, git+git, git+file, hg+file, hg+http, hg+https, hg+ssh, hg+static-http, svn+ssh, svn+http, svn+https, svn+svn, svn+file).”
“ImportError: libcudart.so.12: cannot open shared object file: No such file or directory”
所以直接从whl文件安装
wget https://github.com/Dao-AILab/causal-conv1d/releases/download/v1.1.3.post1/causal_conv1d-1.1.3.post1+cu118torch2.1cxx11abiFALSE-cp310-cp310-linux_x86_64.whl
wget https://github.com/state-spaces/mamba/releases/download/v1.1.1/mamba_ssm-1.1.1+cu118torch2.1cxx11abiFALSE-cp310-cp310-linux_x86_64.whl
pip install causal_conv1d-1.1.3.post1+cu118torch2.1cxx11abiFALSE-cp310-cp310-linux_x86_64.whl
pip install mamba_ssm-1.1.1+cu118torch2.1cxx11abiFALSE-cp310-cp310-linux_x86_64.whl
然后用官方项目里的mamba_ssm替换安装在conda环境里的mamba_ssm
# 用conda env list 查看刚才安装的mamba环境的路径,我的mamba环境在/home/liyhc/anaconda3/envs/mamba
conda env list
#用官方项目里的mamba_ssm替换安装在conda环境里的mamba_ssm
cp -rf mamba-1p1p1/mamba_ssm /home/liyhc/anaconda3/envs/mamba/lib/python3.10/site-packages
为了快速体验效果,直接用CIFAR数据集测试,把datasets.py里的CIFAR数据集设置为download=True,然后在运行:
CUDA_VISIBLE_DEVICES=0 torchrun --master_port=6666 --nproc_per_node=1 main.py \
--model vim_small_patch16_224_bimambav2_final_pool_mean_abs_pos_embed_with_midclstok_div2 --batch-size 2 \
--drop-path 0.05 --weight-decay 0.05 --lr 1e-3 --num_workers 1 \
--data-set CIFAR \
--data-path /media/amax/c08a625b-023d-436f-b33e-9652dc1bc7c0/DATA/liyuehang/Vim-main/vim/cifar-100-python \
--output_dir ./output/vim_small_patch16_224_bimambav2_final_pool_mean_abs_pos_embed_with_midclstok_div2 \
--no_amp
效果展示