-
Notifications
You must be signed in to change notification settings - Fork 5.9k
max pool Layer with mask #4891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
max pool Layer with mask #4891
Conversation
paddle/cuda/src/hl_cuda_cnn.cu
Outdated
| const int tgtStride) { | ||
| const int tgtStride, | ||
| real* maskData, | ||
| bool withMask) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not need withMask, we can check whether maskData a NULL pointer.
paddle/cuda/include/hl_cnn.h
Outdated
| * @param[out] tgtData output data. | ||
| * @param[in] tgtStride stride between output data samples. | ||
| * @param[out] maskData the location indices of select max data | ||
| * @param[in] withMask set true if output maskData |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove line 77 and 78.
| if (maxval < inputData[h * width + w]) | ||
| if (maxval < inputData[h * width + w]) { | ||
| maxval = inputData[h * width + w]; | ||
| max_index = h * width + w; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxval = inputData[max_index];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| * @param[out] maskData the location indices of select max data | ||
| * @param[in] withMask set true if output maskData | ||
| */ | ||
| extern void hl_maxpool_forward(const int frameCnt, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to add this interface. Only need to add a maskData parameter to the original interface.
paddle/gserver/layers/PoolLayer.h
Outdated
| int confPaddingY_; | ||
|
|
||
| std::string poolType_; | ||
| bool with_mask_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not need with_mask_.
| false); | ||
| } | ||
|
|
||
| void GpuMatrix::maxPoolForward(Matrix& inputMat, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, do not need to add a new interface.
paddle/gserver/layers/Projection.h
Outdated
| forward(); | ||
| } | ||
|
|
||
| void forward(const Argument* in, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not change this file.
We can add a PoolMaxWithMaskLayer, and create this layer in the PoolLayer::create when pool == "max-pool-with-mask" .
hedaoyuan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not modify the implementation of the original Layer. The current Operator refactoring is based on the Layer, modify the original Layer implementation may be confused on the reconstruction. You can add a PoolMaxWithMaskLayer to avoid modifying the original layer.
… poolmaxpool_with_mask
… poolmaxpool_with_mask
… poolmaxpool_with_mask
… poolmaxpool_with_mask
… poolmaxpool_with_mask
… poolmaxpool_with_mask
… poolmaxpool_with_mask
… poolmaxpool_with_mask
paddle/math/Matrix.cpp
Outdated
| for (int w = wstart; w < wend; ++w) { | ||
| outData[ph * outputW + pw] = std::max( | ||
| outData[ph * outputW + pw], inputData[h * imgSizeW + w]); | ||
| if (maskMatP == NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the if (maskMatP == NULL) can be inside the for loop? And use maskData == NULL instead of maskMatP == NULL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
paddle/math/Matrix.cpp
Outdated
| inputData += inLength; | ||
| outData += outLength; | ||
|
|
||
| if (maskMatP != NULL) maskData += outLength; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use maskData != NULL instead of maskMatP != NULL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| assert type(pool_type) in [AvgPooling, MaxPooling, MaxWithMaskPooling, CudnnAvgPooling, | ||
| CudnnMaxPooling], \ | ||
| "only (Cudnn)AvgPooling, (Cudnn)MaxPooling are supported" | ||
| "only (Cudnn)AvgPooling, (Cudnn)MaxPooling MaxWithMaskPooling are supported" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add , before MaxWithMaskPooling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| sizeY_, | ||
| confPaddingY_, | ||
| strideY_, | ||
| /* caffeMode */ false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it can be modified into caffeMode = true? The other Layer (Pooling, Conv) default is true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The caffeMode in poolProjection.cpp is false, i referred there. https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/gserver/layers/PoolProjection.cpp#L51
| maskMat->setData(maskData); | ||
| doOneMaxPoolingWithMaskOutputTest( | ||
| inputMat, "max-pool-with-mask", useGpu, maskMat); | ||
| /* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove line 108-118
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to delete the annotation symbol, it supports the gpu test
| pool->set_stride(sw); | ||
| pool->set_stride_y(sh); | ||
|
|
||
| int ow = outputSize(pool->img_size(), kw, pw, sw, /* caffeMode */ false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you change the value of caffeMode in the Layer, this also needs to be modified.
… poolmaxpool_with_mask
fix #4889
python usage: