一.前言
源码地址: 论文相关源码
本片是基于最近比较红的SwinTransformer下的一个子分支做的,所以这篇主要记录我的搭建流程。
os: win10
cuda: 11.4
GPU: RTX3090(30系列显卡最好用最新的cuda, 不然会在编译mmcv-full的时候报错(例如nvcc fatal : Unsupported gpu architecture ‘compute_86‘
)
二.环境搭建
1.安装cuda和对应的cudnn
参考cuda11.4,cudnn8.2.1
2.安装vs2019
参考
因为是自己编译,需要借助vs2019的编译器,从https://visualstudio.microsoft.com/zh-hans/thank-you-downloading-visual-studio/?sku=Community&rel=16直接下载社区版即可,然后在安装的时候需要注意安装一个工作负荷以提供编译器:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210714183941457.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMzNjQyMzQy,size_16,color_FFFFFF,t_70)
安装完成后,使用everything搜索系统中是否存在vcvars64.bat文件,如果有的话直接CMD执行call命令初始化,然后输入cl验证是否安装成功:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210714184004667.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMzNjQyMzQy,size_16,color_FFFFFF,t_70)
3.安装pytorch
直接去pytorch官网:https://pytorch.org/选择合适版本的pytorch,并在CMD中执行官网提供的pip命令即可
4.安装mmcv 和 mmsegmentation
先激活或者新建你的conda环境,例如我的就叫做open-mmlab,注意在win10上装mmcv会比在linux上复杂,对于已经装了mmcv的环境,建议舍弃或者删除mmcv
pip uninstall mmcv
pip uninstall mmcv-full
然后从源码进行安装:
git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
set MMCV_WITH_OPS=1
pip install -e .#这一步时间很长
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210714184928443.JPG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMzNjQyMzQy,size_16,color_FFFFFF,t_70)
接着安装mmsegmentation
pip install git+https://github.com/open-mmlab/mmsegmentation.git
5.拷贝MMSegmentation
git clone https://github.com/open-mmlab/mmsegmentation.git
cd mmsegmentation
pip install -e . # 或者"python setup.py develop"
三.测试
在mmsegmentation中新建一个checkpoints文件夹,里面放置从预训练权重仓库下载下来的权重,然后运行下面程序(图片和视频自行准备)
from mmseg.apis import inference_segmentor, init_segmentor
import mmcv
config_file = 'configs/setr/setr_pup_512x512_160k_b16_ade20k.py'
checkpoint_file = 'checkpoints/setr_pup_512x512_160k_b16_ade20k_20210619_191343-7e0ce826.pth'
# build the model from a config file and a checkpoint file
model = init_segmentor(config_file, checkpoint_file, device='cuda:0')
# test a single image and show the results
img = 'demo/test.jpg' # or img = mmcv.imread(img), which will only load it once
result = inference_segmentor(model, img)
# visualize the results in a new window
model.show_result(img, result, show=True)
# or save the visualization results to image files
# you can change the opacity of the painted segmentation map in (0, 1].
model.show_result(img, result, out_file='result.jpg', opacity=0.5)
# test a video and show the results
video = mmcv.VideoReader('demo/test.mp4')
for i, frame in enumerate(video):
result = inference_segmentor(model, frame)
model.show_result(frame, result, out_file='lbq_test/%s.jpg' % str(i), wait_time=0.1)
# for frame in video:
# result = inference_segmentor(model, frame)
# model.show_result(frame, result, wait_time=1)
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210714185816838.JPG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzMzNjQyMzQy,size_16,color_FFFFFF,t_70)
四.训练
暂时还没训练,最近在过模型。