From 880774d1418d53a3f4cf103891bc77ebed05e685 Mon Sep 17 00:00:00 2001 From: Haonan Date: Wed, 9 Nov 2016 17:48:17 -0800 Subject: [PATCH 1/2] change the act.name for LinearActivation() to "linear" so that it won't fail in hl_activetype; also fix the hasinputsset in submodel --- python/paddle/trainer/config_parser.py | 10 +++++----- python/paddle/trainer_config_helpers/activations.py | 8 ++++---- python/paddle/trainer_config_helpers/layers.py | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/python/paddle/trainer/config_parser.py b/python/paddle/trainer/config_parser.py index 73631602a9..2abbf56503 100644 --- a/python/paddle/trainer/config_parser.py +++ b/python/paddle/trainer/config_parser.py @@ -218,7 +218,7 @@ def Inputs(*args): @config_func def HasInputsSet(): - return len(g_config.model_config.input_layer_names) != 0 + return len(g_current_submodel.input_layer_names) != 0 # Define the name of the output layers of the NeuralNetwork. @@ -1120,14 +1120,14 @@ def parse_block_expand(block_expand, input_layer_name, block_expand_conf): block_expand_conf.output_x = 0 else: block_expand_conf.output_x = cnn_output_size( - block_expand.img_size_x, block_expand.block_x, + block_expand.img_size_x, block_expand.block_x, block_expand.padding_x, block_expand.stride_x, False) if block_expand_conf.img_size_y == 0: block_expand_conf.output_y = 0 else: block_expand_conf.output_y = cnn_output_size( - block_expand.img_size_y, block_expand.block_y, + block_expand.img_size_y, block_expand.block_y, block_expand.padding_y, block_expand.stride_y, False) def parse_maxout(maxout, input_layer_name, maxout_conf): @@ -1135,7 +1135,7 @@ def parse_maxout(maxout, input_layer_name, maxout_conf): maxout_conf.groups = maxout.groups maxout_conf.img_size_x = maxout.img_size_x maxout_conf.img_size_y = maxout.img_size_y - + # Define an evaluator @config_func def Evaluator( @@ -1773,7 +1773,7 @@ class MaxOutLayer(LayerBase): self.config.inputs[0].maxout_conf) maxout_conf = self.config.inputs[0].maxout_conf self.set_layer_size(g_layer_map[input_layer.name].size / maxout_conf.groups) - + # key: cost type # value: cost class g_cost_map = {} diff --git a/python/paddle/trainer_config_helpers/activations.py b/python/paddle/trainer_config_helpers/activations.py index ad5cdc0a0e..29b5437446 100644 --- a/python/paddle/trainer_config_helpers/activations.py +++ b/python/paddle/trainer_config_helpers/activations.py @@ -23,9 +23,9 @@ __all__ = ["TanhActivation", "SigmoidActivation", class BaseActivation(object): """ - A mark for activation class. + A mark for activation class. Each activation inherit BaseActivation, which has two parameters. - + :param name: activation name in paddle config. :type name: basestring :param support_hppl: True if supported by hppl. HPPL is a library used by paddle @@ -104,7 +104,7 @@ class IdentityActivation(BaseActivation): Just do nothing for output both forward/backward. """ - def __init__(self): BaseActivation.__init__(self, '', False) + def __init__(self): BaseActivation.__init__(self, 'linear', False) LinearActivation = IdentityActivation @@ -194,7 +194,7 @@ class SquareActivation(BaseActivation): class ExpActivation(BaseActivation): """ Exponential Activation. - + .. math:: f(z) = e^z. """ diff --git a/python/paddle/trainer_config_helpers/layers.py b/python/paddle/trainer_config_helpers/layers.py index 6b5d39a471..bf1d0631aa 100644 --- a/python/paddle/trainer_config_helpers/layers.py +++ b/python/paddle/trainer_config_helpers/layers.py @@ -1657,7 +1657,7 @@ def img_pool_layer(input, pool_size, name=None, :type pool_size_y: int|None :param num_channels: number of input channel. :type num_channels: int - :param pool_type: pooling type. MaxPooling or AveragePooling. Default is + :param pool_type: pooling type. MaxPooling or AvgPooling. Default is MaxPooling. :type pool_type: BasePoolingType :param stride: stride width of pooling. From 45f6e1abee60f0bb14c84b455ffe47a903c3c806 Mon Sep 17 00:00:00 2001 From: Haonan Date: Thu, 10 Nov 2016 16:29:23 -0800 Subject: [PATCH 2/2] change hlactivetype instead of act.name --- paddle/utils/Util.cpp | 2 +- python/paddle/trainer_config_helpers/activations.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/paddle/utils/Util.cpp b/paddle/utils/Util.cpp index 2cdff9d1ac..b16d431465 100644 --- a/paddle/utils/Util.cpp +++ b/paddle/utils/Util.cpp @@ -378,7 +378,7 @@ hl_activation_mode_t hlActiveType(const std::string& type) { return HL_ACTIVATION_RELU; } else if (type == "tanh") { return HL_ACTIVATION_TANH; - } else if (type == "linear") { + } else if (type == "linear" || type == "") { return HL_ACTIVATION_LINEAR; } else { LOG(FATAL) << "Do not support activation type " << type; diff --git a/python/paddle/trainer_config_helpers/activations.py b/python/paddle/trainer_config_helpers/activations.py index 29b5437446..2202d0bf96 100644 --- a/python/paddle/trainer_config_helpers/activations.py +++ b/python/paddle/trainer_config_helpers/activations.py @@ -104,7 +104,7 @@ class IdentityActivation(BaseActivation): Just do nothing for output both forward/backward. """ - def __init__(self): BaseActivation.__init__(self, 'linear', False) + def __init__(self): BaseActivation.__init__(self, '', False) LinearActivation = IdentityActivation