Update cls bias init (#5520)
Browse files* Update cls bias init
Increased numerical precision. Returns 1.0 probability for single-class datasets now. Addresses https://github.com/ultralytics/yolov5/issues/5357
```python
torch.sigmoid(torch.tensor([math.log(0.6 / (1 - 0.99999))]))
Out[19]: tensor([1.0000])
```
* Update yolo.py
- models/yolo.py +1 -1
models/yolo.py
CHANGED
@@ -201,7 +201,7 @@ class Model(nn.Module):
|
|
201 |
for mi, s in zip(m.m, m.stride): # from
|
202 |
b = mi.bias.view(m.na, -1) # conv.bias(255) to (3,85)
|
203 |
b.data[:, 4] += math.log(8 / (640 / s) ** 2) # obj (8 objects per 640 image)
|
204 |
-
b.data[:, 5:] += math.log(0.6 / (m.nc - 0.
|
205 |
mi.bias = torch.nn.Parameter(b.view(-1), requires_grad=True)
|
206 |
|
207 |
def _print_biases(self):
|
|
|
201 |
for mi, s in zip(m.m, m.stride): # from
|
202 |
b = mi.bias.view(m.na, -1) # conv.bias(255) to (3,85)
|
203 |
b.data[:, 4] += math.log(8 / (640 / s) ** 2) # obj (8 objects per 640 image)
|
204 |
+
b.data[:, 5:] += math.log(0.6 / (m.nc - 0.999999)) if cf is None else torch.log(cf / cf.sum()) # cls
|
205 |
mi.bias = torch.nn.Parameter(b.view(-1), requires_grad=True)
|
206 |
|
207 |
def _print_biases(self):
|