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


Python backend.pool2d方法代码示例

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


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

示例1: call

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import pool2d [as 别名]
def call(self, x, mask=None):
        if K.image_dim_ordering == "th":
            _, f, r, c = self.shape
        else:
            _, r, c, f = self.shape
        squared = K.square(x)
        pooled = K.pool2d(squared, (self.n, self.n), strides=(1, 1),
            padding="same", pool_mode="avg")
        if K.image_dim_ordering == "th":
            summed = K.sum(pooled, axis=1, keepdims=True)
            averaged = self.alpha * K.repeat_elements(summed, f, axis=1)
        else:
            summed = K.sum(pooled, axis=3, keepdims=True)
            averaged = self.alpha * K.repeat_elements(summed, f, axis=3)
        denom = K.pow(self.k + averaged, self.beta)
        return x / denom 
开发者ID:dalmia,项目名称:WannaPark,代码行数:18,代码来源:custom.py

示例2: pool1d

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import pool2d [as 别名]
def pool1d(
    x,
    pool_size,
    strides=1,
    padding='valid',
    data_format=None,
    pool_mode='max'
):
    """向量序列的pool函数
    """
    x = K.expand_dims(x, 1)
    x = K.pool2d(
        x,
        pool_size=(1, pool_size),
        strides=(1, strides),
        padding=padding,
        data_format=data_format,
        pool_mode=pool_mode
    )
    return x[:, 0] 
开发者ID:bojone,项目名称:bert4keras,代码行数:22,代码来源:backend.py

示例3: call

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import pool2d [as 别名]
def call(self, x, mask=None):
        """Layer functionality."""

        maxpool_type = self.config.get('conversion', 'maxpool_type')
        if 'binary' in self.activation_str:
            return k.pool2d(x, self.pool_size, self.strides, self.padding,
                            pool_mode='max')
        elif maxpool_type == 'avg_max':
            update_rule = self.spikerate_pre + (x - self.spikerate_pre) * \
                          self.dt / self.time
        elif maxpool_type == 'exp_max':
            # update_rule = self.spikerate_pre + x / 2. ** (1 / t_inv)
            update_rule = self.spikerate_pre * 1.005 + x * 0.995
        elif maxpool_type == 'fir_max':
            update_rule = self.spikerate_pre + x * self.dt / self.time
        else:
            print("Wrong max pooling type, falling back on average pooling.")
            return k.pool2d(x, self.pool_size, self.strides, self.padding,
                            pool_mode='avg')
        self.add_update([(self.spikerate_pre, update_rule),
                         (self.previous_x, x)])
        return self._pooling_function([self.spikerate_pre, self.previous_x],
                                      self.pool_size, self.strides,
                                      self.padding, self.data_format) 
开发者ID:NeuromorphicProcessorProject,项目名称:snn_toolbox,代码行数:26,代码来源:temporal_mean_rate_theano.py

示例4: weighted_dice_loss

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import pool2d [as 别名]
def weighted_dice_loss(y_true, y_pred):
    y_true = K.cast(y_true, 'float32')
    y_pred = K.cast(y_pred, 'float32')
    # if we want to get same size of output, kernel size must be odd number
    if K.int_shape(y_pred)[1] == 128:
        kernel_size = 11
    elif K.int_shape(y_pred)[1] == 256:
        kernel_size = 21
    elif K.int_shape(y_pred)[1] == 512:
        kernel_size = 21
    elif K.int_shape(y_pred)[1] == 1024:
        kernel_size = 41
    else:
        raise ValueError('Unexpected image size')
    averaged_mask = K.pool2d(
        y_true, pool_size=(kernel_size, kernel_size), strides=(1, 1), padding='same', pool_mode='avg')
    border = K.cast(K.greater(averaged_mask, 0.005), 'float32') * K.cast(K.less(averaged_mask, 0.995), 'float32')
    weight = K.ones_like(averaged_mask)
    w0 = K.sum(weight)
    weight += border * 2
    w1 = K.sum(weight)
    weight *= (w0 / w1)
    loss = 1 - weighted_dice_coeff(y_true, y_pred, weight)
    return loss 
开发者ID:petrosgk,项目名称:Kaggle-Carvana-Image-Masking-Challenge,代码行数:26,代码来源:losses.py

示例5: weighted_bce_dice_loss

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import pool2d [as 别名]
def weighted_bce_dice_loss(y_true, y_pred):
    y_true = K.cast(y_true, 'float32')
    y_pred = K.cast(y_pred, 'float32')
    # if we want to get same size of output, kernel size must be odd number
    if K.int_shape(y_pred)[1] == 128:
        kernel_size = 11
    elif K.int_shape(y_pred)[1] == 256:
        kernel_size = 21
    elif K.int_shape(y_pred)[1] == 512:
        kernel_size = 21
    elif K.int_shape(y_pred)[1] == 1024:
        kernel_size = 41
    else:
        raise ValueError('Unexpected image size')
    averaged_mask = K.pool2d(
        y_true, pool_size=(kernel_size, kernel_size), strides=(1, 1), padding='same', pool_mode='avg')
    border = K.cast(K.greater(averaged_mask, 0.005), 'float32') * K.cast(K.less(averaged_mask, 0.995), 'float32')
    weight = K.ones_like(averaged_mask)
    w0 = K.sum(weight)
    weight += border * 2
    w1 = K.sum(weight)
    weight *= (w0 / w1)
    loss = weighted_bce_loss(y_true, y_pred, weight) + (1 - weighted_dice_coeff(y_true, y_pred, weight))
    return loss 
