xhwNobody / yolov5_prune_sfp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.

martinkeith opened this issue · comments

Traceback (most recent call last):
File "/home//yolov5_prune_sfp/weights/copy_weight.py", line 10, in
model_dst = Model(nc=80)
File "/home/
/yolov5_prune_sfp/weights/model.py", line 43, in init
self._initialize_biases() # only run once
File "/home/***/yolov5_prune_sfp/weights/model.py", line 64, in _initialize_biases
b[:, 4] += math.log(8 / (640 / s) ** 2) # obj (8 objects per 640 image)
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.

如上,我在执行copy_weight.py时,出现这个错误,请问有遇到同样的问题的吗?

Hi I meet the same error with you
I update my code as :
def _initialize_biases(self, cf=None): # initialize biases into Detect(), cf is class frequency m = self.head_self # Detect() module for mi, s in zip(m.m, m.stride): # from b = mi.bias.view(m.na, -1) # conv.bias(255) to (3,85) with torch.no_grad(): b[:, 4] += math.log(8 / (640 / s) ** 2) # obj (8 objects per 640 image) b[:, 5:] += math.log(0.6 / (m.nc - 0.99)) if cf is None else torch.log(cf / cf.sum()) # cls mi.bias = torch.nn.Parameter(b.view(-1), requires_grad=True)