Add crop layers for supporting FCN model#2490
Add crop layers for supporting FCN model#2490wanghaoshuang merged 20 commits intoPaddlePaddle:developfrom
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.
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
There was a problem hiding this comment.
Both Caffe and MXNet use offset to indicate crop_corner.
paddle/gserver/layers/CropLayer.cpp
Outdated
There was a problem hiding this comment.
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.
@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
| """ | ||
| if isinstance(input, LayerOutput): | ||
| input = [input] | ||
| elif isinstance(input, Projection): |
|
|
||
| @wrap_name_default() | ||
| @layer_support() | ||
| def crop_layer(input, axis, offset, shape=None, name=None, layer_attr=None): |
| :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.
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.
The crop layer crop -> The crop layer crops
| 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.
应该是:inputLayers_[1]?看Python接口里,第2个input是reference_input
There was a problem hiding this comment.
这里是取原始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.
Python接口写的是支持一个或两个输入,这块却是CHECK_EQ ?
2. Add crop layer unitest 3. Fix bugs
|
@qingqing01 crop layer相关bugs已经fixed.已commit. |
solve #2470