glenn-jocher
commited on
Commit
•
3a5c532
1
Parent(s):
18b4da9
ONNX, BCEBlurWithLogitsLoss, plot_study updates
Browse files- models/onnx_export.py +6 -3
- utils/utils.py +18 -1
models/onnx_export.py
CHANGED
@@ -1,6 +1,9 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
4 |
|
5 |
import argparse
|
6 |
|
|
|
1 |
+
"""Exports a pytorch *.pt model to *.onnx format
|
2 |
+
|
3 |
+
Usage:
|
4 |
+
import torch
|
5 |
+
$ export PYTHONPATH="$PWD" && python models/onnx_export.py --weights ./weights/yolov5s.pt --img 640 --batch 1
|
6 |
+
"""
|
7 |
|
8 |
import argparse
|
9 |
|
utils/utils.py
CHANGED
@@ -339,6 +339,23 @@ def smooth_BCE(eps=0.1): # https://github.com/ultralytics/yolov3/issues/238#iss
|
|
339 |
return 1.0 - 0.5 * eps, 0.5 * eps
|
340 |
|
341 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
342 |
def compute_loss(p, targets, model): # predictions, targets, model
|
343 |
ft = torch.cuda.FloatTensor if p[0].is_cuda else torch.Tensor
|
344 |
lcls, lbox, lobj = ft([0]), ft([0]), ft([0])
|
@@ -1009,7 +1026,7 @@ def plot_study_txt(f='study.txt', x=None): # from utils.utils import *; plot_st
|
|
1009 |
ax2.plot(1E3 / np.array([209, 140, 97, 58, 35, 18]), [33.5, 39.1, 42.5, 45.9, 49., 50.5],
|
1010 |
'k.-', linewidth=2, markersize=8, alpha=.25, label='EfficientDet')
|
1011 |
ax2.set_xlim(0, 30)
|
1012 |
-
ax2.set_ylim(
|
1013 |
ax2.set_xlabel('GPU Latency (ms)')
|
1014 |
ax2.set_ylabel('COCO AP val')
|
1015 |
ax2.legend(loc='lower right')
|
|
|
339 |
return 1.0 - 0.5 * eps, 0.5 * eps
|
340 |
|
341 |
|
342 |
+
class BCEBlurWithLogitsLoss(nn.Module):
|
343 |
+
# BCEwithLogitLoss() with reduced missing label effects.
|
344 |
+
def __init__(self, alpha=0.05):
|
345 |
+
super(BCEBlurWithLogitsLoss, self).__init__()
|
346 |
+
self.loss_fcn = nn.BCEWithLogitsLoss(reduction='none') # must be nn.BCEWithLogitsLoss()
|
347 |
+
self.alpha = alpha
|
348 |
+
|
349 |
+
def forward(self, pred, true):
|
350 |
+
loss = self.loss_fcn(pred, true)
|
351 |
+
pred = torch.sigmoid(pred) # prob from logits
|
352 |
+
dx = pred - true # reduce only missing label effects
|
353 |
+
# dx = (pred - true).abs() # reduce missing label and false label effects
|
354 |
+
alpha_factor = 1 - torch.exp((dx - 1) / (self.alpha + 1e-4))
|
355 |
+
loss *= alpha_factor
|
356 |
+
return loss.mean()
|
357 |
+
|
358 |
+
|
359 |
def compute_loss(p, targets, model): # predictions, targets, model
|
360 |
ft = torch.cuda.FloatTensor if p[0].is_cuda else torch.Tensor
|
361 |
lcls, lbox, lobj = ft([0]), ft([0]), ft([0])
|
|
|
1026 |
ax2.plot(1E3 / np.array([209, 140, 97, 58, 35, 18]), [33.5, 39.1, 42.5, 45.9, 49., 50.5],
|
1027 |
'k.-', linewidth=2, markersize=8, alpha=.25, label='EfficientDet')
|
1028 |
ax2.set_xlim(0, 30)
|
1029 |
+
ax2.set_ylim(25, 50)
|
1030 |
ax2.set_xlabel('GPU Latency (ms)')
|
1031 |
ax2.set_ylabel('COCO AP val')
|
1032 |
ax2.legend(loc='lower right')
|