GRES: Generalized Referring Expression Segmentation代码复现

代码地址: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 ...
  1. Run sh make.sh under gres_model/modeling/pixel_decoder/ops
    在这里插入图片描述

  2. Install other required packages: pip install -r requirements.txt

  3. 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

这段代码的含义是:

  1. 使用 wget 命令从指定的 URL 下载名为 swin_base_patch4_window12_384_22k.pth 的文件。
  2. 使用 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]

这段代码的含义是:

  1. 使用 Python 运行名为 train_net.py 的脚本。
  2. 使用 --config-file 参数指定配置文件为 configs/referring_swin_base.yaml
  3. 使用 --num-gpus 8 参数指定使用 8 个 GPU 进行训练。
  4. 使用 --dist-url auto 参数指定分布式训练的 URL 设置为自动配置。
  5. 使用 MODEL.WEIGHTS 参数指定模型的权重路径为 [path_to_weights],这里需要替换为实际的权重文件路径。
  6. 使用 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

  • 41
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值