提交 790379f1 编写于 作者: C chengduoZH

fix above comments

上级 2377d719
...@@ -173,31 +173,6 @@ extern void hl_avgpool_backward(const int frameCnt, ...@@ -173,31 +173,6 @@ extern void hl_avgpool_backward(const int frameCnt,
real* backGrad, real* backGrad,
const int outStride); const int outStride);
/**
* @brief Maximum pool forward.
*
* @param[in] frameCnt batch size of input image.
* @param[in] inputData input data.
* @param[in] channels number of channel.
* @param[in] depth image depth.
* @param[in] height image height.
* @param[in] width image width.
* @param[in] pooledD output image depth.
* @param[in] pooledH output image height.
* @param[in] pooledW output image width.
* @param[in] sizeZ depth of pooling window.
* @param[in] sizeY height of pooling window.
* @param[in] sizeX width of pooling window.
* @param[in] strideD pooling stride depth.
* @param[in] strideH pooling stride height.
* @param[in] strideW pooling stride width.
* @param[in] paddingD padding depth.
* @param[in] paddingH padding height.
* @param[in] paddingW padding width.
* @param[out] tgtData output data.
* @param[in] tgtStride stride between output data samples.
*
*/
extern void hl_maxpool3D_forward(const int frameCnt, extern void hl_maxpool3D_forward(const int frameCnt,
const real* inputData, const real* inputData,
const int channels, const int channels,
...@@ -219,35 +194,6 @@ extern void hl_maxpool3D_forward(const int frameCnt, ...@@ -219,35 +194,6 @@ extern void hl_maxpool3D_forward(const int frameCnt,
real* tgtData, real* tgtData,
const int tgtStride); const int tgtStride);
/**
* @brief Maximum pool backward.
*
* @param[in] frameCnt batch size of input image.
* @param[in] inputData input data.
* @param[out] outData output data.
* @param[out] outGrad output grad data.
* @param[in] channels number of channel.
* @param[in] depth image depth.
* @param[in] height image height.
* @param[in] width image width.
* @param[in] pooledD output image depth.
* @param[in] pooledH output image height.
* @param[in] pooledW output image width.
* @param[in] sizeZ depth of pooling window.
* @param[in] sizeY height of pooling window.
* @param[in] sizeX width of pooling window.
* @param[in] strideD pooling stride depth.
* @param[in] strideH pooling stride height.
* @param[in] strideW pooling stride width.
* @param[in] scaleA scale.
* @param[in] scaleB scale.
* @param[in] paddingD padding depth.
* @param[in] paddingH padding height.
* @param[in] paddingW padding width.
* @param[out] targetGrad output grad.
* @param[in] outStride stride between output data samples.
*
*/
extern void hl_maxpool3D_backward(const int frameCnt, extern void hl_maxpool3D_backward(const int frameCnt,
const real* inputData, const real* inputData,
const real* outData, const real* outData,
...@@ -273,31 +219,6 @@ extern void hl_maxpool3D_backward(const int frameCnt, ...@@ -273,31 +219,6 @@ extern void hl_maxpool3D_backward(const int frameCnt,
real* targetGrad, real* targetGrad,
const int outStride); const int outStride);
/**
* @brief Averge pool forward.
*
* @param[in] frameCnt batch size of input image.
* @param[in] inputData input data.
* @param[in] channels number of channel.
* @param[in] depth image depth.
* @param[in] height image height.
* @param[in] width image width.
* @param[in] pooledD output image depth.
* @param[in] pooledH output image height.
* @param[in] pooledW output image width.
* @param[in] sizeZ depth of pooling window.
* @param[in] sizeY height of pooling window.
* @param[in] sizeX width of pooling window.
* @param[in] strideD pooling stride depth.
* @param[in] strideH pooling stride height.
* @param[in] strideW pooling stride width.
* @param[in] paddingD padding depth.
* @param[in] paddingH padding height.
* @param[in] paddingW padding width.
* @param[out] tgtData output data.
* @param[in] tgtStride stride between output data samples.
*
*/
extern void hl_avgpool3D_forward(const int frameCnt, extern void hl_avgpool3D_forward(const int frameCnt,
const real* inputData, const real* inputData,
const int channels, const int channels,
...@@ -319,33 +240,6 @@ extern void hl_avgpool3D_forward(const int frameCnt, ...@@ -319,33 +240,6 @@ extern void hl_avgpool3D_forward(const int frameCnt,
real* tgtData, real* tgtData,
const int tgtStride); const int tgtStride);
/**
* @brief Maximum pool backward.
*
* @param[in] frameCnt batch size of input image.
* @param[in] outGrad output grad data.
* @param[in] channels number of channel.
* @param[in] depth image depth.
* @param[in] height image height.
* @param[in] width image width.
* @param[in] pooledD output image depth.
* @param[in] pooledH output image height.
* @param[in] pooledW output image width.
* @param[in] sizeZ depth of pooling window.
* @param[in] sizeY height of pooling window.
* @param[in] sizeX width of pooling window.
* @param[in] strideD pooling stride depth.
* @param[in] strideH pooling stride height.
* @param[in] strideW pooling stride width.
* @param[in] paddingD padding depth.
* @param[in] paddingH padding height.
* @param[in] paddingW padding width.
* @param[in] scaleA scale.
* @param[in] scaleB scale.
* @param[out] backGrad output grad.
* @param[in] outStride stride between output data samples.
*
*/
extern void hl_avgpool3D_backward(const int frameCnt, extern void hl_avgpool3D_backward(const int frameCnt,
const real* outGrad, const real* outGrad,
const int channels, const int channels,
......
...@@ -169,9 +169,9 @@ inline void hl_avgpool3D_backward(const int frameCnt, ...@@ -169,9 +169,9 @@ inline void hl_avgpool3D_backward(const int frameCnt,
const int strideD, const int strideD,
const int strideH, const int strideH,
const int strideW, const int strideW,
int paddingD, const int paddingD,
int paddingH, const int paddingH,
int paddingW, const int paddingW,
real scaleA, real scaleA,
real scaleB, real scaleB,
real* backGrad, real* backGrad,
......
...@@ -58,30 +58,9 @@ size_t Pool3DLayer::getSize() { ...@@ -58,30 +58,9 @@ size_t Pool3DLayer::getSize() {
CHECK_EQ(inputLayers_.size(), 1UL); CHECK_EQ(inputLayers_.size(), 1UL);
size_t layerSize = 0; size_t layerSize = 0;
// imgSizeD_ = inputLayers_[0]->getOutput().getFrameDepth(); outputD_ = outputSize(imgSizeD_, sizeZ_, paddingD_, strideD_, false);
// imgSizeH_ = inputLayers_[0]->getOutput().getFrameHeight(); outputH_ = outputSize(imgSizeH_, sizeY_, paddingH_, strideH_, false);
// imgSizeW_ = inputLayers_[0]->getOutput().getFrameWidth(); outputW_ = outputSize(imgSizeW_, sizeX_, paddingW_, strideW_, false);
if (imgSizeH_ == 0) {
// imgSizeH_ = imgSizeY_;
}
if (imgSizeW_ == 0) {
// imgSizeW_ = imgSize_;
}
outputD_ = outputSize(imgSizeD_,
sizeZ_,
paddingD_,
strideD_,
/* caffeMode */ false);
outputH_ = outputSize(imgSizeH_,
sizeY_,
paddingH_,
strideH_,
/* caffeMode */ false);
outputW_ = outputSize(imgSizeW_,
sizeX_,
paddingW_,
strideW_,
/* caffeMode */ false);
layerSize = outputD_ * outputH_ * outputW_ * channels_; layerSize = outputD_ * outputH_ * outputW_ * channels_;
getOutput().setFrameHeight(outputH_); getOutput().setFrameHeight(outputH_);
...@@ -100,37 +79,37 @@ void Pool3DLayer::forward(PassType passType) { ...@@ -100,37 +79,37 @@ void Pool3DLayer::forward(PassType passType) {
if (poolType_ == "avg") { if (poolType_ == "avg") {
outMat->avgPool3DForward(*inMat, outMat->avgPool3DForward(*inMat,
channels_,
imgSizeD_, imgSizeD_,
imgSizeH_, imgSizeH_,
imgSizeW_, imgSizeW_,
channels_, outputD_,
outputH_,
outputW_,
sizeZ_, sizeZ_,
sizeY_, sizeY_,
sizeX_, sizeX_,
strideD_, strideD_,
strideH_, strideH_,
strideW_, strideW_,
outputD_,
outputH_,
outputW_,
paddingD_, paddingD_,
paddingH_, paddingH_,
paddingW_); paddingW_);
} else if (poolType_ == "max") { } else if (poolType_ == "max") {
outMat->maxPool3DForward(*inMat, outMat->maxPool3DForward(*inMat,
channels_,
imgSizeD_, imgSizeD_,
imgSizeH_, imgSizeH_,
imgSizeW_, imgSizeW_,
channels_, outputD_,
outputH_,
outputW_,
sizeZ_, sizeZ_,
sizeY_, sizeY_,
sizeX_, sizeX_,
strideD_, strideD_,
strideH_, strideH_,
strideW_, strideW_,
outputD_,
outputH_,
outputW_,
paddingD_, paddingD_,
paddingH_, paddingH_,
paddingW_); paddingW_);
...@@ -155,41 +134,41 @@ void Pool3DLayer::backward(const UpdateCallback& callback) { ...@@ -155,41 +134,41 @@ void Pool3DLayer::backward(const UpdateCallback& callback) {
imgSizeD_, imgSizeD_,
imgSizeH_, imgSizeH_,
imgSizeW_, imgSizeW_,
outputD_,
outputH_,
outputW_,
sizeZ_, sizeZ_,
sizeY_, sizeY_,
sizeZ_, sizeZ_,
strideD_, strideD_,
strideH_, strideH_,
strideW_, strideW_,
outputD_,
outputH_,
outputW_,
1,
1,
paddingD_, paddingD_,
paddingH_, paddingH_,
paddingW_); paddingW_,
1.0,
1.0);
} else if (poolType_ == "max") { } else if (poolType_ == "max") {
inGradMat->maxPool3DBackward(*inMat, inGradMat->maxPool3DBackward(*inMat,
*outGradMat,
*outMat,
imgSizeD_, imgSizeD_,
imgSizeH_, imgSizeH_,
imgSizeW_, imgSizeW_,
*outGradMat, outputD_,
*outMat, outputH_,
outputW_,
sizeZ_, sizeZ_,
sizeY_, sizeY_,
sizeZ_, sizeZ_,
strideD_, strideD_,
strideH_, strideH_,
strideW_, strideW_,
outputD_,
outputH_,
outputW_,
1,
1,
paddingD_, paddingD_,
paddingH_, paddingH_,
paddingW_); paddingW_,
1.0,
1.0);
} else { } else {
LOG(FATAL) << "Unknown pool type: " << poolType_; LOG(FATAL) << "Unknown pool type: " << poolType_;
} }
......
...@@ -44,5 +44,6 @@ protected: ...@@ -44,5 +44,6 @@ protected:
int imgSizeW_, imgSizeH_, imgSizeD_; int imgSizeW_, imgSizeH_, imgSizeD_;
int outputW_, outputH_, outputD_; int outputW_, outputH_, outputD_;
std::string poolType_; std::string poolType_;
MatrixPtr maxPoolIdx_;
}; };
} // namespace paddle } // namespace paddle
...@@ -1191,23 +1191,23 @@ void GpuMatrix::avgPoolBackward(Matrix& outGrad, ...@@ -1191,23 +1191,23 @@ void GpuMatrix::avgPoolBackward(Matrix& outGrad,
} }
void GpuMatrix::maxPool3DForward(Matrix& inputMat, void GpuMatrix::maxPool3DForward(Matrix& inputMat,
size_t channels,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
size_t channels, size_t outputD,
size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW) { size_t paddingW) {
CHECK(inputMat.useGpu_ == true) << "Matrix type are not equal"; CHECK(inputMat.useGpu_) << "Matrix type are not correct";
real* inputData = inputMat.getData(); real* inputData = inputMat.getData();
size_t num = inputMat.getHeight(); size_t num = inputMat.getHeight();
...@@ -1236,32 +1236,31 @@ void GpuMatrix::maxPool3DForward(Matrix& inputMat, ...@@ -1236,32 +1236,31 @@ void GpuMatrix::maxPool3DForward(Matrix& inputMat,
paddingD, paddingD,
paddingH, paddingH,
paddingW, paddingW,
data_, getData(),
getStride()); getStride());
} }
void GpuMatrix::maxPool3DBackward(Matrix& inputMat, void GpuMatrix::maxPool3DBackward(Matrix& inputMat,
Matrix& outGrad,
Matrix& outV,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
Matrix& outGrad, size_t outputD,
Matrix& outV, size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
real scaleTargets,
real scaleOutput,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW) { size_t paddingW,
CHECK(inputMat.useGpu_ == true && outGrad.useGpu_ == true && real scaleTargets,
outV.useGpu_ == true) real scaleOutput) {
CHECK(inputMat.useGpu_ && outGrad.useGpu_ && outV.useGpu_)
<< "Matrix type are not equal"; << "Matrix type are not equal";
real* inputData = inputMat.getData(); real* inputData = inputMat.getData();
...@@ -1300,28 +1299,28 @@ void GpuMatrix::maxPool3DBackward(Matrix& inputMat, ...@@ -1300,28 +1299,28 @@ void GpuMatrix::maxPool3DBackward(Matrix& inputMat,
paddingW, paddingW,
scaleTargets, scaleTargets,
scaleOutput, scaleOutput,
data_, getData(),
outGrad.getStride()); outGrad.getStride());
} }
void GpuMatrix::avgPool3DForward(Matrix& inputMat, void GpuMatrix::avgPool3DForward(Matrix& inputMat,
size_t channels,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
size_t channels, size_t outputD,
size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW) { size_t paddingW) {
CHECK(inputMat.useGpu_ == true) << "Matrix type are not equal"; CHECK(inputMat.useGpu_) << "Matrix type are not equal";
real* inputData = inputMat.getData(); real* inputData = inputMat.getData();
size_t frameNum = inputMat.getHeight(); size_t frameNum = inputMat.getHeight();
...@@ -1350,7 +1349,7 @@ void GpuMatrix::avgPool3DForward(Matrix& inputMat, ...@@ -1350,7 +1349,7 @@ void GpuMatrix::avgPool3DForward(Matrix& inputMat,
paddingD, paddingD,
paddingH, paddingH,
paddingW, paddingW,
data_, getData(),
getStride()); getStride());
} }
...@@ -1358,21 +1357,21 @@ void GpuMatrix::avgPool3DBackward(Matrix& outGrad, ...@@ -1358,21 +1357,21 @@ void GpuMatrix::avgPool3DBackward(Matrix& outGrad,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
size_t outputD,
size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
real scaleTargets,
real scaleOutput,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW) { size_t paddingW,
CHECK(outGrad.useGpu_ == true) << "Matrix type are not equal"; real scaleTargets,
real scaleOutput) {
CHECK(outGrad.useGpu_) << "Matrix type are not equal";
real* outDiff = outGrad.getData(); real* outDiff = outGrad.getData();
size_t frameNum = outGrad.getHeight(); size_t frameNum = outGrad.getHeight();
...@@ -1404,7 +1403,7 @@ void GpuMatrix::avgPool3DBackward(Matrix& outGrad, ...@@ -1404,7 +1403,7 @@ void GpuMatrix::avgPool3DBackward(Matrix& outGrad,
paddingW, paddingW,
scaleTargets, scaleTargets,
scaleOutput, scaleOutput,
data_, getData(),
outGrad.getStride()); outGrad.getStride());
} }
...@@ -2149,24 +2148,24 @@ void CpuMatrix::avgPoolBackward(Matrix& input, ...@@ -2149,24 +2148,24 @@ void CpuMatrix::avgPoolBackward(Matrix& input,
} }
void CpuMatrix::maxPool3DForward(Matrix& inputMat, void CpuMatrix::maxPool3DForward(Matrix& inputMat,
size_t channels,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
size_t channels, size_t outputD,
size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW) { size_t paddingW) {
real* inputData = inputMat.getData(); real* inputData = inputMat.getData();
real* outData = data_; real* outData = getData();
size_t num = inputMat.getHeight(); size_t num = inputMat.getHeight();
size_t inWidth = imgSizeW; size_t inWidth = imgSizeW;
size_t inHeight = imgSizeH; size_t inHeight = imgSizeH;
...@@ -2186,7 +2185,7 @@ void CpuMatrix::maxPool3DForward(Matrix& inputMat, ...@@ -2186,7 +2185,7 @@ void CpuMatrix::maxPool3DForward(Matrix& inputMat,
/* pool max one by one */ /* pool max one by one */
for (size_t n = 0; n < num; ++n) { // frame by frame for (size_t n = 0; n < num; ++n) { // frame by frame
if (!isContiguous()) { if (!isContiguous()) {
outData = data_ + n * outStride; outData = getData() + n * outStride;
} }
for (size_t c = 0; c < channels; ++c) { // channel by channel for (size_t c = 0; c < channels; ++c) { // channel by channel
for (size_t pd = 0; pd < outputD; ++pd) { for (size_t pd = 0; pd < outputD; ++pd) {
...@@ -2201,16 +2200,19 @@ void CpuMatrix::maxPool3DForward(Matrix& inputMat, ...@@ -2201,16 +2200,19 @@ void CpuMatrix::maxPool3DForward(Matrix& inputMat,
dstart = std::max(dstart, 0); dstart = std::max(dstart, 0);
hstart = std::max(hstart, 0); hstart = std::max(hstart, 0);
wstart = std::max(wstart, 0); wstart = std::max(wstart, 0);
real maxOutData = outData[(pd * outputH + ph) * outputW + pw];
for (int d = dstart; d < dend; ++d) { for (int d = dstart; d < dend; ++d) {
for (int h = hstart; h < hend; ++h) { for (int h = hstart; h < hend; ++h) {
for (int w = wstart; w < wend; ++w) { for (int w = wstart; w < wend; ++w) {
outData[(pd * outputH + ph) * outputW + pw] = if (maxOutData <
std::max(outData[(pd * outputH + ph) * outputW + pw], inputData[(d * inHeight + h) * inWidth + w]) {
inputData[(d * inHeight + h) * inWidth + w]); maxOutData = inputData[(d * inHeight + h) * inWidth + w];
} }
} }
} }
} }
outData[(pd * outputH + ph) * outputW + pw] = maxOutData;
}
} }
} }
// compute offset // compute offset
...@@ -2221,25 +2223,25 @@ void CpuMatrix::maxPool3DForward(Matrix& inputMat, ...@@ -2221,25 +2223,25 @@ void CpuMatrix::maxPool3DForward(Matrix& inputMat,
} }
void CpuMatrix::maxPool3DBackward(Matrix& image, void CpuMatrix::maxPool3DBackward(Matrix& image,
Matrix& outGrad,
Matrix& outV,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
Matrix& outGrad, size_t outputD,
Matrix& outV, size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
real scaleTargets,
real scaleOutput,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW) { size_t paddingW,
real scaleTargets,
real scaleOutput) {
size_t num = image.getHeight(); size_t num = image.getHeight();
size_t channels = size_t(width_ / imgSizeD / imgSizeH / imgSizeW); size_t channels = size_t(width_ / imgSizeD / imgSizeH / imgSizeW);
CHECK(image.getWidth() == imgSizeD * imgSizeH * imgSizeW * channels); CHECK(image.getWidth() == imgSizeD * imgSizeH * imgSizeW * channels);
...@@ -2247,19 +2249,18 @@ void CpuMatrix::maxPool3DBackward(Matrix& image, ...@@ -2247,19 +2249,18 @@ void CpuMatrix::maxPool3DBackward(Matrix& image,
CHECK(outV.getHeight() == outGrad.getHeight() && CHECK(outV.getHeight() == outGrad.getHeight() &&
outV.getWidth() == outGrad.getWidth()); outV.getWidth() == outGrad.getWidth());
real* tgtGrad = data_; real* tgtGrad = getData();
real* inData = image.getData(); real* inData = image.getData();
real* otData = outV.getData(); real* otData = outV.getData();
real* otGrad = outGrad.getData(); real* otGrad = outGrad.getData();
size_t outStride = outV.getStride(); size_t outStride = outV.getStride();
real* origOutData = otData; ;
real* origOutGrad = otGrad;
for (size_t n = 0; n < num; ++n) { for (size_t n = 0; n < num; ++n) {
if (!outV.isContiguous()) { if (!outV.isContiguous()) {
otData = origOutData + n * outStride; otData = outV.getData() + n * outStride;
otGrad = origOutGrad + n * outStride; otGrad = outGrad.getData() + n * outStride;
} }
for (size_t c = 0; c < channels; ++c) { for (size_t c = 0; c < channels; ++c) {
for (size_t pd = 0; pd < outputD; ++pd) { for (size_t pd = 0; pd < outputD; ++pd) {
...@@ -2274,7 +2275,7 @@ void CpuMatrix::maxPool3DBackward(Matrix& image, ...@@ -2274,7 +2275,7 @@ void CpuMatrix::maxPool3DBackward(Matrix& image,
dstart = std::max(dstart, 0); dstart = std::max(dstart, 0);
hstart = std::max(hstart, 0); hstart = std::max(hstart, 0);
wstart = std::max(wstart, 0); wstart = std::max(wstart, 0);
for (int d = 0; d < dend; ++d) { for (int d = dstart; d < dend; ++d) {
for (int h = hstart; h < hend; ++h) { for (int h = hstart; h < hend; ++h) {
for (int w = wstart; w < wend; ++w) { for (int w = wstart; w < wend; ++w) {
tgtGrad[(d * imgSizeH + h) * imgSizeW + w] = tgtGrad[(d * imgSizeH + h) * imgSizeW + w] =
...@@ -2299,19 +2300,19 @@ void CpuMatrix::maxPool3DBackward(Matrix& image, ...@@ -2299,19 +2300,19 @@ void CpuMatrix::maxPool3DBackward(Matrix& image,
} }
void CpuMatrix::avgPool3DForward(Matrix& input, void CpuMatrix::avgPool3DForward(Matrix& input,
size_t channels,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
size_t channels, size_t outputD,
size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW) { size_t paddingW) {
...@@ -2322,7 +2323,7 @@ void CpuMatrix::avgPool3DForward(Matrix& input, ...@@ -2322,7 +2323,7 @@ void CpuMatrix::avgPool3DForward(Matrix& input,
size_t inWidth = imgSizeW; size_t inWidth = imgSizeW;
CHECK(inDepth * inHeight * inWidth * channels == input.getWidth()); CHECK(inDepth * inHeight * inWidth * channels == input.getWidth());
CHECK(outputD * outputH * outputW * channels * num == height_ * width_); CHECK(outputD * outputH * outputW * channels * num == height_ * width_);
real* tgtData = data_; real* tgtData = getData();
real* inData = input.getData(); real* inData = input.getData();
for (size_t n = 0; n < num; ++n) { for (size_t n = 0; n < num; ++n) {
...@@ -2372,20 +2373,20 @@ void CpuMatrix::avgPool3DBackward(Matrix& input, ...@@ -2372,20 +2373,20 @@ void CpuMatrix::avgPool3DBackward(Matrix& input,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
size_t outputD,
size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
real scaleTargets,
real scaleOutput,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW) { size_t paddingW,
real scaleTargets,
real scaleOutput) {
size_t num = input.getHeight(); size_t num = input.getHeight();
size_t channels = input.getWidth() / outputD / outputH / outputW; size_t channels = input.getWidth() / outputD / outputH / outputW;
CHECK(imgSizeD * imgSizeH * imgSizeW * channels == getWidth()); CHECK(imgSizeD * imgSizeH * imgSizeW * channels == getWidth());
......
...@@ -933,19 +933,19 @@ public: ...@@ -933,19 +933,19 @@ public:
* in the sizeX of value * in the sizeX of value
*/ */
virtual void maxPool3DForward(Matrix& inputMat, virtual void maxPool3DForward(Matrix& inputMat,
size_t channels,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
size_t channels, size_t outputD,
size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW) { size_t paddingW) {
...@@ -953,42 +953,42 @@ public: ...@@ -953,42 +953,42 @@ public:
} }
virtual void maxPool3DBackward(Matrix& image, virtual void maxPool3DBackward(Matrix& image,
Matrix& outGrad,
Matrix& outV,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
Matrix& outGrad, size_t outputD,
Matrix& outV, size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
real scaleTargets,
real scaleOutput,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW) { size_t paddingW,
real scaleTargets,
real scaleOutput) {
LOG(FATAL) << "Not implemeted"; LOG(FATAL) << "Not implemeted";
} }
virtual void avgPool3DForward(Matrix& input, virtual void avgPool3DForward(Matrix& input,
size_t channels,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
size_t channels, size_t outputD,
size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW) { size_t paddingW) {
...@@ -999,20 +999,20 @@ public: ...@@ -999,20 +999,20 @@ public:
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
size_t outputD,
size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
real scaleTargets,
real scaleOutput,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW) { size_t paddingW,
real scaleTargets,
real scaleOutput) {
LOG(FATAL) << "Not implemeted"; LOG(FATAL) << "Not implemeted";
} }
...@@ -1435,60 +1435,59 @@ public: ...@@ -1435,60 +1435,59 @@ public:
size_t paddingH, size_t paddingH,
size_t paddingW); size_t paddingW);
/////////////////////////
void maxPool3DForward(Matrix& inputMat, void maxPool3DForward(Matrix& inputMat,
size_t channels,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
size_t channels, size_t outputD,
size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW); size_t paddingW);
void maxPool3DBackward(Matrix& image, void maxPool3DBackward(Matrix& image,
Matrix& outGrad,
Matrix& outV,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
Matrix& outGrad, size_t outputD,
Matrix& outV, size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
real scaleTargets,
real scaleOutput,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW); size_t paddingW,
real scaleTargets,
real scaleOutput);
void avgPool3DForward(Matrix& input, void avgPool3DForward(Matrix& input,
size_t channels,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
size_t channels, size_t outputD,
size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW); size_t paddingW);
...@@ -1497,20 +1496,20 @@ public: ...@@ -1497,20 +1496,20 @@ public:
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
size_t outputD,
size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
real scaleTargets,
real scaleOutput,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW); size_t paddingW,
real scaleTargets,
real scaleOutput);
void maxSequenceForward(Matrix& input, void maxSequenceForward(Matrix& input,
const IVector& sequence, const IVector& sequence,
...@@ -1670,60 +1669,60 @@ public: ...@@ -1670,60 +1669,60 @@ public:
real scaleOutput, real scaleOutput,
size_t paddingH, size_t paddingH,
size_t paddingW); size_t paddingW);
//////////////////////
void maxPool3DForward(Matrix& inputMat, void maxPool3DForward(Matrix& inputMat,
size_t channels,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
size_t channels, size_t outputD,
size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW); size_t paddingW);
void maxPool3DBackward(Matrix& image, void maxPool3DBackward(Matrix& image,
Matrix& outGrad,
Matrix& outV,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
Matrix& outGrad, size_t outputD,
Matrix& outV, size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
real scaleTargets,
real scaleOutput,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW); size_t paddingW,
real scaleTargets,
real scaleOutput);
void avgPool3DForward(Matrix& input, void avgPool3DForward(Matrix& input,
size_t channels,
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
size_t channels, size_t outputD,
size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW); size_t paddingW);
...@@ -1732,20 +1731,20 @@ public: ...@@ -1732,20 +1731,20 @@ public:
size_t imgSizeD, size_t imgSizeD,
size_t imgSizeH, size_t imgSizeH,
size_t imgSizeW, size_t imgSizeW,
size_t outputD,
size_t outputH,
size_t outputW,
size_t sizeZ, size_t sizeZ,
size_t sizeY, size_t sizeY,
size_t sizeX, size_t sizeX,
size_t strideD, size_t strideD,
size_t strideH, size_t strideH,
size_t strideW, size_t strideW,
size_t outputD,
size_t outputH,
size_t outputW,
real scaleTargets,
real scaleOutput,
size_t paddingD, size_t paddingD,
size_t paddingH, size_t paddingH,
size_t paddingW); size_t paddingW,
real scaleTargets,
real scaleOutput);
void maxSequenceForward(Matrix& input, void maxSequenceForward(Matrix& input,
const IVector& sequence, const IVector& sequence,
......
...@@ -1204,7 +1204,6 @@ TEST(Matrix, warpCTC) { ...@@ -1204,7 +1204,6 @@ TEST(Matrix, warpCTC) {
} }
} }
/////
void testMatrixPool3D(int depth, int height, int width) { void testMatrixPool3D(int depth, int height, int width) {
int channel = 3; int channel = 3;
int filterX = 3, filterY = 4, filterZ = 5; int filterX = 3, filterY = 4, filterZ = 5;
...@@ -1226,38 +1225,37 @@ void testMatrixPool3D(int depth, int height, int width) { ...@@ -1226,38 +1225,37 @@ void testMatrixPool3D(int depth, int height, int width) {
cpuImage->randomizeUniform(); cpuImage->randomizeUniform();
gpuImage->copyFrom(*cpuImage); gpuImage->copyFrom(*cpuImage);
// std::cout << "test maxPool3DForward...\n";
cpuOutput->maxPool3DForward(*cpuImage, cpuOutput->maxPool3DForward(*cpuImage,
channel,
depth, depth,
height, height,
width, width,
channel, outD,
outH,
outW,
filterZ, filterZ,
filterY, filterY,
filterX, filterX,
strideZ, strideZ,
strideY, strideY,
strideX, strideX,
outD,
outH,
outW,
padZ, padZ,
padY, padY,
padX); padX);
gpuOutput->maxPool3DForward(*gpuImage, gpuOutput->maxPool3DForward(*gpuImage,
channel,
depth, depth,
height, height,
width, width,
channel, outD,
outH,
outW,
filterZ, filterZ,
filterY, filterY,
filterX, filterX,
strideZ, strideZ,
strideY, strideY,
strideX, strideX,
outD,
outH,
outW,
padZ, padZ,
padY, padY,
padX); padX);
...@@ -1265,39 +1263,38 @@ void testMatrixPool3D(int depth, int height, int width) { ...@@ -1265,39 +1263,38 @@ void testMatrixPool3D(int depth, int height, int width) {
cpuImage->randomizeUniform(); cpuImage->randomizeUniform();
gpuImage->copyFrom(*cpuImage); gpuImage->copyFrom(*cpuImage);
// std::cout << "test avgPool3DForward...\n";
cpuOutput->avgPool3DForward(*cpuImage, cpuOutput->avgPool3DForward(*cpuImage,
channel,
depth, depth,
height, height,
width, width,
channel, outD,
outH,
outW,
filterZ, filterZ,
filterY, filterY,
filterX, filterX,
strideZ, strideZ,
strideY, strideY,
strideX, strideX,
outD,
outH,
outW,
padZ, padZ,
padY, padY,
padX); padX);
gpuOutput->avgPool3DForward(*gpuImage, gpuOutput->avgPool3DForward(*gpuImage,
channel,
depth, depth,
height, height,
width, width,
channel, outD,
outH,
outW,
filterZ, filterZ,
filterY, filterY,
filterX, filterX,
strideZ, strideZ,
strideY, strideY,
strideX, strideX,
outD,
outH,
outW,
padZ, padZ,
padY, padY,
padX); padX);
...@@ -1306,98 +1303,96 @@ void testMatrixPool3D(int depth, int height, int width) { ...@@ -1306,98 +1303,96 @@ void testMatrixPool3D(int depth, int height, int width) {
gpuImage->copyFrom(*cpuImage); gpuImage->copyFrom(*cpuImage);
cpuOutput->randomizeUniform(); cpuOutput->randomizeUniform();
gpuOutput->copyFrom(*cpuOutput); gpuOutput->copyFrom(*cpuOutput);
// std::cout << "test avgPool3DBackward...\n";
cpuImage->avgPool3DBackward(*cpuOutput, cpuImage->avgPool3DBackward(*cpuOutput,
depth, depth,
height, height,
width, width,
outD,
outH,
outW,
filterZ, filterZ,
filterY, filterY,
filterX, filterX,
strideZ, strideZ,
strideY, strideY,
strideX, strideX,
outD,
outH,
outW,
1,
1,
padZ, padZ,
padY, padY,
padX); padX,
1.0,
1.0);
gpuImage->avgPool3DBackward(*gpuOutput, gpuImage->avgPool3DBackward(*gpuOutput,
depth, depth,
height, height,
width, width,
outD,
outH,
outW,
filterZ, filterZ,
filterY, filterY,
filterX, filterX,
strideZ, strideZ,
strideY, strideY,
strideX, strideX,
outD,
outH,
outW,
1,
1,
padZ, padZ,
padY, padY,
padX); padX,
1.0,
1.0);
TensorCheckErr(*cpuImage, *gpuImage); TensorCheckErr(*cpuImage, *gpuImage);
cpuImage->randomizeUniform(); cpuImage->randomizeUniform();
gpuImage->copyFrom(*cpuImage); gpuImage->copyFrom(*cpuImage);
cpuOutput->randomizeUniform(); cpuOutput->randomizeUniform();
gpuOutput->copyFrom(*cpuOutput); gpuOutput->copyFrom(*cpuOutput);
// std::cout << "test maxPool3DBackward...\n";
cpuImage->maxPool3DBackward(*cpuImage, cpuImage->maxPool3DBackward(*cpuImage,
*cpuOutput,
*cpuOutput,
depth, depth,
height, height,
width, width,
*cpuOutput, outD,
*cpuOutput, outH,
outW,
filterZ, filterZ,
filterY, filterY,
filterX, filterX,
strideZ, strideZ,
strideY, strideY,
strideX, strideX,
outD,
outH,
outW,
1,
1,
padZ, padZ,
padY, padY,
padX); padX,
1.0,
1.0);
gpuImage->maxPool3DBackward(*gpuImage, gpuImage->maxPool3DBackward(*gpuImage,
*gpuOutput,
*gpuOutput,
depth, depth,
height, height,
width, width,
*gpuOutput, outD,
*gpuOutput, outH,
outW,
filterZ, filterZ,
filterY, filterY,
filterX, filterX,
strideZ, strideZ,
strideY, strideY,
strideX, strideX,
outD,
outH,
outW,
1,
1,
padZ, padZ,
padY, padY,
padX); padX,
1.0,
1.0);
TensorCheckErr(*cpuImage, *gpuImage); TensorCheckErr(*cpuImage, *gpuImage);
} }
TEST(Matrix, Pool3D) { TEST(Matrix, Pool3D) {
for (auto depth : {9, 16, 64, 128}) { for (auto depth : {9, 16, 64}) {
for (auto height : {9, 11, 128, 256}) { for (auto height : {9, 11, 128}) {
for (auto width : {9, 32, 128}) { for (auto width : {9, 32, 128}) {
VLOG(3) << "depth=" << depth << " height=" << height VLOG(3) << "depth=" << depth << " height=" << height
<< " width=" << width; << " width=" << width;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册