batch_norm.py 724 字节
Newer Older
J
jiangjiajun 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import copy


class BiasOpt:
    def __init__(self):
        self.conv_layers = [
            'fluid.layers.conv2d', 'fluid.layers.conv2d_transpose'
        ]
        self.act_layers = [
            'fluid.layers.relu', 'fluid.layers.relu6', 'fluid.layers.sigmoid',
            'fluid.layers.exp', 'fluid.layers.tanh', 'fluid.layers.softplus',
            'fluid.layers.leaky_relu'
        ]

    def run(self, graph):
        layers = copy.deepcopy(graph.layers)
        for layer_id, layer in layers.items():
            can_be_optimized = True
            if layer.kernel != "fluid.layers.elemenwise_mul":
                can_be_optimized = False
                continue
            input_ids = graph.edges_in[layer_id]