Skip to content

Commit bc2b521

Browse files
committed
Follow comments
1 parent 7f6e9ac commit bc2b521

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

paddle/gserver/tests/test_LayerGrad.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,14 @@ TEST(Layer, BilinearInterpLayer) {
4343

4444
bilinear->set_img_size_x(32);
4545
bilinear->set_img_size_y(32);
46-
bilinear->set_out_size_x(64);
47-
bilinear->set_out_size_y(64);
4846
bilinear->set_num_channels(4);
4947

5048
for (auto useGpu : {false, true}) {
51-
testLayerGrad(config, "bilinear_interp", 10, false, useGpu);
52-
}
53-
54-
bilinear->set_img_size_x(32);
55-
bilinear->set_img_size_y(32);
56-
bilinear->set_out_size_x(32);
57-
bilinear->set_out_size_y(32);
58-
bilinear->set_num_channels(4);
59-
60-
for (auto useGpu : {false, true}) {
61-
testLayerGrad(config, "bilinear_interp", 10, false, useGpu);
49+
for (auto out_size : {32, 64, 128}) {
50+
bilinear->set_out_size_x(out_size);
51+
bilinear->set_out_size_y(out_size);
52+
testLayerGrad(config, "bilinear_interp", 10, false, useGpu);
53+
}
6254
}
6355
}
6456

paddle/math/Matrix.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3902,6 +3902,8 @@ void CpuMatrix::bilinearForward(const Matrix& in,
39023902
size_t batchSize = getHeight();
39033903
size_t inputW = in.getWidth();
39043904
size_t inputH = in.getHeight();
3905+
size_t inPosOffset = inImgH * inImgW;
3906+
size_t outPosOffset = outImgH * outImgW;
39053907
(void)(inputH);
39063908

39073909
real* outData = getData();
@@ -3931,8 +3933,8 @@ void CpuMatrix::bilinearForward(const Matrix& in,
39313933
h2lambda * (w2lambda * inPos[0] + w1lambda * inPos[wid]) +
39323934
h1lambda * (w2lambda * inPos[hid * inImgW] +
39333935
w1lambda * inPos[hid * inImgW + wid]);
3934-
inPos += inImgH * inImgW;
3935-
outPos += outImgH * outImgW;
3936+
inPos += inPosOffset;
3937+
outPos += outPosOffset;
39363938
}
39373939
}
39383940
}
@@ -3954,6 +3956,8 @@ void CpuMatrix::bilinearBackward(const Matrix& out,
39543956
size_t inputH = getHeight();
39553957
size_t outputW = out.getWidth();
39563958
size_t batchSize = out.getHeight();
3959+
size_t inPosOffset = inImgH * inImgW;
3960+
size_t outPosOffset = outImgH * outImgW;
39573961
(void)(inputH);
39583962

39593963
real* inGrad = getData();
@@ -3981,8 +3985,8 @@ void CpuMatrix::bilinearBackward(const Matrix& out,
39813985
inPos[wid] += h2lambda * w1lambda * outPos[0];
39823986
inPos[hid * inImgW] += h1lambda * w2lambda * outPos[0];
39833987
inPos[hid * inImgW + wid] += h1lambda * w1lambda * outPos[0];
3984-
inPos += inImgH * inImgW;
3985-
outPos += outImgH * outImgW;
3988+
inPos += inPosOffset;
3989+
outPos += outPosOffset;
39863990
}
39873991
}
39883992
}

0 commit comments

Comments
 (0)