Skip to content

Commit 43a616a

Browse files
committed
PyTorch 1.6.0 compatability updates
1 parent 7f8471e commit 43a616a

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

detect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def detect(save_img=False):
154154

155155
with torch.no_grad():
156156
if opt.update: # update all models (to fix SourceChangeWarning)
157-
for opt.weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt', 'yolov3-spp.pt']:
157+
for opt.weights in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']:
158158
detect()
159159
strip_optimizer(opt.weights)
160160
else:

models/yolo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ def forward(self, x, augment=False, profile=False):
9090
yi = self.forward_once(xi)[0] # forward
9191
# cv2.imwrite('img%g.jpg' % s, 255 * xi[0].numpy().transpose((1, 2, 0))[:, :, ::-1]) # save
9292
yi[..., :4] /= si # de-scale
93-
if fi is 2:
93+
if fi == 2:
9494
yi[..., 1] = img_size[0] - yi[..., 1] # de-flip ud
95-
elif fi is 3:
95+
elif fi == 3:
9696
yi[..., 0] = img_size[1] - yi[..., 0] # de-flip lr
9797
y.append(yi)
9898
return torch.cat(y, 1), None # augmented inference, train
@@ -148,6 +148,7 @@ def fuse(self): # fuse model Conv2d() + BatchNorm2d() layers
148148
print('Fusing layers... ', end='')
149149
for m in self.model.modules():
150150
if type(m) is Conv:
151+
m._non_persistent_buffers_set = set() # pytorch 1.6.0 compatability
151152
m.conv = torch_utils.fuse_conv_and_bn(m.conv, m.bn) # update conv
152153
m.bn = None # remove batchnorm
153154
m.forward = m.fuseforward # update forward

test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,16 @@ def test(data,
148148

149149
# Per target class
150150
for cls in torch.unique(tcls_tensor):
151-
ti = (cls == tcls_tensor).nonzero().view(-1) # prediction indices
152-
pi = (cls == pred[:, 5]).nonzero().view(-1) # target indices
151+
ti = (cls == tcls_tensor).nonzero(as_tuple=False).view(-1) # prediction indices
152+
pi = (cls == pred[:, 5]).nonzero(as_tuple=False).view(-1) # target indices
153153

154154
# Search for detections
155155
if pi.shape[0]:
156156
# Prediction to target ious
157157
ious, i = box_iou(pred[pi, :4], tbox[ti]).max(1) # best ious, indices
158158

159159
# Append detections
160-
for j in (ious > iouv[0]).nonzero():
160+
for j in (ious > iouv[0]).nonzero(as_tuple=False):
161161
d = ti[i[j]] # detected target
162162
if d not in detected:
163163
detected.append(d)

0 commit comments

Comments
 (0)