【vision transformer】LETR论文解读及代码实战(二)

LETR: Line Segment Detection Using Transformers without Edges

基于vision-transformer/DETR 提取wireframe的网络框架,截止日前实现了sota性能。

论文:https://arxiv.org/abs/2101.01909

代码:https://github.com/mlpc-ucsd/LETR

项目实战:

(1)构建环境:

git clone https://github.com/mlpc-ucsd/LETR.git
mkdir -p data
mkdir -p evaluation/data
mkdir -p exp


conda create -n letr 
conda activate letr
conda install -c pytorch pytorch torchvision
conda install cython scipy
pip install -U 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
pip install docopt

(2)准备数据,wireframe raw 数据集和YorkUrban 数据集。

(3)模型训练

# Usage: bash script/*/*.sh [exp name]
bash script/train/a0_train_stage1_res50.sh  res50_stage1 # LETR-R50  
bash script/train/a1_train_stage1_res101.sh res101_stage1 # LETR-R101 

调试过程及问题解决

 (1)ImportError: cannot import name '_new_empty_tensor'

Traceback (most recent call last):
  File "src/main.py", line 13, in <module>
    import datasets
  File "/home/wsx/0A_DATA/LETR/src/datasets/__init__.py", line 5, in <module>
    from .coco import build as build_coco
  File "/home/wsx/0A_DATA/LETR/src/datasets/coco.py", line 10, in <module>
    import datasets.transforms as T
  File "/home/wsx/0A_DATA/LETR/src/datasets/transforms.py", line 18, in <module>
    from util.misc import interpolate
  File "/home/wsx/0A_DATA/LETR/src/util/misc.py", line 22, in <module>
    from torchvision.ops import _new_empty_tensor
ImportError: cannot import name '_new_empty_tensor'

solution:

定位报错文件中File "/home/wsx/0A_DATA/LETR/src/util/misc.py", line 22, in <module>,将报错文件misc.py中的关于“_new_empty_tensor”的内容注释掉,如下:

# if float(torchvision.__version__[:3]) < 0.7:
    # from torchvision.ops import _new_empty_tensor
    # from torchvision.ops.misc import _output_size

(2)再运行:ImportError: cannot import name '_LinearWithBias'

Traceback (most recent call last):
  File "src/main.py", line 17, in <module>
    from models import build_model
  File "/home/wsx/0A_DATA/LETR/src/models/__init__.py", line 2, in <module>
    from .letr import build
  File "/home/wsx/0A_DATA/LETR/src/models/letr.py", line 15, in <module>
    from .transformer import build_transformer
  File "/home/wsx/0A_DATA/LETR/src/models/transformer.py", line 16, in <module>
    from .multi_head_attention import MultiheadAttention
  File "/home/wsx/0A_DATA/LETR/src/models/multi_head_attention.py", line 11, in <module>
    from torch.nn.modules.linear import _LinearWithBias
ImportError: cannot import name '_LinearWithBias'

solution:

定位出错的文件,  File "/home/wsx/0A_DATA/LETR/src/models/multi_head_attention.py", line 11, in <module>,将 line 11 的 # from torch.nn.modules.linear import _LinearWithBias 注释掉,
改为 from torch.nn.modules.linear import Linear,如下

# from torch.nn.modules.linear import _LinearWithBias
from torch.nn.modules.linear import Linear

同时将引用部分 multi_head_attention.py 的440行 ,

self.out_proj = _LinearWithBias(embed_dim, embed_dim)

改为:

self.out_proj = Linear(embed_dim, embed_dim)

(3)再运行,RuntimeError: The NVIDIA driver on your system is too old (found version 10010).

Traceback (most recent call last):
  File "src/main.py", line 214, in <module>
    main(args)
  File "src/main.py", line 21, in main
    utils.init_distributed_mode(args)
  File "/home/wsx/0A_DATA/LETR/src/util/misc.py", line 421, in init_distributed_mode
    torch.cuda.set_device(args.gpu)
  File "/home/wsx/anaconda3/envs/letr/lib/python3.6/site-packages/torch/cuda/__init__.py", line 264, in set_device
    torch._C._cuda_setDevice(device)
  File "/home/wsx/anaconda3/envs/letr/lib/python3.6/site-packages/torch/cuda/__init__.py", line 172, in _lazy_init
    torch._C._cuda_init()
RuntimeError: The NVIDIA driver on your system is too old (found version 10010). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx Alternatively, go to: https://pytorch.org to install a PyTorch version that has been compiled with your version of the CUDA driver.

solution:

查看pytorch 版本

(letr) wsx@hello:~/0A_DATA/LETR$ python
Python 3.6.4 |Anaconda, Inc.| (default, Mar 13 2018, 01:15:57) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.__version__)
1.9.0+cu102

查看CUDA版本

nvidia-smi

 pytorch 是cuda10.2的,机子的cuda是10.1的,故卸载pytorch ,重装pytorch+cuda,

下面pip安装可省略,直接用conda  

pip3 install torch==1.8.1+cu101 torchvision==0.9.1+cu101  -f https://download.py torch.org/whl/cu101/torch_stable.html
(letr) wsx@hello:~/0A_DATA/LETR$ python -m pip install torch==1.8.1+cu101 torchvision==0.9.1+cu101
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
ERROR: Could not find a version that satisfies the requirement torch==1.8.1+cu101 (from versions: 1.0.0, 1.0.1, 1.0.1.post2, 1.1.0, 1.2.0, 1.3.0, 1.3.1, 1.4.0, 1.5.0, 1.5.1, 1.6.0, 1.7.0, 1.7.1, 1.8.0, 1.8.1, 1.9.0, 1.9.1, 1.10.0, 1.10.1, 1.10.2)
ERROR: No matching distribution found for torch==1.8.1+cu101

 conda 安装

 conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=10.1 -c pytorch

大功告成:

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LeapMay

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值