-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add crop layers for supporting FCN model #2490
Add crop layers for supporting FCN model #2490
Conversation
Cropping and Padding are the opposite operations. Can we use the padding function for this cropping operation? |
@qingqing01 @pkuyym padding function and cropping funtion is not opposite operations, strictly? 'Padding forward funtion' != 'Cropping backward function' |
@qingqing01 @pkuyym Thks for interpretion and discussion about cropping function and padding function. I think i got it. Padding function and cropping funtion is opposite operations. |
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.
This doc shows how to write a new layer. This code also needs the following contents.
-
Gradient check unit test in test_LayerGrad.
-
Python wrapper in config_parser.py
-
Python wrapper in trainer_config_helpers and its unit test.
proto/ModelConfig.proto
Outdated
required ImageConfig image_conf = 1; | ||
repeated uint32 crop_corner = 2; | ||
repeated uint32 crop_shape = 3; | ||
} |
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.
Both Caffe and MXNet use offset
to indicate crop_corner
.
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.
Thx,get it.
paddle/gserver/layers/CropLayer.cpp
Outdated
|
||
void CropLayer::forward(PassType passType) { | ||
Layer::forward(passType); | ||
MatrixPtr input = inputLayers_[0]->getOutputValue(); |
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.
This layer should be able to accept two inputs, get the height and width from the second input. So, we can support to accept one or two inputs.
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.
Get it.
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.
@qingqing01 I have submit a pr to add python wrapper and grad test for crop layer. But TeamCity build job was blocked by issue #2490
f9c7e96
to
e31ccd6
Compare
@wanghaoshuang 如果提交了comments,请回复下哈~ |
1. change configure content to 'axis, offset, shape' 2. add an optional input to crop layer as cropping reference
1. change configure content to 'axis, offset, shape' 2. add an optional input to crop layer as cropping reference
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 isinstance(input, LayerOutput): | ||
input = [input] | ||
elif isinstance(input, Projection): |
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.
不支持Projection
输入,应该去掉。
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.
Fixed.
|
||
@wrap_name_default() | ||
@layer_support() | ||
def crop_layer(input, axis, offset, shape=None, name=None, layer_attr=None): |
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.
axis给个默认值吧。
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.
fixed
:param offset: The crop offset | ||
:type offset: Sequence | ||
:param shape: The shape to be cropped. Default is None. | ||
:type shape: Sqquence | None |
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.
Sqquence是啥?
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.
Fixed. Sqquence->Sequence
@layer_support() | ||
def crop_layer(input, axis, offset, shape=None, name=None, layer_attr=None): | ||
""" | ||
The crop layer crop images by offset and shape. User can set crop shape by |
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 crop layer crop -> The crop layer crops
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.
fixed
paddle/gserver/layers/CropLayer.cpp
Outdated
inDims_.setDim(0, batchSize); | ||
int h = inputLayers_[0]->getOutput().getFrameHeight(); | ||
if (h != 0) inDims_.setDim(2, h); | ||
int w = inputLayers_[0]->getOutput().getFrameWidth(); |
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.
应该是:inputLayers_[1]?看Python接口里,第2个input是reference_input
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.
这里是取原始input的dims,所以是inputLayers_[0].
paddle/gserver/layers/CropLayer.cpp
Outdated
} | ||
|
||
void CropLayer::setTensorDim(const size_t batchSize) { | ||
CHECK_EQ(static_cast<int>(inputLayers_.size()), 2); |
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.
Python接口写的是支持一个或两个输入,这块却是CHECK_EQ
?
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.
Fixed.
2. Add crop layer unitest 3. Fix bugs
@qingqing01 crop layer相关bugs已经fixed.已commit. |
solve #2470