|
|
@@ -127,7 +127,7 @@ class Model(nn.Module): |
|
|
|
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 |
|
|
|
for mi, s in zip(m.m, m.stride): # from |
|
|
|
b = mi.bias.view(m.na, -1) # conv.bias(255) to (3,85) |
|
|
|
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 |
|
|
@@ -135,7 +135,7 @@ class Model(nn.Module): |
|
|
|
|
|
|
|
def _print_biases(self): |
|
|
|
m = self.model[-1] # Detect() module |
|
|
|
for mi in m.m: # from |
|
|
|
for mi in m.m: # from |
|
|
|
b = mi.bias.detach().view(m.na, -1).T # conv.bias(255) to (3,85) |
|
|
|
print(('%6g Conv2d.bias:' + '%10.3g' * 6) % (mi.weight.shape[1], *b[:5].mean(1).tolist(), b[5:].mean())) |
|
|
|
|