PyTorch Warning uint8 to bool
问题
报错如下:
warning: indexing with dtype torch.uint8 is now deprecated, please use a dtype torch.bool instead. (function expandTensors)
虽然只是warning,但是数据量一大就会导致比如 OSError: [Errno 5] Input/output error 导致Terminal 崩溃,所以还是要解决一下。
原因
pytorch 的老版本是没有 bool 的,都是用 uint8 来代替 bool 使用,然后在某一新版本是支持了 torch.bool ,所以就报 warning 希望大家改一改代码
解决
之前试过 python -W ignore 没有用,把所有出现 dtype=torch.uint8 改成 bool 也没用,还是得从根源上来治:
grep -r uint8 .找到所有出现uint8的地方- numpy 的最后加一个
.bool() - pytorch 的直接改成
dtype=torch.bool就行