TypeError: div() got an unexpected keyword argument ‘rounding_mode’

报错代码:torch.div(…, …, rounding_mode=“floor”)

mask_idx = torch.div(idx, self.instance_classes, rounding_mode=“floor”)

报错原因: rounding_mode在torch1.8才引入

https://github.com/mit-han-lab/torchsparse/pull/126
torch.div()方法的rounding_mode参数 似乎是torch1.8才引入的,我的torch版本太老了

解决方法:在torch.div()外面再套一层torch.floor()

可以升级torch到1.8以上,但如果不想升级:
根据torch官方文档:
https://pytorch.org/docs/stable/generated/torch.div.html

“floor” - rounds the results of the division down. Equivalent to floor division in Python (the // operator) and NumPy’s np.floor_divide.

TypeError: div() got an unexpected keyword argument ‘rounding_mode’_第1张图片

那我直接再套一层floor代替呗。
这样跑起来和官方的例子一样,完美:
TypeError: div() got an unexpected keyword argument ‘rounding_mode’_第2张图片
最终解决办法:

# mask_idx = torch.div(idx, self.instance_classes, rounding_mode="floor")
mask_idx = torch.floor(torch.div(idx, self.instance_classes)) # modified by Qiao for torch<1.8

你可能感兴趣的:(个人笔记,Python,python,torch)