开发者ID:petrosgk,项目名称:Kaggle-Carvana-Image-Masking-Challenge,代码行数:26,代码来源:losses.py

示例6: call

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import pool2d [as 别名]
def call(self, v, **kwargs):
        assert (len(self.input_dims) == len(self.output_dims) and
                self.input_dims[0] == self.output_dims[0])

        # possibly shrink spatial axis by pooling elements
        if len(self.input_dims) == 4 and (self.input_dims[1] > self.output_dims[1] or self.input_dims[2] > self.output_dims[2]):
            assert (self.input_dims[1] % self.output_dims[1] == 0 and
                    self.input_dims[2] % self.output_dims[2] == 0)

            pool_sizes = (self.input_dims[1] / self.output_dims[1],
                          self.input_dims[2] / self.output_dims[2])
            strides = pool_sizes
            v = K.pool2d(
                v, pool_size=pool_sizes, strides=strides,
                padding='same', data_format='channels_last', pool_mode='avg')

        # possibly extend spatial axis by repeating elements
        for i in range(1, len(self.input_dims) - 1):
            if self.input_dims[i] < self.output_dims[i]:
                assert self.output_dims[i] % self.input_dims[i] == 0
                v = K.repeat_elements(
                    v, rep=int(self.output_dims[i] / self.input_dims[i]),
                    axis=i)

        return v 
开发者ID:PacktPublishing,项目名称:Hands-On-Generative-Adversarial-Networks-with-Keras,代码行数:27,代码来源:layers.py

示例7: get_border_mask

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import pool2d [as 别名]
def get_border_mask(pool_size, y_true):
    negative = 1 - y_true
    positive = y_true
    positive = K.pool2d(positive, pool_size=pool_size, padding="same")
    negative = K.pool2d(negative, pool_size=pool_size, padding="same")
    border = positive * negative
    return border 
开发者ID:killthekitten,项目名称:kaggle-carvana-2017,代码行数:9,代码来源:losses.py

示例8: _nms

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import pool2d [as 别名]
def _nms(heat, kernel=3):
  hmax = K.pool2d(heat, (kernel, kernel), padding='same', pool_mode='max')
  keep = K.cast(K.equal(hmax, heat), K.floatx())
  return heat * keep 
开发者ID:see--,项目名称:keras-centernet,代码行数:6,代码来源:decode.py

示例9: min_max_pool2d

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import pool2d [as 别名]
def min_max_pool2d(x):
    max_x =  K.pool2d(x, pool_size=(2, 2), strides=(2, 2))
    min_x = min_pool2d(x)
    return K.concatenate([max_x, min_x], axis=3) # concatenate on channel 
开发者ID:TUMFTM,项目名称:CameraRadarFusionNet,代码行数:6,代码来源:vggmax.py

示例10: call

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import pool2d [as 别名]
def call(self, v, **kwargs):
        assert len(self.si) == len(self.so) and self.si[0] == self.so[0]

        # Decrease feature maps.  Attention: channels last
        if self.si[-1] > self.so[-1]:
            v = v[...,:self.so[-1]]

        # Increase feature maps.  Attention:channels last
        if self.si[-1] < self.so[-1]:
            z = K.zeros((self.so[:-1] + (self.so[-1] - self.si[-1])),dtype=v.dtype)
            v = K.concatenate([v,z])
        
        # Shrink spatial axis
        if len(self.si) == 4 and (self.si[1] > self.so[1] or self.si[2] > self.so[2]):
            assert self.si[1] % self.so[1] == 0 and self.si[2] % self.so[2] == 0
            pool_size = (self.si[1] / self.so[1],self.si[2] / self.so[2])
            strides = pool_size
            v = K.pool2d(v,pool_size=pool_size,strides=strides,padding='same',data_format='channels_last',pool_mode='avg')

        #Extend spatial axis
        for i in range(1,len(self.si) - 1):
            if self.si[i] < self.so[i]:
                assert self.so[i] % self.si[i] == 0
                v = K.repeat_elements(v,rep=int(self.so[i] / self.si[i]),axis=i)

        return v 
开发者ID:MSC-BUAA,项目名称:Keras-progressive_growing_of_gans,代码行数:28,代码来源:layers.py

示例11: weighted_bce_dice_loss

# 需要导入模块: from keras import backend [as 别名]
# 或者: from keras.backend import pool2d [as 别名]
def weighted_bce_dice_loss(y_true, y_pred):
    y_true = K.cast(y_true, 'float32')
    y_pred = K.cast(y_pred, 'float32')
    # if we want to get same size of output, kernel size must be odd number
    averaged_mask = K.pool2d(
            y_true, pool_size=(11, 11), strides=(1, 1), padding='same', pool_mode='avg')
    border = K.cast(K.greater(averaged_mask, 0.005), 'float32') * K.cast(K.less(averaged_mask, 0.995), 'float32')
    weight = K.ones_like(averaged_mask)
    w0 = K.sum(weight)
    weight += border * 2
    w1 = K.sum(weight)
    weight *= (w0 / w1)
    loss = weighted_bce_loss(y_true, y_pred, weight) + \
    weighted_dice_loss(y_true, y_pred, weight)
    return loss 
开发者ID:Geoyi,项目名称:pixel-decoder,代码行数:17,代码来源:loss.py


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