diff --git a/fluid/image_classification/caffe2fluid/examples/imagenet/compare.py b/fluid/image_classification/caffe2fluid/examples/imagenet/compare.py index 45b1f5303ce77de7c7f5e3a232517c26e159b2fa..c995e6df17a4be068984cece06a9b3a33f6ea4f4 100644 --- a/fluid/image_classification/caffe2fluid/examples/imagenet/compare.py +++ b/fluid/image_classification/caffe2fluid/examples/imagenet/compare.py @@ -45,7 +45,7 @@ def calc_diff(f1, f2): sq_df = np.mean(df * df) return max_df, sq_df except Exception as e: - return -1.0, -1.0 + return 1.0, 1.0 def compare(path1, path2, no_exception): diff --git a/fluid/image_classification/caffe2fluid/kaffe/paddle/network.py b/fluid/image_classification/caffe2fluid/kaffe/paddle/network.py index 4b6f38be6647b23a4c79dcc7850aaab55fa6ffa8..0c1354530c6af3b35977bb51e830b89d481de6b6 100644 --- a/fluid/image_classification/caffe2fluid/kaffe/paddle/network.py +++ b/fluid/image_classification/caffe2fluid/kaffe/paddle/network.py @@ -245,10 +245,18 @@ class Network(object): @layer def prelu(self, input, channel_shared, name): - #fluid = import_fluid() - #output = fluid.layers.relu(input) - #return output - raise NotImplementedError('prelu not implemented') + fluid = import_fluid() + if channel_shared: + mode = 'all' + else: + mode = 'channel' + + prefix = name + '_' + output = fluid.layers.prelu( + input, + mode=mode, + param_attr=fluid.ParamAttr(name=prefix + 'negslope')) + return output def pool(self, pool_type, input, k_h, k_w, s_h, s_w, ceil_mode, padding, name): diff --git a/fluid/image_classification/caffe2fluid/kaffe/transformers.py b/fluid/image_classification/caffe2fluid/kaffe/transformers.py index b92e93bbd84989e39bd658d107166f68e9dc4a27..f436ec8cbfb49394ef2880dbf0cb46aeff7a6ca0 100644 --- a/fluid/image_classification/caffe2fluid/kaffe/transformers.py +++ b/fluid/image_classification/caffe2fluid/kaffe/transformers.py @@ -176,6 +176,7 @@ class DataReshaper(object): del node.reshaped_data return graph + class CropFuser(object): ''' Crop is to return a scalar output Blob for an input Blob of arbitrary size. @@ -197,7 +198,8 @@ class CropFuser(object): cls._traced_names[fname] = [] cls._traced_names[fname].append(tname) - def __init__(self, allowed_parent_types=[NodeKind.Input, NodeKind.DummyData]): + def __init__(self, + allowed_parent_types=[NodeKind.Input, NodeKind.DummyData]): self.allowed_parent_types = allowed_parent_types def __call__(self, graph): @@ -232,7 +234,11 @@ class CropFuser(object): def merge(self, parent, child): '''Merge the parent node into the child.''' - child.metadata['shape'] = [parent.output_shape.batch_size, parent.output_shape.channels, parent.output_shape.height, parent.output_shape.width] + child.metadata['shape'] = [ + parent.output_shape.batch_size, parent.output_shape.channels, + parent.output_shape.height, parent.output_shape.width + ] + class SubNodeFuser(object): ''' @@ -395,6 +401,8 @@ class ParameterNamer(object): names = ('scale', ) if getattr(node.parameters, 'bias_term', False): names = ('scale', 'offset') + elif node.kind == NodeKind.PReLU: + names = ('negslope', ) elif node.kind == "Normalize": names = ('scale', ) else: