Skip to content

Commit

Permalink
Update cls bias init (ultralytics#5520)
Browse files Browse the repository at this point in the history
* Update cls bias init

Increased numerical precision. Returns 1.0 probability for single-class datasets now. Addresses ultralytics#5357

```python
torch.sigmoid(torch.tensor([math.log(0.6 / (1 - 0.99999))]))
Out[19]: tensor([1.0000])
```

* Update yolo.py
  • Loading branch information
glenn-jocher authored Nov 5, 2021
1 parent a9b5f5e commit 9ade0fb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion models/yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _initialize_biases(self, cf=None): # initialize biases into Detect(), cf is
for mi, s in zip(m.m, m.stride): # from
b = mi.bias.view(m.na, -1) # conv.bias(255) to (3,85)
b.data[:, 4] += math.log(8 / (640 / s) ** 2) # obj (8 objects per 640 image)
b.data[:, 5:] += math.log(0.6 / (m.nc - 0.99)) if cf is None else torch.log(cf / cf.sum()) # cls
b.data[:, 5:] += math.log(0.6 / (m.nc - 0.999999)) if cf is None else torch.log(cf / cf.sum()) # cls
mi.bias = torch.nn.Parameter(b.view(-1), requires_grad=True)

def _print_biases(self):
Expand Down

0 comments on commit 9ade0fb

Please sign in to comment.