当前位置: 首页>>代码示例>>Python>>正文


Python layers.Add方法代码示例

本文整理汇总了Python中tensorflow.keras.layers.Add方法的典型用法代码示例。如果您正苦于以下问题:Python layers.Add方法的具体用法?Python layers.Add怎么用?Python layers.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.keras.layers的用法示例。


在下文中一共展示了layers.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_model

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Add [as 别名]
def build_model(self,
                    input_dim,
                    hidden_units,
                    output_dim):
        """Build a simple MINE model
        
        Arguments:
            See class arguments.
        """
        inputs1 = Input(shape=(input_dim), name="x")
        inputs2 = Input(shape=(input_dim), name="y")
        x1 = Dense(hidden_units)(inputs1)
        x2 = Dense(hidden_units)(inputs2)
        x = Add()([x1, x2])
        x = Activation('relu', name="ReLU")(x)
        outputs = Dense(output_dim, name="MI")(x)
        inputs = [inputs1, inputs2]
        self._model = Model(inputs,
                            outputs,
                            name='MINE')
        self._model.summary() 
开发者ID:PacktPublishing,项目名称:Advanced-Deep-Learning-with-Keras,代码行数:23,代码来源:mine-13.8.1.py

示例2: __init__

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Add [as 别名]
def __init__(self,
                 filters,
                 kernel_size,
                 norm_type="instance",
                 pad_type="constant",
                 **kwargs):
        super(ResBlock, self).__init__(name="ResBlock")
        padding = (kernel_size - 1) // 2
        padding = (padding, padding)
        self.model = tf.keras.models.Sequential()
        self.model.add(get_padding(pad_type, padding))
        self.model.add(Conv2D(filters, kernel_size))
        self.model.add(get_norm(norm_type))
        self.model.add(ReLU())
        self.model.add(get_padding(pad_type, padding))
        self.model.add(Conv2D(filters, kernel_size))
        self.model.add(get_norm(norm_type))
        self.add = Add() 
开发者ID:mnicnc404,项目名称:CartoonGan-tensorflow,代码行数:20,代码来源:layers.py

