From b7776e66d609bd26d40a6338b9534005621e876c Mon Sep 17 00:00:00 2001 From: yangyaming Date: Wed, 6 Sep 2017 18:30:59 +0800 Subject: [PATCH] Fix dimension bugs. --- paddle/operators/smooth_l1_loss_op.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/paddle/operators/smooth_l1_loss_op.h b/paddle/operators/smooth_l1_loss_op.h index ae91b9c893f..3e474038584 100644 --- a/paddle/operators/smooth_l1_loss_op.h +++ b/paddle/operators/smooth_l1_loss_op.h @@ -87,10 +87,13 @@ class SmoothL1LossKernel : public framework::OpKernel { auto outside_weight = EigenVector::Flatten(*in3); errors.device(place) = errors * outside_weight; } - auto loss = EigenMatrix::From(*out1, {in0->dims()[0], 1}); + auto loss = EigenVector::Flatten(*out1); // first dimension of 'X' is the number of samples - auto errors_mat_view = EigenMatrix::From(paddle_errors, in0->dims()); - loss.device(place) = errors_mat_view.sum(Eigen::array({1})); + auto mat_dims = + framework::make_ddim({static_cast(in0->dims()[0]), + static_cast(in_counts / in0->dims()[0])}); + auto errors_mat_view = EigenMatrix::From(paddle_errors, mat_dims); + loss.device(place) = errors_mat_view.sum(Eigen::array({{1}})); } }; @@ -162,9 +165,9 @@ class SmoothL1LossGradKernel : public framework::OpKernel { // compute gradients auto out_grad = EigenMatrix::From(*og); auto diff_mat_view = EigenMatrix::From(paddle_diff, mat_dims); - auto gradients = - out_grad.broadcast(Eigen::array({1, static_cast(cols)})) * - weights * diff_mat_view; + auto gradients = out_grad.broadcast( + Eigen::array({{1, static_cast(cols)}})) * + weights * diff_mat_view; if (out0) { out0->mutable_data(context.GetPlace()); -- GitLab