提交 73da9720 编写于 作者: L Luo Tao

fix AvgPoolBackward and using CaffeMode in test_AvgPoolFwdBwd

上级 8067a42b
...@@ -298,11 +298,13 @@ __global__ void KeAvgPoolBackward(const int nthreads, ...@@ -298,11 +298,13 @@ __global__ void KeAvgPoolBackward(const int nthreads,
for (int ph = phstart; ph < phend; ++ph) { for (int ph = phstart; ph < phend; ++ph) {
int hstart = ph * strideH - padH; int hstart = ph * strideH - padH;
int hend = min(hstart + sizeY, height + padH); int hend = min(hstart + sizeY, height);
hstart = max(hstart, 0);
for (int pw = pwstart; pw < pwend; ++pw) { for (int pw = pwstart; pw < pwend; ++pw) {
// figure out the pooling size // figure out the pooling size
int wstart = pw * strideW - padW; int wstart = pw * strideW - padW;
int wend = min(wstart + sizeX, width + padW); int wend = min(wstart + sizeX, width);
wstart = max(wstart, 0);
int poolsize = (hend - hstart) * (wend - wstart); int poolsize = (hend - hstart) * (wend - wstart);
gradient += outGrad[ph * pooledW + pw] / poolsize; gradient += outGrad[ph * pooledW + pw] / poolsize;
} }
...@@ -708,14 +710,17 @@ __global__ void KeAvgPool3DBackward(const int nthreads, ...@@ -708,14 +710,17 @@ __global__ void KeAvgPool3DBackward(const int nthreads,
for (int pd = pdstart; pd < pdend; ++pd) { for (int pd = pdstart; pd < pdend; ++pd) {
int dstart = pd * strideD - padD; int dstart = pd * strideD - padD;
int dend = min(dstart + sizeZ, depth + padD); int dend = min(dstart + sizeZ, depth);
dstart = max(dstart, 0);
for (int ph = phstart; ph < phend; ++ph) { for (int ph = phstart; ph < phend; ++ph) {
int hstart = ph * strideH - padH; int hstart = ph * strideH - padH;
int hend = min(hstart + sizeY, height + padH); int hend = min(hstart + sizeY, height);
hstart = max(hstart, 0);
for (int pw = pwstart; pw < pwend; ++pw) { for (int pw = pwstart; pw < pwend; ++pw) {
// figure out the pooling size // figure out the pooling size
int wstart = pw * strideW - padW; int wstart = pw * strideW - padW;
int wend = min(wstart + sizeX, width + padW); int wend = min(wstart + sizeX, width);
wstart = max(wstart, 0);
int poolsize = (dend - dstart) * (hend - hstart) * (wend - wstart); int poolsize = (dend - dstart) * (hend - hstart) * (wend - wstart);
gradient += outGrad[(pd * pooledH + ph) * pooledW + pw] / poolsize; gradient += outGrad[(pd * pooledH + ph) * pooledW + pw] / poolsize;
} }
......
...@@ -825,9 +825,8 @@ void testMaxPoolFwdBwd(int numSamples, ...@@ -825,9 +825,8 @@ void testMaxPoolFwdBwd(int numSamples,
int strideW, int strideW,
int padH, int padH,
int padW) { int padW) {
int outH = 0, outW = 0; int outH = outputSize(imgSizeH, ksizeH, padH, strideH, true);
outH = (imgSizeH - ksizeH + 2 * padH + strideH - 1) / strideH + 1; int outW = outputSize(imgSizeW, ksizeW, padW, strideW, true);
outW = (imgSizeW - ksizeW + 2 * padW + strideW - 1) / strideW + 1;
int inWidth = imgSizeH * imgSizeW * channels; int inWidth = imgSizeH * imgSizeW * channels;
MatrixPtr input = CpuMatrix::create(numSamples, inWidth, false, false); MatrixPtr input = CpuMatrix::create(numSamples, inWidth, false, false);
...@@ -927,9 +926,8 @@ void testAvgPoolFwdBwd(int numSamples, ...@@ -927,9 +926,8 @@ void testAvgPoolFwdBwd(int numSamples,
int strideW, int strideW,
int padH, int padH,
int padW) { int padW) {
int outH = 0, outW = 0; int outH = outputSize(imgSizeH, ksizeH, padH, strideH, true);
outH = (imgSizeH - ksizeH + 2 * padH + strideH - 1) / strideH + 1; int outW = outputSize(imgSizeW, ksizeW, padW, strideW, true);
outW = (imgSizeW - ksizeW + 2 * padW + strideW - 1) / strideW + 1;
int inWidth = imgSizeH * imgSizeW * channels; int inWidth = imgSizeH * imgSizeW * channels;
MatrixPtr input = CpuMatrix::create(numSamples, inWidth, false, false); MatrixPtr input = CpuMatrix::create(numSamples, inWidth, false, false);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册