Swin-Ttransformer Object Detection environment configuration and training

insert image description here

Swin-Ttransformer Object Detection environment configuration and training

Source code address: https://github.com/SwinTransformer/Swin-Transformer-Object-Detection
Reference directory:
https://www.bilibili.com/video/BV1eu41197qK/?spm_id_from=333.788
https://www.bilibili.com /video/BV1Y3411676J?spm_id_from=333.337.search-card.all.click

Simply record the steps of installing, running, and GPU training swin-t source code.

Environment configuration

  1. First get the source code from the official website: https://github.com/SwinTransformer/Swin-Transformer-Object-Detection
git clone https://github.com/SwinTransformer/Swin-Transformer-Object-Detection.git
  1. Create a new conda environment and install pytorch. I use python==3.6.13 and pytorch==1.7.1 and torchvision==0.8.2. There are
    many tutorials for installing pytorch, so I won’t go into details here. Pay attention to the matching of the GPU version with the cuda driver . Let me put the verification method here:
    $ pythonenter the python command line
    import torchand it is ok if there is no error.
    If it is the GPU version and you need to enter torch.cuda.is_available()True, it is successful. (available() is followed by parentheses )
    insert image description here

  2. Install timm according to the official website

 pip install timm==0.4.12
  1. The installation of mmcv-full failed directly pip install mmcv-full==1.4.0, but the installation with mim was successful (the success rate of mim installation is still quite high). I saw other bloggers say that the 1.4.5 version is easy to step on the pit.
pip install openmim
mim install mmcv-full==1.4.0      #(这部分会下载opencv-python,就不需要单独装了)
  1. Next, install according to the official website
pip install -r requirements.txt
python setup.py develop
  1. It’s okay not to install apex for the time being. If you only use cpu, you don’t need to install apex at all. But I installed it directly:
git clone https://github.com/NVIDIA/apex        #(git clone的时候可能会失败,多试几次就好了。)
cd apex
pip install -v --disable-pip-version-check --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./        #(这句失败) 
pip install -v --no-cache-dir ./     #(我是用这句成功的,在GPU上这句的成功率高)

At this point the installation is over.

demo

Try running demo.py:
command:

python demo/image_demo.py demo/demo.jpg configs/swin/mask_rcnn_swin_tiny_patch4_window7_mstrain_480-800_adamw_1x_coco.py ./mask_rcnn_swin_tiny_patch4_window7_1x.pth

Explain, where:
configs/swin/mask_rcnn_swin_tiny_patch4_window7_mstrain_480-800_adamw_1x_coco.pyis the configuration file
./mask_rcnn_swin_tiny_patch4_window7_1x.pthis the pre-training model parameters, I put it in the current directory, and write it wherever the path is placed.
The pre-training model is downloaded from the official website, and I downloaded it
insert image description here

Running results: It can be seen that the detection accuracy is very high, and the edge is accurately grasped.
insert image description here

COCO training

Download COCO dataset: Official website address
But the official website is very difficult to download, and the webpage can’t be opened.
The following address can be downloaded directly by copying to the webpage:
http://images.cocodataset.org/zips/train2017.zip
http://images. cocodataset.org/annotations/annotations_trainval2017.zip
http://images.cocodataset.org/zips/val2017.zip
http://images.cocodataset.org/annotations/stuff_annotations_trainval2017.zip
http://images.cocodataset.org/zips /test2017.zip
http://images.cocodataset.org/annotations/image_info_test2017.zip
Generally, you only need to download the first three, including training and verification images and labels.

Next, we need to make some small modifications to the code, mainly ① the path of the data set, and ② if the GPU cannot be moved, the scaling size can be modified. The above two points are enough, and other debugging can be done later.

  1. Open the configuration file swin-T-DE/configs/swin/mask_rcnn_swin_tiny_patch4_window7_mstrain_480-800_adamw_1x_coco.py
    (I modified Swin-Transformer-Object-Detection to swin-T-DE) and

    you can see that the coco_instance.py file is called. This is the target segmentation. It doesn't matter. Let's use this first. Or students with obsessive-compulsive disorder can also modify it to coco_detection.py.

Open whichever file is called ( coco_instance.pyor coco_detection.py), you can see the second line, the data set path data_root, and change it to the path where you store the data set
insert image description here

The following is the path to find the training and verification sets, refer to your own path. All of mine are placed in the COCO folder, and the annotations_trainval2017.zip is decompressed and the file name is annotations.
insert image description here
insert image description here

OK, you can already train here, if you are afraid that the GPU will not be able to carry it, then look at the second point

  1. coco_instance.py①As in 1, modify ( or ) in which file to call coco_detection.py, and change the zoom scale to (256, 256). There are two places in total, which should be the eighth and nineteenth rows. ② Modify the three scales in
    the configuration file used in 1 . mask_rcnn_swin_tiny_patch4_window7_mstrain_480-800_adamw_1x_coco.pyIt has been circled in the picture.
    insert image description here
    insert image description here

Here's what I'm doing halfway through my training:
insert image description here

The training will take about two days.


Finally, I wish you all success in scientific research, good health, and success in everything~

Guess you like

Origin blog.csdn.net/qq_45122568/article/details/125043314