代码地址:https://github.com/czczup/ViT-Adapter.git
一、配置环境
在恒源云上租用服务器,配置如下:
使用pytorch==1.9.0,cuda==11.1.0,python==3.8
操作如下:
# recommended environment: torch1.9 + cuda11.1
#创造一个虚拟环境并且激活
conda create --name openmmlab python=3.8 -y
conda activate openmmlab
#安装对应的torch、torchvision、torchaudio
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
#安装对应的mmcv-full
pip install mmcv-full==1.4.2 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.9.0/index.html
#安装其他库
pip install timm==0.4.12
pip install mmdet==2.22.0 # for Mask2Former
pip install mmsegmentation==0.20.2
pip install spicy
sudo apt install libglib2.0-dev
#clone到服务器中
cd hy-tmp
git clone https://gitclone.com/github.com/czczup/ViT-Adapter.git
#然后进入ViT-Adapter-main/segmentation中
cd /hy-tmp/ViT-Adapter/segmentation
ln -s ../detection/ops ./
cd ops
bash ./make.sh
到这如果都没有问题的话,那环境配置就成功了。
二、训练过程
1.数据集准备
使用的是ADE20k的数据集
数据集下载链接:https://pan.baidu.com/s/1D6yI20dp64OGesYZqevC4w
提取码:vit8
然后将数据集上传到ViT-Adapter/segmentation/data/ade文件夹中并解压
2.预训练模型准备
使用的是beit_large_patch16_224_pt22k_ft22k.pth
预训练模型下载链接:https://pan.baidu.com/s/1GIK-R5swujwzpY0Ulmi9kw
提取码:vit8
然后将预训练模型上传到ViT-Adapter/segmentation/pretrained文件夹中
3.参数设置
使用的是ViT-Adapter/segmentation/configs/ade20k文件夹中的
mask2former_beit_adapter_large_640_160k_ade20k_ms.py
在146行可以修改batch size(我设置的是2)
同时还需要将train.py代码进行修改,主要是修改config、work-dir和checkpoint的路径
根据自己的路径修改25-28行
parser.add_argument('config', default='hy-tmp/ViT-Adapter/segmentation/configs/ade20k/mask2former_beit_adapter_large_640_160k_ade20k_ms.py',help='train config file path')
parser.add_argument('--work-dir',default='output',help='the dir to save logs and models')
parser.add_argument(
'--load-from',default='pretrained/beit_large_patch16_224_pt22k_ft22k.pth',help='the checkpoint file to load weights from')
改完这些地方就可以进行训练了
训练的命令是:最后的数字是gpu数量,可自行调整。
bash ./dist_train.sh configs/ade20k/mask2former_beit_adapter_large_640_160k_ade20k_ms.py 1
三、训练结果
代码还正在跑,后续会将训练结果及预测结果更新