Skip to content

Commit a132f27

Browse files
authored
Merge pull request #192 from YongWookHa/master
fix: deprecated 'size_average'
2 parents 272f0a4 + ac43ec2 commit a132f27

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

tool/darknet2pytorch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,11 @@ def create_network(self, blocks):
308308
models.append(model)
309309
elif block['type'] == 'cost':
310310
if block['_type'] == 'sse':
311-
model = nn.MSELoss(size_average=True)
311+
model = nn.MSELoss(reduction='mean')
312312
elif block['_type'] == 'L1':
313-
model = nn.L1Loss(size_average=True)
313+
model = nn.L1Loss(reduction='mean')
314314
elif block['_type'] == 'smooth':
315-
model = nn.SmoothL1Loss(size_average=True)
315+
model = nn.SmoothL1Loss(reduction='mean')
316316
out_filters.append(1)
317317
out_strides.append(prev_stride)
318318
models.append(model)

tool/region_loss.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ def forward(self, output, target):
174174

175175
t3 = time.time()
176176

177-
loss_x = self.coord_scale * nn.MSELoss(size_average=False)(x * coord_mask, tx * coord_mask) / 2.0
178-
loss_y = self.coord_scale * nn.MSELoss(size_average=False)(y * coord_mask, ty * coord_mask) / 2.0
179-
loss_w = self.coord_scale * nn.MSELoss(size_average=False)(w * coord_mask, tw * coord_mask) / 2.0
180-
loss_h = self.coord_scale * nn.MSELoss(size_average=False)(h * coord_mask, th * coord_mask) / 2.0
181-
loss_conf = nn.MSELoss(size_average=False)(conf * conf_mask, tconf * conf_mask) / 2.0
182-
loss_cls = self.class_scale * nn.CrossEntropyLoss(size_average=False)(cls, tcls)
177+
loss_x = self.coord_scale * nn.MSELoss(reduction='sum')(x * coord_mask, tx * coord_mask) / 2.0
178+
loss_y = self.coord_scale * nn.MSELoss(reduction='sum')(y * coord_mask, ty * coord_mask) / 2.0
179+
loss_w = self.coord_scale * nn.MSELoss(reduction='sum')(w * coord_mask, tw * coord_mask) / 2.0
180+
loss_h = self.coord_scale * nn.MSELoss(reduction='sum')(h * coord_mask, th * coord_mask) / 2.0
181+
loss_conf = nn.MSELoss(reduction='sum')(conf * conf_mask, tconf * conf_mask) / 2.0
182+
loss_cls = self.class_scale * nn.CrossEntropyLoss(reduction='sum')(cls, tcls)
183183
loss = loss_x + loss_y + loss_w + loss_h + loss_conf + loss_cls
184184
t4 = time.time()
185185
if False:

train.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,11 @@ def forward(self, xin, labels=None):
263263
target[..., 2:4] *= tgt_scale
264264

265265
loss_xy += F.binary_cross_entropy(input=output[..., :2], target=target[..., :2],
266-
weight=tgt_scale * tgt_scale, size_average=False)
267-
loss_wh += F.mse_loss(input=output[..., 2:4], target=target[..., 2:4], size_average=False) / 2
268-
loss_obj += F.binary_cross_entropy(input=output[..., 4], target=target[..., 4], size_average=False)
269-
loss_cls += F.binary_cross_entropy(input=output[..., 5:], target=target[..., 5:], size_average=False)
270-
loss_l2 += F.mse_loss(input=output, target=target, size_average=False)
266+
weight=tgt_scale * tgt_scale, reduction='sum')
267+
loss_wh += F.mse_loss(input=output[..., 2:4], target=target[..., 2:4], reduction='sum') / 2
268+
loss_obj += F.binary_cross_entropy(input=output[..., 4], target=target[..., 4], reduction='sum')
269+
loss_cls += F.binary_cross_entropy(input=output[..., 5:], target=target[..., 5:], reduction='sum')
270+
loss_l2 += F.mse_loss(input=output, target=target, reduction='sum')
271271

272272
loss = loss_xy + loss_wh + loss_obj + loss_cls
273273

@@ -511,7 +511,6 @@ def evaluate(model, data_loader, cfg, device, logger=None, **kwargs):
511511
"scores": scores,
512512
"labels": labels,
513513
}
514-
515514
evaluator_time = time.time()
516515
coco_evaluator.update(res)
517516
evaluator_time = time.time() - evaluator_time

0 commit comments

Comments
 (0)