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

逃离我推掉我的手 2023-01-16 09:46 292阅读 0赞

修改代码。如下:

  1. def _initialize_biases(self, cf=None): # initialize biases into Detect(), cf is class frequency
  2. # cf = torch.bincount(torch.tensor(np.concatenate(dataset.labels, 0)[:, 0]).long(), minlength=nc) + 1.
  3. m = self.model[-1] # Detect() module
  4. for mi, s in zip(m.m, m.stride): # from
  5. b = mi.bias.view(m.na, -1) # conv.bias(255) to (3,85)
  6. with torch.no_grad():
  7. b[:, 4] += math.log(8 / (640 / s) ** 2) # obj (8 objects per 640 image)
  8. b[:, 5:] += math.log(0.6 / (m.nc - 0.99)) if cf is None else torch.log(cf / cf.sum()) # cls
  9. mi.bias = torch.nn.Parameter(b.view(-1), requires_grad=True)

发表评论

表情:
评论列表 (有 0 条评论,292人围观)

还没有评论,来说两句吧...

相关阅读