From 45b8c47e043e6163dc3e228bf2fb7a6f6cab9b43 Mon Sep 17 00:00:00 2001 From: liaogang Date: Mon, 7 Nov 2016 15:10:15 +0800 Subject: [PATCH] Add img_size for unit test --- cmake/flags.cmake | 6 ++--- paddle/gserver/layers/BilinearInterpLayer.cpp | 24 ++++++++++++------- paddle/gserver/tests/test_LayerGrad.cpp | 2 ++ proto/ModelConfig.proto.m4 | 11 +++++---- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/cmake/flags.cmake b/cmake/flags.cmake index 337db53b37f..e087770991a 100644 --- a/cmake/flags.cmake +++ b/cmake/flags.cmake @@ -65,9 +65,9 @@ endif() set(COMMON_FLAGS -fPIC -fno-omit-frame-pointer -# -Wall -# -Wextra -# -Werror + -Wall + -Wextra + -Werror -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wno-unused-parameter diff --git a/paddle/gserver/layers/BilinearInterpLayer.cpp b/paddle/gserver/layers/BilinearInterpLayer.cpp index 9f0c01a8385..f37efc824a2 100644 --- a/paddle/gserver/layers/BilinearInterpLayer.cpp +++ b/paddle/gserver/layers/BilinearInterpLayer.cpp @@ -23,7 +23,22 @@ REGISTER_LAYER(bilinear_interp, BilinearInterpLayer); size_t BilinearInterpLayer::getSize() { inImgH_ = inputLayers_[0]->getOutput().getFrameHeight(); inImgW_ = inputLayers_[0]->getOutput().getFrameWidth(); + + const BilinearInterpConfig& conf = config_.inputs(0).bilinear_interp_conf(); + if (inImgH_ == 0) { + inImgH_ = conf.img_size_y(); + } + if (inImgW_ == 0) { + inImgW_ = conf.img_size_x(); + } + + outImgH_ = conf.out_size_y(); + outImgW_ = conf.out_size_x(); + numChannels_ = conf.num_channels(); + + CHECK(outImgH_ > 0 && outImgW_ > 0); CHECK(inImgH_ > 0 && inImgW_ > 0); + CHECK(numChannels_); getOutput().setFrameHeight(outImgH_); getOutput().setFrameWidth(outImgW_); @@ -37,15 +52,6 @@ bool BilinearInterpLayer::init(const LayerMap& layerMap, CHECK_EQ(1, config_.inputs_size()); - const BilinearInterpConfig& conf = config_.inputs(0).bilinear_interp_conf(); - - outImgH_ = conf.out_size_y(); - outImgW_ = conf.out_size_x(); - numChannels_ = conf.num_channels(); - - CHECK(outImgH_ > 0 && outImgW_ > 0); - CHECK(numChannels_); - return true; } diff --git a/paddle/gserver/tests/test_LayerGrad.cpp b/paddle/gserver/tests/test_LayerGrad.cpp index 8ee89992ddf..b5b944833e4 100644 --- a/paddle/gserver/tests/test_LayerGrad.cpp +++ b/paddle/gserver/tests/test_LayerGrad.cpp @@ -40,6 +40,8 @@ TEST(Layer, BilinearInterpLayer) { LayerInputConfig* input = config.layerConfig.add_inputs(); BilinearInterpConfig* bilinear = input->mutable_bilinear_interp_conf(); + bilinear->set_img_size_x(32); + bilinear->set_img_size_y(32); bilinear->set_out_size_x(64); bilinear->set_out_size_y(64); bilinear->set_num_channels(4); diff --git a/proto/ModelConfig.proto.m4 b/proto/ModelConfig.proto.m4 index 41d08194277..479b457e55a 100644 --- a/proto/ModelConfig.proto.m4 +++ b/proto/ModelConfig.proto.m4 @@ -213,10 +213,13 @@ message OperatorConfig { } message BilinearInterpConfig { - // The size if output feature map. - required uint32 out_size_x = 1; - required uint32 out_size_y = 2; - required uint32 num_channels = 3; + // The size of input feature map. + optional uint32 img_size_x = 1; + optional uint32 img_size_y = 2; + // The size of output feature map. + required uint32 out_size_x = 3; + required uint32 out_size_y = 4; + required uint32 num_channels = 5; } message ImageConfig { -- GitLab