提交 6245fed2 编写于 作者: H Haonan

rotate_layer python interface fixes

上级 7f4042ec
......@@ -95,6 +95,9 @@ void FeatureMapExpandLayer::forward(PassType passType) {
void FeatureMapExpandLayer::backward(const UpdateCallback& callback) {
MatrixPtr inGrad = getInputGrad(0);
if (NULL == inGrad) {
return;
}
MatrixPtr outGrad = getOutputGrad();
size_t batchSize = getInput(0).getBatchSize();
int imgSize = inGrad->getWidth();
......
......@@ -68,8 +68,8 @@ bool GruStepLayer::init(const LayerMap& layerMap,
if (!Layer::init(layerMap, parameterMap)) return false;
CHECK_EQ(2U, inputLayers_.size());
CHECK_EQ(getSize() * getSize() * 3, parameters_[1]->getSize());
weight_.reset(new Weight(getSize(), getSize() * 3, parameters_[1]));
CHECK_EQ(getSize() * getSize() * 3, parameters_[0]->getSize());
weight_.reset(new Weight(getSize(), getSize() * 3, parameters_[0]));
if (biasParameter_.get() != NULL) {
CHECK_EQ(getSize() * 3, biasParameter_->getSize());
......
......@@ -25,6 +25,8 @@ bool RotateLayer::init(const LayerMap& layerMap,
CHECK_EQ(inputLayers_.size(), 1UL);
height_ = config_.height();
width_ = config_.width();
CHECK_GT(height_, 0);
CHECK_GT(width_, 0);
return true;
}
......
......@@ -1969,13 +1969,13 @@ class ResizeLayer(LayerBase):
@config_layer('rotate')
class RotateLayer(LayerBase):
def __init__(self, name, inputs, height, device=None):
def __init__(self, name, inputs, height, width, device=None):
super(RotateLayer, self).__init__(
name, 'rotate', 0, inputs=inputs, device=device)
config_assert(
len(self.inputs) == 1,
'RotateLayer must have one and only one input')
self.config.height = height
self.set_layer_height_width(height, width)
self.set_layer_size(self.get_input_layer(0).size)
......@@ -3007,7 +3007,7 @@ class GruStepLayer(LayerBase):
config_assert(input_layer1.size == size,
'input_layer1.size != layer.size')
self.config.active_gate_type = active_gate_type
self.create_input_parameter(1, size * size * 3, [size, size * 3])
self.create_input_parameter(0, size * size * 3, [size, size * 3])
self.create_bias_parameter(bias, size * 3)
......
......@@ -1677,22 +1677,23 @@ def trans_layer(input, name=None, layer_attr=None):
@wrap_name_default()
@layer_support()
def rotate_layer(input, height, name=None, layer_attr=None):
def rotate_layer(input, height, width, name=None, layer_attr=None):
"""
A layer for rotation (clock-wise), usually used when the input sample
is some image or map.
A layer for rotating 90 degrees (clock-wise), usually used when the input sample
is some image or feature map.
.. math::
y(j,i) = x(M-i-1,j)
y(j,i,:) = x(M-i-1,j,:)
where :math:`x` is (M x N) input, and :math:`y` is (N x M) output.
where :math:`x` is (M x N x C) input, and :math:`y` is (N x M x C) output.
The example usage is:
.. code-block:: python
rot = rotate_layer(input=layer,
height=100)
height=100,
width=100)
:param input: Input layer.
:type input: LayerOutput
......@@ -1709,6 +1710,7 @@ def rotate_layer(input, height, name=None, layer_attr=None):
l = Layer(
name=name,
height=height,
width=width,
type=LayerType.ROTATE_LAYER,
inputs=[input.name],
**ExtraLayerAttribute.to_kwargs(layer_attr))
......
......@@ -39,7 +39,7 @@ z1 = mixed_layer(
assert z1.size > 0
y2 = fc_layer(input=y, size=15)
z2 = rotate_layer(input=y2, height=5)
z2 = rotate_layer(input=y2, height=5, width=3)
cos1 = cos_sim(a=x1, b=y1)
cos3 = cos_sim(a=x1, b=y2, size=3)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册