From 15067de20184c68ff8315d8d821e4375102c27c0 Mon Sep 17 00:00:00 2001 From: wanghaoshuang Date: Wed, 6 Nov 2019 16:44:53 +0800 Subject: [PATCH] 1. Rename common to core package. 2. Add copyright. 3. Rmove FLOPS from graph wrapper. --- paddleslim/{common => core}/__init__.py | 0 paddleslim/core/__init__.pyc | Bin 0 -> 219 bytes paddleslim/{common => core}/graph_wrapper.py | 46 ------------------- paddleslim/core/graph_wrapper.pyc | Bin 0 -> 14549 bytes paddleslim/prune/pruner.py | 2 +- tests/layers.py | 13 ++++++ tests/test_prune.py | 13 ++++++ 7 files changed, 27 insertions(+), 47 deletions(-) rename paddleslim/{common => core}/__init__.py (100%) create mode 100644 paddleslim/core/__init__.pyc rename paddleslim/{common => core}/graph_wrapper.py (84%) create mode 100644 paddleslim/core/graph_wrapper.pyc diff --git a/paddleslim/common/__init__.py b/paddleslim/core/__init__.py similarity index 100% rename from paddleslim/common/__init__.py rename to paddleslim/core/__init__.py diff --git a/paddleslim/core/__init__.pyc b/paddleslim/core/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e532c8d43acacca16231998b9717c3d81d7b94d8 GIT binary patch literal 219 zcmYL@Q3}E^42F|VPzFPf;G4yV?E)g6zz6kdAYrUUEA3X+ig-5PJc?KF0;VV!k}t`h z{~_7C$Y0OLv4vj6Jo(Q4UIq3 zjp_C9mD6pxm07ZI!7d?=8AOe>L^26~ggLKeS@}jOtAjPJYJ2DUt|Bs>iA1Hp#|fKO Ru2)y9*HfNDdS-?>egJd{CuINt literal 0 HcmV?d00001 diff --git a/paddleslim/common/graph_wrapper.py b/paddleslim/core/graph_wrapper.py similarity index 84% rename from paddleslim/common/graph_wrapper.py rename to paddleslim/core/graph_wrapper.py index 04d8b077..72de894a 100644 --- a/paddleslim/common/graph_wrapper.py +++ b/paddleslim/core/graph_wrapper.py @@ -329,52 +329,6 @@ class GraphWrapper(object): ret += np.product(param.shape()) return ret - def flops(self, only_conv=False): - """ - Get the flops of current graph. - Args: - only_conv: Only calculating the conv layers. default: False. - Returns: - int: The flops of current graph. - """ - flops = 0 - for op in self.ops(): - if op.type() in ['conv2d', 'depthwise_conv2d']: - filter_shape = op.inputs("Filter")[0].shape() - input_shape = op.inputs("Input")[0].shape() - output_shape = op.outputs("Output")[0].shape() - c_out, c_in, k_h, k_w = filter_shape - _, _, h_out, w_out = output_shape - groups = op.attr("groups") - kernel_ops = k_h * k_w * (c_in / groups) - if len(op.inputs("Bias")) > 0: - with_bias = 1 - else: - with_bias = 0 - flops += 2 * h_out * w_out * c_out * (kernel_ops + with_bias) - elif op.type() == 'pool2d' and not only_conv: - input_shape = op.inputs("X")[0].shape() - output_shape = op.outputs("Out")[0].shape() - _, c_out, h_out, w_out = output_shape - k_size = op.attr("ksize") - flops += h_out * w_out * c_out * (k_size[0]**2) - - elif op.type() == 'mul' and not only_conv: - x_shape = list(op.inputs("X")[0].shape()) - y_shape = op.inputs("Y")[0].shape() - if x_shape[0] == -1: - x_shape[0] = 1 - flops += 2 * x_shape[0] * x_shape[1] * y_shape[1] - - elif op.type() in ['relu', 'sigmoid', 'batch_norm' - ] and not only_conv: - input_shape = list(op.inputs("X")[0].shape()) - if input_shape[0] == -1: - input_shape[0] = 1 - flops += np.product(input_shape) - - return flops - def update_param_shape(self, scope): """ Update the shape of parameters in the graph according to tensors in scope. diff --git a/paddleslim/core/graph_wrapper.pyc b/paddleslim/core/graph_wrapper.pyc new file mode 100644 index 0000000000000000000000000000000000000000..591351096db4cc217efe7320165cd2f13ca1ddb2 GIT binary patch literal 14549 zcmds8O>`Z}Rjz(ddeYO6B}=wv95R_6&y4+MU^F2^aAM44Y-`5jz{sXOiDv{((|X;K z+UnQ++||#L5{Z+81Du>>6|w*ptXZ(m1`dlXSg>ae>|h6nB@6hzTmAQ>XV2)_;T*8s zrRwUg>bm#Vz4yDfO3nYApIQBfzq#L4`M)-PzlTfzD+(X~Efp!XUe+zO-YD9eYQ0(1 zC)E0c)Eg?ARK1p3Zz+rYn{q#;)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%g(!V2XD)S0p5`Vqf<0~JnZh^&&{aiiP^U6CQ%f~Uj=E|o^xmgGO}y*4!vv|Iy4a` zVxwov*~z^k*ZB$?IPGNP0S1;#u0vtS4&>OJkeuCBb9Vh*26Or%iaE>tEW#^YXe>0F O*6>ez;@sEHeeyq`X4W47 literal 0 HcmV?d00001 diff --git a/paddleslim/prune/pruner.py b/paddleslim/prune/pruner.py index 85567a99..aa7f0f59 100644 --- a/paddleslim/prune/pruner.py +++ b/paddleslim/prune/pruner.py @@ -14,7 +14,7 @@ import numpy as np import paddle.fluid as fluid -from ..common import VarWrapper, OpWrapper, GraphWrapper +from ..core import VarWrapper, OpWrapper, GraphWrapper __all__ = ["prune"] diff --git a/tests/layers.py b/tests/layers.py index 78ef8395..140ff591 100644 --- a/tests/layers.py +++ b/tests/layers.py @@ -1,3 +1,16 @@ +# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License" +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. import paddle.fluid as fluid from paddle.fluid.param_attr import ParamAttr diff --git a/tests/test_prune.py b/tests/test_prune.py index 90affb76..3fdaa867 100644 --- a/tests/test_prune.py +++ b/tests/test_prune.py @@ -1,3 +1,16 @@ +# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License" +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. import sys sys.path.append("../") import unittest -- GitLab