glenn-jocher
commited on
Commit
•
5c470d2
1
Parent(s):
67d5e65
multi-gpu test bug fix #15
Browse files- models/yolo.py +20 -1
models/yolo.py
CHANGED
@@ -20,7 +20,7 @@ class Detect(nn.Module):
|
|
20 |
self.export = False # onnx export
|
21 |
|
22 |
def forward(self, x):
|
23 |
-
x = x.copy()
|
24 |
z = [] # inference output
|
25 |
self.training |= self.export
|
26 |
for i in range(self.nl):
|
@@ -67,6 +67,25 @@ class Model(nn.Module):
|
|
67 |
print('')
|
68 |
|
69 |
def forward(self, x, augment=False, profile=False):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
y, dt = [], [] # outputs
|
71 |
for m in self.model:
|
72 |
if m.f != -1: # if not from previous layer
|
|
|
20 |
self.export = False # onnx export
|
21 |
|
22 |
def forward(self, x):
|
23 |
+
x = x.copy() # for profiling
|
24 |
z = [] # inference output
|
25 |
self.training |= self.export
|
26 |
for i in range(self.nl):
|
|
|
67 |
print('')
|
68 |
|
69 |
def forward(self, x, augment=False, profile=False):
|
70 |
+
if augment:
|
71 |
+
img_size = x.shape[-2:] # height, width
|
72 |
+
s = [0.83, 0.67] # scales
|
73 |
+
y = []
|
74 |
+
for i, xi in enumerate((x,
|
75 |
+
torch_utils.scale_img(x.flip(3), s[0], same_shape=False), # flip-lr and scale
|
76 |
+
torch_utils.scale_img(x, s[1], same_shape=False), # scale
|
77 |
+
)):
|
78 |
+
# cv2.imwrite('img%g.jpg' % i, 255 * xi[0].numpy().transpose((1, 2, 0))[:, :, ::-1])
|
79 |
+
y.append(self.forward_once(xi)[0])
|
80 |
+
|
81 |
+
y[1][..., :4] /= s[0] # scale
|
82 |
+
y[1][..., 0] = img_size[1] - y[1][..., 0] # flip lr
|
83 |
+
y[2][..., :4] /= s[1] # scale
|
84 |
+
return torch.cat(y, 1), None # augmented inference, train
|
85 |
+
else:
|
86 |
+
return self.forward_once(x, profile) # single-scale inference, train
|
87 |
+
|
88 |
+
def forward_once(self, x, profile=False):
|
89 |
y, dt = [], [] # outputs
|
90 |
for m in self.model:
|
91 |
if m.f != -1: # if not from previous layer
|