예제 #1
0
    def __init__(
        self,
        layer = [],
        combine_fn = tf.minimum,
        name ='elementwise_layer',
        act = None,
    ):
        Layer.__init__(self, name=name)
        '''
        if act:
            #print("  [TL] ElementwiseLayer %s: size:%s fn:%s, act:%s" % (
            #self.name, layer[0].outputs.get_shape(), combine_fn.__name__, act.__name__))
        else:
            #print("  [TL] ElementwiseLayer %s: size:%s fn:%s" % (
            #self.name, layer[0].outputs.get_shape(), combine_fn.__name__))
        '''
        self.outputs = layer[0].outputs
        # #print(self.outputs._shape, type(self.outputs._shape))
        for l in layer[1:]:
            # assert str(self.outputs.get_shape()) == str(l.outputs.get_shape()), "Hint: the input shapes should be the same. %s != %s" %  (self.outputs.get_shape() , str(l.outputs.get_shape()))
            self.outputs = combine_fn(self.outputs, l.outputs, name=name)
        if act:
            self.outputs = act(self.outputs)
        self.all_layers = list(layer[0].all_layers)
        self.all_params = list(layer[0].all_params)
        self.all_drop = dict(layer[0].all_drop)

        for i in range(1, len(layer)):
            self.all_layers.extend(list(layer[i].all_layers))
            self.all_params.extend(list(layer[i].all_params))
            self.all_drop.update(dict(layer[i].all_drop))

        self.all_layers = list_remove_repeat(self.all_layers)
        self.all_params = list_remove_repeat(self.all_params)
    def __init__(
        self,
        layer = [],
        combine_fn = tf.minimum,
        name ='elementwise_layer',
        act = None,
    ):
        Layer.__init__(self, name=name)

        if act:
            print("  [TL] ElementwiseLayer %s: size:%s fn:%s, act:%s" % (
            self.name, layer[0].outputs.get_shape(), combine_fn.__name__, act.__name__))
        else:
            print("  [TL] ElementwiseLayer %s: size:%s fn:%s" % (
            self.name, layer[0].outputs.get_shape(), combine_fn.__name__))

        self.outputs = layer[0].outputs
        # print(self.outputs._shape, type(self.outputs._shape))
        for l in layer[1:]:
            # assert str(self.outputs.get_shape()) == str(l.outputs.get_shape()), "Hint: the input shapes should be the same. %s != %s" %  (self.outputs.get_shape() , str(l.outputs.get_shape()))
            self.outputs = combine_fn(self.outputs, l.outputs, name=name)
        if act:
            self.outputs = act(self.outputs)
        self.all_layers = list(layer[0].all_layers)
        self.all_params = list(layer[0].all_params)
        self.all_drop = dict(layer[0].all_drop)

        for i in range(1, len(layer)):
            self.all_layers.extend(list(layer[i].all_layers))
            self.all_params.extend(list(layer[i].all_params))
            self.all_drop.update(dict(layer[i].all_drop))

        self.all_layers = list_remove_repeat(self.all_layers)
        self.all_params = list_remove_repeat(self.all_params)
예제 #3
0
    def __init__(
        self,
        layer=[],
        combine_fn=tf.minimum,  # 默认是取对应元素最小值
        name='elementwise_layer',
        act=None,
    ):
        Layer.__init__(self, name=name)  # [shortcut, residual]

        if act:
            print("  [TL] ElementwiseLayer %s: size:%s fn:%s, act:%s" %
                  (self.name, layer[0].outputs.get_shape(),
                   combine_fn.__name__, act.__name__))
        else:
            print(
                "  [TL] ElementwiseLayer %s: size:%s fn:%s" %
                (self.name, layer[0].outputs.get_shape(), combine_fn.__name__)
            )  # ElementwiseLayer resnet_v1_50/block1/unit_1/bottleneck_v1/combine_layer: size:(?, 56, 56, 256) fn:add

        self.outputs = layer[0].outputs  # shortcut (?, 56, 56, 256)
        # print(self.outputs._shape, type(self.outputs._shape))
        for l in layer[1:]:  # residual (?, 56, 56, 256)
            # assert str(self.outputs.get_shape()) == str(l.outputs.get_shape()), "Hint: the input shapes should be the same. %s != %s" %  (self.outputs.get_shape() , str(l.outputs.get_shape()))
            self.outputs = combine_fn(
                self.outputs, l.outputs, name=name
            )  # shortcut (?, 56, 56, 256) + residual (?, 56, 56, 256)
        if act:
            self.outputs = act(self.outputs)
        self.all_layers = list(layer[0].all_layers)
        self.all_params = list(layer[0].all_params)
        self.all_drop = dict(layer[0].all_drop)

        for i in range(1, len(layer)):
            self.all_layers.extend(list(layer[i].all_layers))
            self.all_params.extend(list(layer[i].all_params))
            self.all_drop.update(dict(layer[i].all_drop))

        self.all_layers = list_remove_repeat(
            self.all_layers
        )  # 剔除掉重复的layers,resnet_v1_50/conv1,resnet_v1_50/bn0,resnet_v1_50/prelu0
        self.all_params = list_remove_repeat(self.all_params)
예제 #4
0
    def __init__(
        self,
        layer=None,
        shape=None,
        name='resize_bilinear_layer',
    ):
        Layer.__init__(self, name=name)

        self.inputs = layer.outputs
        if shape == None:
            shape = tf.shape(self.inputs)[1:3, ]

        self.outputs = tf.image.resize_bilinear(self.inputs, shape)
        print("  [TL] ResizeBilinearLayer  %s: %s" %
              (self.name, self.outputs.get_shape()))

        self.all_layers = list(layer.all_layers)
        self.all_params = list(layer.all_params)
        self.all_drop = dict(layer.all_drop)

        self.all_layers = list_remove_repeat(self.all_layers)
        self.all_params = list_remove_repeat(self.all_params)