在服务器docker中复现swin transformer

拉取一个进行

dicker pull pytorch/pytorch:1.8.0-cuda11.1-cudnn8-devel

创建一个镜像 python=3.8 pytorch=1.8.0 cuda11.1 cudnn8

docker run -d -v /home/chain/物理机的文件夹/:/容器里的文件夹/ --name 容器名字 --gpus all --shm-size 16G -it -p 6006:6006 pytorch/pytorch:1.8.0-cuda11.1-cudnn8-devel /bin/bash 

-p 是映射,不需要可以删除

比如:

docker run -d -v /home/chain/CaoJinhao/:/workspace_disk/ --name cjh-swin --gpus all --shm-size 16G -it -p 6006:6006 pytorch/pytorch:1.8.0-cuda11.1-cudnn8-devel /bin/bash 

pythorch的安装

pip3 install torch==1.8.2+cu111 torchvision==0.9.2+cu111 torchaudio==0.8.2 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html

安装一些其他的包

pip install cython matplotlib opencv-python timm -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

安装mmcv

pip install mmcv-full==1.3.17

查看是否安装

pip list

安装vim

更新apt-get

apt-get update

安装vim

apt-get install vim

查看vim能否使用

vi -v

退出信息界面请安ESC 然后:q! 回车

安装mmdetection

1.获取mmdetection

git clone -b v2.20.0 GitHub - open-mmlab/mmdetection: OpenMMLab Detection Toolbox and Benchmark

2.进入mmdetection-2.20.0

cd mmdetection-2.20.0

vim /requirements/tests.txt 

按 i

#-e git+https://github.com/open-mmlab/mmtracking#egg=mmtrack 把这行注释掉

按esc :wq! 强制保存退出

3.安装需求环境

pip install -r requirements.txt -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

4.安装

python setup.py develop

5.查看安装成功

pip list

安装apex

1.进入 https://github.com/NVIDIA/apex,找到版本号22.03下载,将文件移入容器镜像文件夹中。

2.进入文件夹 cd apex

4.安装 python setup.py install

安装Swin-Transformer-Object-Detection
1.下载
git clone GitHub - SwinTransformer/Swin-Transformer-Object-Detection: This is an official implementation for "Swin Transformer: Hierarchical Vision Transformer using Shifted Windows" on Object Detection and Instance Segmentation.

2.进入文件夹

cd Swin-Transformer-Object-Detection

3.安装需求

python setup.py develop

测试

1.下载权重mask_rcnn_swin_tiny_patch4_window7_1x.pth

在这个https://github.com/SwinTransformer/Swin-Transformer-Object-Detection中下载权重,

移动到Swin-Transformer-Object-Detection目录下。

2.修改可视化,因为在服务器中可视化不可见,需要把测试的结果保存到文件夹中,修改demo/image_demo.py。

from mmdet.apis import init_detector, inference_detector



config_file = 'configs/swin/mask_rcnn_swin_tiny_patch4_window7_mstrain_480-800_adamw_3x_coco.py'  #配置文件路径

checkpoint_file = 'mask_rcnn_swin_tiny_patch4_window7.pth'                                     #权重文件路径

device = 'cuda:0'

# init a detector

model = init_detector(config_file, checkpoint_file, device=device)

# inference the demo image

img = 'demo/demo.jpg'

result = inference_detector(model, 'demo/demo.jpg')

model.show_result(img, result)

model.show_result(img, result, out_file='demo/demo_result.jpg')

执行测试

python demo/image_demo.py demo/demo.jpg configs/swin/mask_rcnn_swin_tiny_patch4_window7_mstrain_480-800_adamw_3x_coco.py mask_rcnn_swin_tiny_patch4_window7.pth

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值