Skip to content

Commit f90c06b

Browse files
Merge pull request #5888 from wanghaoshuang/fix_crop
Add size, height and width for crop layer and switch order layer.
2 parents 728e8b1 + a88d98c commit f90c06b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

python/paddle/trainer/config_parser.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2400,6 +2400,14 @@ def __init__(self, name, inputs, axis, offset, shape, **xargs):
24002400
image_conf.img_size_y = input_layer.height
24012401
image_conf.channels = input_layer.size / (input_layer.width *
24022402
input_layer.height)
2403+
# only support for 4-dims inputs and NCHW order
2404+
if (len(self.config.inputs) == 2):
2405+
self.set_layer_height_width(
2406+
self.get_input_layer(1).height, self.get_input_layer(1).width)
2407+
self.set_layer_size(self.get_input_layer(1).size)
2408+
else:
2409+
self.set_layer_height_width(shape[-2], shape[-1])
2410+
self.set_layer_size(reduce(lambda x, y: x * y, shape[1:]))
24032411

24042412

24052413
@config_layer('batch_norm')
@@ -3849,6 +3857,26 @@ def __init__(self, name, inputs, reshape, **xargs):
38493857
name, 'switch_order', 0, inputs=inputs, **xargs)
38503858
self.config.reshape_conf.height_axis.extend(reshape['height'])
38513859
self.config.reshape_conf.width_axis.extend(reshape['width'])
3860+
input_layer = self.get_input_layer(0)
3861+
if reshape is None:
3862+
self.set_layer_size(input_layer.size)
3863+
else:
3864+
in_h = input_layer.height
3865+
in_w = input_layer.width
3866+
out_dims = None
3867+
if input_layer.has_depth():
3868+
in_d = input_layer.depth
3869+
in_c = input_layer.size / in_h / in_w / in_d
3870+
# batch_size, depth, height, width, channel
3871+
out_dims = [0, in_d, in_h, in_w, in_c]
3872+
else:
3873+
in_c = input_layer.size / in_h / in_w
3874+
# batch_size, height, width, channel
3875+
out_dims = [0, in_h, in_w, in_c]
3876+
# Because (reshape['width'][0] > 0) always be true.
3877+
# So out_dims[0] won't be used.
3878+
size = reduce(lambda x, y: x * y, out_dims[reshape['width'][0]:])
3879+
self.set_layer_size(size)
38523880

38533881

38543882
@config_layer('scale_sub_region')

python/paddle/trainer_config_helpers/layers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6873,6 +6873,7 @@ def crop_layer(input, offset, axis=2, shape=None, name=None, layer_attr=None):
68736873
68746874
:param input: The input of this layer. If two inputs are given, the second one
68756875
will be regarded as the reference.
6876+
And the input must be 4-dims and in NCHW order.
68766877
:type input: LayerOutput | Sequence
68776878
:param offset: The crop offset.
68786879
:type offset: Sequence

0 commit comments

Comments
 (0)