报错问题:
.py:226: UserWarning: floordiv is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the ‘trunc’ function NOT ‘floor’). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode=‘trunc’), or for actual floor division, use torch.div(a, b, rounding_mode=‘floor’).coord_h = int((center_h / upsampled_size[0]) // (1. / num_grid))
错误分析
向下取整运算符 “//” 已经被废弃,使用torch.div()来替代
torch.div(a,b,rounding_mode='floor') ## 向下取整
torch.div(a,b,rounding_mode='trunc') ## 四舍五入
解决问题
原文:
coord_w = int((center_w / upsampled_size[1]) // (1. / num_grid))
coord_h = int((center_h / upsampled_size[0]) // (1. / num_grid))
改成:
coord_w = int(torch.div((center_w / upsampled_size[1]), (1. / num_grid), rounding_mode='floor'))
coord_h = int(torch.div((center_h / upsampled_size[0]), (1. / num_grid), rounding_mode='floor'))