Skip to content

Commit 05836e7

Browse files
committed
support pytorch 1.0.1
1 parent 717ddb8 commit 05836e7

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

data/data_augment.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _crop(image, boxes, labels, img_dim):
4747
boxes_t[:, 2:] = np.minimum(boxes_t[:, 2:], roi[2:])
4848
boxes_t[:, 2:] -= roi[:2]
4949

50-
# keep the cropped image after resizing has at less one face > 16 pixel
50+
# make sure that the cropped image contains at least one face > 16 pixel at training image scale
5151
b_w_t = (boxes_t[:, 2] - boxes_t[:, 0] + 1) / w * img_dim
5252
b_h_t = (boxes_t[:, 3] - boxes_t[:, 1] + 1) / h * img_dim
5353
mask_b = np.minimum(b_w_t, b_h_t) > 16.0
@@ -186,7 +186,6 @@ def __init__(self, img_dim, rgb_means):
186186
self.rgb_means = rgb_means
187187

188188
def __call__(self, image, targets):
189-
image = image.astype(np.float32)
190189
assert targets.shape[0] > 0, "this image does not have gt"
191190

192191
boxes = targets[:, :-1].copy()

layers/modules/multibox_loss.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ def forward(self, predictions, priors, targets):
7070
if GPU:
7171
loc_t = loc_t.cuda()
7272
conf_t = conf_t.cuda()
73-
# wrap targets
74-
loc_t = Variable(loc_t, requires_grad=False)
75-
conf_t = Variable(conf_t, requires_grad=False)
7673

7774
pos = conf_t > 0
7875

@@ -81,7 +78,7 @@ def forward(self, predictions, priors, targets):
8178
pos_idx = pos.unsqueeze(pos.dim()).expand_as(loc_data)
8279
loc_p = loc_data[pos_idx].view(-1, 4)
8380
loc_t = loc_t[pos_idx].view(-1, 4)
84-
loss_l = F.smooth_l1_loss(loc_p, loc_t, size_average=False)
81+
loss_l = F.smooth_l1_loss(loc_p, loc_t, reduction='sum')
8582

8683
# Compute max conf across batch for hard negative mining
8784
batch_conf = conf_data.view(-1, self.num_classes)
@@ -101,7 +98,7 @@ def forward(self, predictions, priors, targets):
10198
neg_idx = neg.unsqueeze(2).expand_as(conf_data)
10299
conf_p = conf_data[(pos_idx+neg_idx).gt(0)].view(-1,self.num_classes)
103100
targets_weighted = conf_t[(pos+neg).gt(0)]
104-
loss_c = F.cross_entropy(conf_p, targets_weighted, size_average=False)
101+
loss_c = F.cross_entropy(conf_p, targets_weighted, reduction='sum')
105102

106103
# Sum of losses: L(x,c,l,g) = (Lconf(x, c) + αLloc(x,l,g)) / N
107104
N = max(num_pos.data.sum().float(), 1)

train.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import torch.optim as optim
55
import torch.backends.cudnn as cudnn
66
import argparse
7-
from torch.autograd import Variable
87
import torch.utils.data as data
98
from data import AnnotationTransform, VOCDetection, detection_collate, preproc, cfg
109
from layers.modules import MultiBoxLoss
@@ -108,12 +107,8 @@ def train():
108107

109108
# load train data
110109
images, targets = next(batch_iterator)
111-
if gpu_train:
112-
images = Variable(images.cuda())
113-
targets = [Variable(anno.cuda()) for anno in targets]
114-
else:
115-
images = Variable(images)
116-
targets = [Variable(anno) for anno in targets]
110+
images = images.to(device)
111+
targets = [anno.to(device) for anno in targets]
117112

118113
# forward
119114
out = net(images)

0 commit comments

Comments
 (0)