tcmyxc commited on
Commit
50b886d
·
unverified ·
1 Parent(s): dcf8073

`.detach()` on bias init (#8044)

Browse files

make init bias better,
I think `detach` is more safer than `data`

Files changed (1) hide show
  1. models/yolo.py +3 -3
models/yolo.py CHANGED
@@ -207,9 +207,9 @@ class Model(nn.Module):
207
  # cf = torch.bincount(torch.tensor(np.concatenate(dataset.labels, 0)[:, 0]).long(), minlength=nc) + 1.
208
  m = self.model[-1] # Detect() module
209
  for mi, s in zip(m.m, m.stride): # from
210
- b = mi.bias.view(m.na, -1) # conv.bias(255) to (3,85)
211
- b.data[:, 4] += math.log(8 / (640 / s) ** 2) # obj (8 objects per 640 image)
212
- b.data[:, 5:] += math.log(0.6 / (m.nc - 0.999999)) if cf is None else torch.log(cf / cf.sum()) # cls
213
  mi.bias = torch.nn.Parameter(b.view(-1), requires_grad=True)
214
 
215
  def _print_biases(self):
 
207
  # cf = torch.bincount(torch.tensor(np.concatenate(dataset.labels, 0)[:, 0]).long(), minlength=nc) + 1.
208
  m = self.model[-1] # Detect() module
209
  for mi, s in zip(m.m, m.stride): # from
210
+ b = mi.bias.view(m.na, -1).detach() # conv.bias(255) to (3,85)
211
+ b[:, 4] += math.log(8 / (640 / s) ** 2) # obj (8 objects per 640 image)
212
+ b[:, 5:] += math.log(0.6 / (m.nc - 0.999999)) if cf is None else torch.log(cf / cf.sum()) # cls
213
  mi.bias = torch.nn.Parameter(b.view(-1), requires_grad=True)
214
 
215
  def _print_biases(self):