代码地址:GRES: Generalized Referring Expression Segmentation代码地址
安装
环境
The code is tested under CUDA 11.8, Pytorch 1.11.0 and Detectron2 0.6.
步骤
1. Install Detectron2 following the manual
安装要求
1、Linux or macOS with Python ≥ 3.7
2、PyTorch ≥ 1.8 and torchvision that matches the PyTorch installation. Install them together at pytorch.org to make sure of this
3、OpenCV is optional but needed by demo and visualization
安装命令
python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'
# (add --user if you don't have permission)
# Or, to install it from a local clone:
git clone https://github.com/facebookresearch/detectron2.git
python -m pip install -e detectron2
# On macOS, you may need to prepend the above commands with a few environment variables:
CC=clang CXX=clang++ ARCHFLAGS="-arch x86_64" python -m pip install ...
-
Run
sh make.sh
undergres_model/modeling/pixel_decoder/ops
-
Install other required packages:
pip install -r requirements.txt
-
Prepare the dataset following
datasets/DATASET.md
验证
python train_net.py \
--config-file configs/referring_swin_base.yaml \
--num-gpus 8 --dist-url auto --eval-only \
MODEL.WEIGHTS [path_to_weights] \
OUTPUT_DIR [output_dir]
训练
1、Firstly, download the backbone weights (swin_base_patch4_window12_384_22k.pkl
) and convert it into detectron2 format using the script:
wget https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_base_patch4_window12_384_22k.pth
python tools/convert-pretrained-swin-model-to-d2.py swin_base_patch4_window12_384_22k.pth swin_base_patch4_window12_384_22k.pkl
这段代码的含义是:
- 使用
wget
命令从指定的 URL 下载名为swin_base_patch4_window12_384_22k.pth
的文件。 - 使用 Python 脚本
convert-pretrained-swin-model-to-d2.py
将下载的swin_base_patch4_window12_384_22k.pth
文件转换为swin_base_patch4_window12_384_22k.pkl
文件。
这个过程涉及下载预训练模型文件并将其转换为不同的格式,可能是为了后续在某个特定的深度学习框架或应用中使用。
2、Then start training:
python train_net.py \
--config-file configs/referring_swin_base.yaml \
--num-gpus 8 --dist-url auto \
MODEL.WEIGHTS [path_to_weights] \
OUTPUT_DIR [path_to_weights]
这段代码的含义是:
- 使用 Python 运行名为
train_net.py
的脚本。 - 使用
--config-file
参数指定配置文件为configs/referring_swin_base.yaml
。 - 使用
--num-gpus 8
参数指定使用 8 个 GPU 进行训练。 - 使用
--dist-url auto
参数指定分布式训练的 URL 设置为自动配置。 - 使用
MODEL.WEIGHTS
参数指定模型的权重路径为[path_to_weights]
,这里需要替换为实际的权重文件路径。 - 使用
OUTPUT_DIR
参数指定输出目录为[path_to_weights]
,这里也需要替换为实际的输出目录路径。
这段代码的作用是使用指定的配置文件对模型进行训练,同时指定了使用的 GPU 数量、权重路径和输出目录
Note: You can add your own configurations subsequently to the training command for customized options. For example:
SOLVER.IMS_PER_BATCH 48
SOLVER.BASE_LR 0.00001
For the full list of base configs, see configs/referring_R50.yaml
and configs/Base-COCO-InstanceSegmentation.yaml