示例3: __init__

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Add [as 别名]
def __init__(self, filters, bottleneck_factor=2):
        self.filters = filters
        self.bottleneck_factor = bottleneck_factor

        conv = partial(Conv2D, activation="relu", padding="same", use_bias=False)

        self.identity_bn = BatchNormalization()
        self.identity_1x1 = conv(filters, kernel_size=(1, 1))

        self.bottleneck_1x1_bn = BatchNormalization()
        self.bottleneck_1x1 = conv(filters // bottleneck_factor, kernel_size=(1, 1))

        self.bottleneck_3x3_bn = BatchNormalization()
        self.bottleneck_3x3 = conv(filters // bottleneck_factor, kernel_size=(3, 3))

        self.expansion_1x1_bn = BatchNormalization()
        self.expansion_1x1 = conv(filters, kernel_size=(1, 1))

        self.residual_add_bn = BatchNormalization()
        self.residual_add = Add() 
开发者ID:jgraving,项目名称:DeepPoseKit,代码行数:22,代码来源:hourglass.py

示例4: build

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Add [as 别名]
def build(self, hp, inputs=None):
        inputs = nest.flatten(inputs)
        if len(inputs) == 1:
            return inputs

        merge_type = self.merge_type or hp.Choice('merge_type',
                                                  ['add', 'concatenate'],
                                                  default='add')

        if not all([shape_compatible(input_node.shape, inputs[0].shape) for
                    input_node in inputs]):
            new_inputs = []
            for input_node in inputs:
                new_inputs.append(Flatten().build(hp, input_node))
            inputs = new_inputs

        # TODO: Even inputs have different shape[-1], they can still be Add(
        #  ) after another layer. Check if the inputs are all of the same
        #  shape
        if all([input_node.shape == inputs[0].shape for input_node in inputs]):
            if merge_type == 'add':
                return layers.Add(inputs)

        return layers.Concatenate()(inputs) 
开发者ID:keras-team,项目名称:autokeras,代码行数:26,代码来源:reduction.py

示例5: pool

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Add [as 别名]
def pool(inputs, outchannels, pool1, pool2,):
    x1 = convblock(inputs, outchannels, 3)
    x2 = convblock(inputs, outchannels, 3)
    x2 = pool2(x2)
    x = layers.Add()([x1, x2])
    x = layers.Conv2D(outchannels, 3, padding='same')(x)
    x = pool1(x)

    y1 = convblock(inputs, outchannels, 3)
    y2 = convblock(inputs, outchannels, 3)
    y2 = pool1(y2)
    y = layers.Add()([y1, y2])
    y = layers.Conv2D(outchannels, 3, padding='same')(y)
    y = pool2(y)
    feat = layers.Add()([x, y])
    feat = layers.Conv2D(outchannels, 3, padding='same')(feat)
    feat = layers.BatchNormalization()(feat)
    skip_x = layers.Conv2D(outchannels, 1, padding='same')(inputs)
    skip_x = layers.BatchNormalization()(skip_x)
    out = layers.Add()([skip_x, feat])
    out = layers.ReLU(max_value=6)(out)
    out = convblock(out, outchannels, 3)
    return out 
开发者ID:1044197988,项目名称:Centernet-Tensorflow2.0,代码行数:25,代码来源:module.py

示例6: residual

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Add [as 别名]
def residual(_x, out_dim, name, stride=1):
  shortcut = _x
  num_channels = K.int_shape(shortcut)[-1]
  _x = ZeroPadding2D(padding=1, name=name + '.pad1')(_x)
  _x = Conv2D(out_dim, 3, strides=stride, use_bias=False, name=name + '.conv1')(_x)
  _x = BatchNormalization(epsilon=1e-5, name=name + '.bn1')(_x)
  _x = Activation('relu', name=name + '.relu1')(_x)

  _x = Conv2D(out_dim, 3, padding='same', use_bias=False, name=name + '.conv2')(_x)
  _x = BatchNormalization(epsilon=1e-5, name=name + '.bn2')(_x)

  if num_channels != out_dim or stride != 1:
    shortcut = Conv2D(out_dim, 1, strides=stride, use_bias=False, name=name + '.shortcut.0')(
        shortcut)
    shortcut = BatchNormalization(epsilon=1e-5, name=name + '.shortcut.1')(shortcut)

  _x = Add(name=name + '.add')([_x, shortcut])
  _x = Activation('relu', name=name + '.relu')(_x)
  return _x 
开发者ID:1044197988,项目名称:Centernet-Tensorflow2.0,代码行数:21,代码来源:hourglass.py

示例7: resblock_body

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Add [as 别名]
def resblock_body(x, num_filters, num_blocks, all_narrow=True):
    '''A series of resblocks starting with a downsampling Convolution2D'''
    # Darknet uses left and top padding instead of 'same' mode
    x = ZeroPadding2D(((1,0),(1,0)))(x)
    x = DarknetConv2D_BN_Mish(num_filters, (3,3), strides=(2,2))(x)

    res_connection = DarknetConv2D_BN_Mish(num_filters//2 if all_narrow else num_filters, (1,1))(x)
    x = DarknetConv2D_BN_Mish(num_filters//2 if all_narrow else num_filters, (1,1))(x)

    for i in range(num_blocks):
        y = compose(
                DarknetConv2D_BN_Mish(num_filters//2, (1,1)),
                DarknetConv2D_BN_Mish(num_filters//2 if all_narrow else num_filters, (3,3)))(x)
        x = Add()([x,y])

    x = DarknetConv2D_BN_Mish(num_filters//2 if all_narrow else num_filters, (1,1))(x)
    x = Concatenate()([x , res_connection])

    return DarknetConv2D_BN_Mish(num_filters, (1,1))(x) 
开发者ID:david8862,项目名称:keras-YOLOv3-model-set,代码行数:21,代码来源:yolo4_darknet.py

示例8: residual_block_id

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Add [as 别名]
def residual_block_id(self,tensor, feature_n,name=None):
        if name != None:
            depconv_1  = DepthwiseConv2D(3,2,padding='same',name=name+"/dconv")(tensor)
            conv_2     = Conv2D(feature_n,1,name=name+"/conv")(depconv_1)
        else:
            depconv_1  = DepthwiseConv2D(3,2,padding='same')(tensor)
            conv_2     = Conv2D(feature_n,1)(depconv_1)


        maxpool_1  = MaxPool2D(pool_size=(2,2),strides=(2,2),padding='same')(tensor)
        conv_zeros = Conv2D(feature_n/2,2,strides=2,use_bias=False,kernel_initializer=tf.zeros_initializer())(tensor)

        padding_1  = Concatenate(axis=-1)([maxpool_1,conv_zeros])#self.feature_padding(maxpool_1)

        add = Add()([padding_1,conv_2])
        relu = ReLU()(add)

        return relu
    
    #def feature_padding(self,tensor,channels_n=0):
    #    #pad = tf.keras.layers.ZeroPadding2D(((0,0),(0,0),(0,tensor.shape[3])))(tensor)
    #    return Concatenate(axis=3)([tensor,pad]) 
开发者ID:SBoulanger,项目名称:blazepalm,代码行数:24,代码来源:palm_detector.py

示例9: Bottleneck

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Add [as 别名]
def Bottleneck(x, size, downsampe=False):
    residual = x

    out = conv(x, size, 1, padding_='valid')
    out = BatchNormalization(epsilon=1e-5, momentum=0.1)(out)
    out = Activation('relu')(out)

    out = conv(out, size, 3)
    out = BatchNormalization(epsilon=1e-5, momentum=0.1)(out)
    out = Activation('relu')(out)

    out = conv(out, size * 4, 1, padding_='valid')
    out = BatchNormalization(epsilon=1e-5, momentum=0.1)(out)

    if downsampe:
        residual = conv(x, size * 4, 1, padding_='valid')
        residual = BatchNormalization(epsilon=1e-5, momentum=0.1)(residual)

    out = Add()([out, residual])
    out = Activation('relu')(out)

    return out 
开发者ID:1044197988,项目名称:TF.Keras-Commonly-used-models,代码行数:24,代码来源:HRNet.py

示例10: ResidualConvUnit

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Add [as 别名]
def ResidualConvUnit(inputs,n_filters=256,kernel_size=3,name=''):
    """
    A local residual unit designed to fine-tune the pretrained ResNet weights
    Arguments:
      inputs: The input tensor
      n_filters: Number of output feature maps for each conv
      kernel_size: Size of convolution kernel
    Returns:
      Output of local residual block
    """
    
    net = ReLU(name=name+'relu1')(inputs)
    net = Conv2D(n_filters, kernel_size, padding='same', name=name+'conv1', kernel_initializer=kern_init, kernel_regularizer=kern_reg)(net)
    net = ReLU(name=name+'relu2')(net)
    net = Conv2D(n_filters, kernel_size, padding='same', name=name+'conv2', kernel_initializer=kern_init, kernel_regularizer=kern_reg)(net)
    net = Add(name=name+'sum')([net, inputs])
    
    return net 
开发者ID:1044197988,项目名称:TF.Keras-Commonly-used-models,代码行数:20,代码来源:Refinenet.py

示例11: get_multi_inputs_model

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Add [as 别名]
def get_multi_inputs_model():
    a = Input(shape=(10,))
    b = Input(shape=(10,))
    c = Add()([a, b])
    c = Dense(1, activation='sigmoid', name='last_layer')(c)
    m_multi = Model(inputs=[a, b], outputs=c)
    return m_multi 
开发者ID:philipperemy,项目名称:keract,代码行数:9,代码来源:multi_inputs.py

示例12: center_pool

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Add [as 别名]
def center_pool(inputs, outchannels):
    x = convblock(inputs, outchannels, 3)
    poolw = right_pool(left_pool(x))
    y = convblock(inputs, outchannels, 3)
    poolh = bottom_pool(top_pool(y))
    pool = layers.Add()([poolw, poolh])
    features = layers.Conv2D(outchannels, 3, padding='same')(pool)
    features = layers.BatchNormalization()(features)
    skip_x = layers.Conv2D(outchannels, 1, padding='same')(inputs)
    skip_x = layers.BatchNormalization()(skip_x)
    out = layers.Add()([skip_x, features])
    out = layers.ReLU(max_value=6)(out)
    out = convblock(out, outchannels, 3)
    return out 
开发者ID:1044197988,项目名称:Centernet-Tensorflow2.0,代码行数:16,代码来源:module.py

示例13: res_layer1

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Add [as 别名]
def res_layer1(inputs, outchannels):
    x = convblock(inputs, int(outchannels/2), 1)
    x = convblock(x, int(outchannels / 2), 3)
    out = convblock(x, outchannels, 1)
    skip_x = convblock(inputs, outchannels, 1)
    out = layers.Add()([out, skip_x])
    return out 
开发者ID:1044197988,项目名称:Centernet-Tensorflow2.0,代码行数:9,代码来源:module.py

示例14: upsample_module

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Add [as 别名]
def upsample_module(inputs, out1, out2):
    left, right = inputs

    xl = res_layer0(left,out2)
    xl = res_layer0(xl, out2)

    xr = convblock(right, out1, 3)
    xr = convblock(xr, out2, 3)
    xr = layers.UpSampling2D()(xr)
    out = layers.Add()([xl, xr])
    return out 
开发者ID:1044197988,项目名称:Centernet-Tensorflow2.0,代码行数:13,代码来源:module.py

示例15: resblock_body

# 需要导入模块: from tensorflow.keras import layers [as 别名]
# 或者: from tensorflow.keras.layers import Add [as 别名]
def resblock_body(x, num_filters, num_blocks):
    '''A series of resblocks starting with a downsampling Convolution2D'''
    # Darknet uses left and top padding instead of 'same' mode
    x = ZeroPadding2D(((1,0),(1,0)))(x)
    x = DarknetConv2D_BN_Leaky(num_filters, (3,3), strides=(2,2))(x)
    for i in range(num_blocks):
        y = compose(
                DarknetConv2D_BN_Leaky(num_filters//2, (1,1)),
                DarknetConv2D_BN_Leaky(num_filters, (3,3)))(x)
        x = Add()([x,y])
    return x 
开发者ID:david8862,项目名称:keras-YOLOv3-model-set,代码行数:13,代码来源:yolo3_darknet.py


注:本文中的tensorflow.keras.layers.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。