RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.
程序员文章站
2022-03-04 14:17:09
...
修改代码。如下:
def _initialize_biases(self, cf=None): # initialize biases into Detect(), cf is class frequency
# cf = torch.bincount(torch.tensor(np.concatenate(dataset.labels, 0)[:, 0]).long(), minlength=nc) + 1.
m = self.model[-1] # 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)
下一篇: 笨办法学python 习题8:打印,打印
推荐阅读
-
RuntimeError: a leaf Variable that requires grad has been used in an in-place operation
-
a leaf Variable that requires grad has been used in an in-place operation
-
RuntimeError: a leaf Variable that requires grad has been used in an in-place operation.
-
RuntimeError: a leaf Variable that requires grad has been used in an in-place operation.a += torch.o
-
yolov5报错:RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place
-
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.