Skip to content
This repository was archived by the owner on Jul 2, 2021. It is now read-only.

fix ssd.multibox_loss with comm #654

Merged
merged 3 commits into from
Jul 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chainercv/links/model/ssd/multibox_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def multibox_loss(mb_locs, mb_confs, gt_mb_locs, gt_mb_labels, k, comm=None):
if comm:
if xp is not np:
chainer.backends.cuda.Stream.null.synchronize()
n_positive = comm.allreduce(n_positive)
n_positive = comm.allreduce(n_positive) / comm.size

if n_positive == 0:
z = chainer.Variable(xp.zeros((), dtype=np.float32))
Expand Down
4 changes: 2 additions & 2 deletions examples/ssd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ PASCAL VOC2007 Test

| Model | Original | ChainerCV (weight conversion) | ChainerCV (train) |
|:-:|:-:|:-:|:-:|
| SSD300 | 77.5 % [2] | 77.8 % | 77.5 % / 77.3 % (4 GPUs) |
| SSD512 | 79.5 % [2] | 79.7 % | 80.1 % * / 79.9 % (4 GPUs) |
| SSD300 | 77.5 % [2] | 77.8 % | 77.5 % / 77.6 % (4 GPUs) |
| SSD512 | 79.5 % [2] | 79.7 % | 80.1 % * / 80.5 % (4 GPUs) |

Scores are mean Average Precision (mAP) with PASCAL VOC2007 metric.

Expand Down
11 changes: 5 additions & 6 deletions tests/links_tests/model_tests/ssd_tests/test_multibox_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,15 @@ def _check_forward(

loc_loss_local = cuda.to_cpu(loc_loss_local.array)
conf_loss_local = cuda.to_cpu(conf_loss_local.array)
from mpi4py import MPI
self.comm.mpi_comm.Allreduce(MPI.IN_PLACE, loc_loss_local)
self.comm.mpi_comm.Allreduce(MPI.IN_PLACE, conf_loss_local)
loc_loss = self.comm.allreduce(loc_loss_local) / self.comm.size
conf_loss = self.comm.allreduce(conf_loss_local) / self.comm.size

loc_loss, conf_loss = multibox_loss(
expect_loc_loss, expect_conf_loss = multibox_loss(
self.mb_locs, self.mb_confs, self.gt_mb_locs, self.gt_mb_labels, k)
np.testing.assert_almost_equal(
loc_loss_local, loc_loss.array, decimal=2)
loc_loss, expect_loc_loss.array, decimal=2)
np.testing.assert_almost_equal(
conf_loss_local, conf_loss.array, decimal=2)
conf_loss, expect_conf_loss.array, decimal=2)

def test_multi_node_forward_cpu(self):
self._check_forward(
Expand Down