Skip to content

Commit

Permalink
add configuration helper for resize layer.
Browse files Browse the repository at this point in the history
  • Loading branch information
lcy-seso authored and dzhwinter committed Oct 2, 2017
1 parent e9a9dd6 commit 9b54ad1
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion doc/api/v1/index_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Model Config API
trainer_config_helpers/optimizers.rst
trainer_config_helpers/data_sources.rst
trainer_config_helpers/layers.rst
trainer_config_helpers/activations.rst
trainer_config_helpers/activations.rst
trainer_config_helpers/poolings.rst
trainer_config_helpers/networks.rst
trainer_config_helpers/evaluators.rst
Expand Down
5 changes: 5 additions & 0 deletions doc/api/v2/config/layer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ clip
.. autoclass:: paddle.v2.layer.clip
:noindex:

resize
------
.. autoclass:: paddle.v2.layer.resize
:noindex:

slope_intercept
---------------
.. autoclass:: paddle.v2.layer.slope_intercept
Expand Down
25 changes: 24 additions & 1 deletion python/paddle/trainer_config_helpers/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
'img_pool3d_layer',
'scale_shift_layer',
'img_conv3d_layer',
'resize_layer',
]


Expand Down Expand Up @@ -250,6 +251,8 @@ class LayerType(object):
KMAX_SEQ_SCORE = 'kmax_seq_score'
SCALE_SHIFT_LAYER = 'scale_shift'

RESIZE = 'resize'

@staticmethod
def is_layer_type(type_name):
"""
Expand Down Expand Up @@ -6473,7 +6476,7 @@ def switch_order_layer(input,
act=None,
layer_attr=None):
"""
This layer switch dimension order of image input.
This layer switch dimension order of image input.
From order "batchSize, channels, height, width"
to order "batchSize, height, width, channels".
Expand Down Expand Up @@ -6932,3 +6935,23 @@ def scale_shift_layer(input, name=None, param_attr=None, bias_attr=None):
bias=ParamAttr.to_bias(bias_attr))
return LayerOutput(
name, LayerType.SCALE_SHIFT_LAYER, parents=[input], size=input.size)


@wrap_name_default("resize")
def resize_layer(input, size, name=None):
"""
The resize layer resizes the input matrix with a shape of [Height, Width]
into the output matrix with a shape of [Height x Width / size, size],
where size is the parameter of this layer indicating the output dimension.
:param input: The input to this layer.
:type input: LayerOutput.
:param name: The name of this layer. It is optional.
:type name: basestring
:param size: The resized output dimesion of this layer.
:type size: int
:return: A LayerOutput object.
:rtype: LayerOutput
"""
Layer(name=name, type=LayerType.RESIZE, inputs=Input(input.name), size=size)
return LayerOutput(name, LayerType.RESIZE, parents=[input], size=input.size)
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ test_prelu_layer test_row_conv test_detection_output_layer test_multibox_loss_la
test_recursive_topology test_gated_unit_layer test_clip_layer test_row_l2_norm_layer
test_kmax_seq_socre_layer test_sub_nested_seq_select_layer test_scale_shift_layer
test_seq_slice_layer test_cross_entropy_over_beam test_pooling3D_layer
test_conv3d_layer test_deconv3d_layer test_BatchNorm3D)
test_conv3d_layer test_deconv3d_layer test_BatchNorm3D test_resize_layer)

export whole_configs=(test_split_datasource)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
type: "nn"
layers {
name: "input"
type: "data"
size: 300
active_type: ""
}
layers {
name: "__resize_0__"
type: "resize"
size: 150
active_type: ""
inputs {
input_layer_name: "input"
}
}
input_layer_names: "input"
output_layer_names: "__resize_0__"
sub_models {
name: "root"
layer_names: "input"
layer_names: "__resize_0__"
input_layer_names: "input"
output_layer_names: "__resize_0__"
is_recurrent_layer_group: false
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from paddle.trainer_config_helpers import *

data = data_layer(name='input', size=300)
resized = resize_layer(input=data, size=150)

outputs(resized)

0 comments on commit 9b54ad1

Please sign in to comment.