Skip to content

Commit

Permalink
fix issue amdegroot#173
Browse files Browse the repository at this point in the history
  • Loading branch information
yodhcn committed May 17, 2022
1 parent a99bec6 commit 6637c05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions layers/modules/multibox_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def forward(self, predictions, targets):
loss_c = log_sum_exp(batch_conf) - batch_conf.gather(1, conf_t.view(-1, 1))

# Hard Negative Mining
loss_c[pos] = 0 # filter out pos boxes for now
loss_c = loss_c.view(num, -1)
loss_c[pos] = 0 # filter out pos boxes for now
_, loss_idx = loss_c.sort(1, descending=True)
_, idx_rank = loss_idx.sort(1)
num_pos = pos.long().sum(1, keepdim=True)
Expand All @@ -111,7 +111,7 @@ def forward(self, predictions, targets):

# Sum of losses: L(x,c,l,g) = (Lconf(x, c) + αLloc(x,l,g)) / N

N = num_pos.data.sum()
loss_l /= N
loss_c /= N
N = num_pos.data.sum().double()
loss_l = loss_l.double() / N
loss_c = loss_c.double() / N
return loss_l, loss_c
8 changes: 4 additions & 4 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ def train():
loss.backward()
optimizer.step()
t1 = time.time()
loc_loss += loss_l.data[0]
conf_loss += loss_c.data[0]
loc_loss += loss_l.item()
conf_loss += loss_c.item()

if iteration % 10 == 0:
print('timer: %.4f sec.' % (t1 - t0))
print('iter ' + repr(iteration) + ' || Loss: %.4f ||' % (loss.data[0]), end=' ')
print('iter ' + repr(iteration) + ' || Loss: %.4f ||' % (loss.item()), end=' ')

if args.visdom:
update_vis_plot(iteration, loss_l.data[0], loss_c.data[0],
update_vis_plot(iteration, loss_l.item(), loss_c.item(),
iter_plot, epoch_plot, 'append')

if iteration != 0 and iteration % 5000 == 0:
Expand Down

0 comments on commit 6637c05

Please sign in to comment.