神奇的bug
litchi&&mango
这个作者很懒,什么都没留下…
展开
-
终端中添加python环境变量
在pycharm中因为是直接把整个文件导入了进去,所以可以自由import文件中的自定义包。但是终端的话,如果想要在某一.py文件里import同一根文件夹的包的话,就还需要进行python环境变量的添加,否则会出现形如 ModuleNotFoundError: No module named 'pymic' 这样无法找到对应包的bug; 解决方法 若文件目录如上图所示,想在运行deform.py时调用transform3d,即在deform.py中有 # deform.py from pymic.io原创 2022-01-07 11:03:29 · 905 阅读 · 3 评论 -
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace o
又是一个莫名其妙的bug,搞了我一下午。。 这样有问题: attention_vector = self.softmax(attentions) 然后这样就OK了: attention_vector = self.softmax(attentions).clone() 加了个.clone()就行了。。。 (看好多博客说无非就是赋值问题,如a+=b是不行的,但我这样的确实没见过) 如果梯度有问题的话可以用这个来检查: with torch.autograd.set_detect_anomaly(True)原创 2021-11-09 19:43:14 · 122 阅读 · 0 评论 -
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace o
又一个折腾了我半天(真·半天)的bug, 而且我还弄了俩不同的导致这错误的bug: 错误原因就两种,一种是nn.ReLU()的inplace,另外一种是赋值的时候出错,如a += 1要改为a = a + 1等; (1) self.relu = nn.ReLU(inplace=True) 得把某些地方的inplace改为False,否则不支持反向传播(挺神奇的) (2) attention = self.softmax(attentions) 检查这种bug有一种专门的方法,就是在后面加个.clone()原创 2021-09-09 21:01:56 · 127 阅读 · 0 评论 -
RuntimeError: non-positive stride is not supported
应该是遇到过的最离谱的bug。。。。。 def __init__(self, in_channel, out_channel, group=32, s=1, n=0): 这样是错的; def __init__(self, in_channel, out_channel, s=1, n=0, group=32): 调换下形参的位置就解决了。。。 长见识了 ...原创 2021-09-07 09:26:59 · 3091 阅读 · 7 评论 -
RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the
狗bug,弄了我一天。。。 原因是在用GPU跑代码的时候,网络模型中使用了多个类,结果习惯性地只给主类使用了.to(device),网络中的其他类没管了,导致出现这个bug,后来在涉及到的类后面都添加了.to(device)后就OK了 block = Block().to(device) # 次类 net = Uet2plus().to(device) # 网络中的主要类 ...原创 2021-08-24 22:48:20 · 285 阅读 · 0 评论