问题怎么定位的呢,把报错信息一股脑甩给chatgpt,问他什么意思,他就反馈说“在标准的Python库中,div() 函数不接受 rounding_mode 参数。”(虽然这个问题也不难,但是改偷的懒还是要偷)
问题再现
Traceback (most recent call last):
File "first_stage.py", line 447, in <module>
main()
File "first_stage.py", line 127, in main
return main_worker(args, logger)
File "first_stage.py", line 132, in main_worker
model = build_LEModel(args)
File "/home/algroup/chenao/SPML-LAC-master/lib/models/LEModel.py", line 135, in build_LEModel
backbone = build_backbone(args)
File "/home/algroup/chenao/SPML-LAC-master/lib/models/backbone.py", line 179, in build_position_encoding
position_embedding = PositionEmbeddingSine(N_steps, normalize=True, maxH=args.img_size // downsample_ratio, maxW=args.img_size // downsample_ratio)
File "/home/algroup/chenao/SPML-LAC-master/lib/models/backbone.py", line 146, in __init__
pe = self._gen_pos_buffer()
File "/home/algroup/chenao/SPML-LAC-master/lib/models/backbone.py", line 159, in _gen_pos_buffer
dim_t = self.temperature ** (2 * (torch.div(dim_t, 2, rounding_mode='floor')) / self.num_pos_feats)
TypeError: div() got an unexpected keyword argument 'rounding_mode'
原因是torch=1.7.0
不支持该参数,要到1.8以后才行;
解决方案如下:两种方法选一种
1. 升级版本
安装的是pytorch-gpu版本,要和显卡对应的,我懒得折腾;
2. 在外面套一层torch.floor
torch.floor(torch.div(...))
结果是一样的;
参考
官网介绍torch.div()
TypeError: div() got an unexpected keyword argument ‘rounding_mode’ 一位老哥的博客