fix above comments

revert-3824-remove_grad_op_type
chengduoZH 8 years ago
parent 2377d71947
commit 790379f147

@ -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,
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,
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,
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,
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() {
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) {
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) {
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:
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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -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) {
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) {
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) {
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;

Loading…
Cancel
Save