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


Python functions.average方法代码示例

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


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

示例1: __init__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import average [as 别名]
def __init__(self, vocab, vocab_ngram_tokens, n_units, n_units_char, dropout,
                 subword):  # dropout ratio, zero indicates no dropout
        super(SUMAVG, self).__init__()
        with self.init_scope():
            if subword.startswith('sum'):
                self.f_sumavg = F.sum
            if subword.startswith('avg'):
                self.f_sumavg = F.average

            self.embed = L.EmbedID(
                len(vocab_ngram_tokens.lst_words) + 2, n_units_char,
                initialW=I.Uniform(1. / n_units_char))  # ngram tokens embedding  plus 2 for OOV and end symbol.

            self.n_ngram = vocab_ngram_tokens.metadata["max_gram"] - vocab_ngram_tokens.metadata["min_gram"] + 1
            self.dropout = dropout
            self.vocab = vocab
            self.vocab_ngram_tokens = vocab_ngram_tokens 
开发者ID:vecto-ai,项目名称:vecto,代码行数:19,代码来源:subword.py

示例2: forward_expected

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import average [as 别名]
def forward_expected(self, inputs):
        x, w = inputs
        if not self.use_weights:
            w = None
        y_expect = numpy.average(x, axis=self.axis, weights=w)
        if self.keepdims:
            # numpy.average does not support keepdims
            axis = self.axis
            if axis is None:
                axis = list(six.moves.range(x.ndim))
            elif isinstance(axis, int):
                axis = axis,
            shape = list(x.shape)
            for i in six.moves.range(len(shape)):
                if i in axis or i - len(shape) in axis:
                    shape[i] = 1
            y_expect = y_expect.reshape(shape)
        y_expect = utils.force_array(y_expect, dtype=self.dtype)
        return y_expect, 
开发者ID:chainer,项目名称:chainer,代码行数:21,代码来源:test_average.py

示例3: scale_layer

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import average [as 别名]
def scale_layer(self, feature_map, node):
        input_data = node.inputs[0].data
        _, _, in_height, in_width = input_data.shape
        _, _, feature_height, feature_width = feature_map.shape
        kernel_height = in_height + 2 * node.ph - node.sy * (feature_height - 1)
        kernel_width = in_width + 2 * node.pw - node.sx * (feature_width - 1)
        scaled_feature = F.deconvolution_2d(
            feature_map,
            self.xp.ones((1, 1, kernel_height, kernel_width)),
            stride=(node.sy, node.sx),
            pad=(node.ph, node.pw),
            outsize=(in_height, in_width),
        )
        averaged_feature_map = F.average(input_data, axis=1, keepdims=True)
        feature_map = scaled_feature * averaged_feature_map
        return feature_map 
开发者ID:Bartzi,项目名称:see,代码行数:18,代码来源:visual_backprop.py

示例4: log_prob

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import average [as 别名]
def log_prob(self, z, logdet):
        logdet[0] = logdet[0] - self.x_size
        logdet[1] = logdet[1] - self.adj_size
        ln_var_adj = self.ln_var * self.xp.ones([self.adj_size])
        ln_var_x = self.ln_var * self.xp.ones([self.x_size])
        nll_adj = F.average(F.sum(F.gaussian_nll(z[1], self.xp.zeros([self.adj_size], dtype=self.xp.float32),
                                                 ln_var_adj, reduce='no'), axis=1) - logdet[1])
        nll_adj /= self.adj_size

        nll_x = F.average(F.sum(F.gaussian_nll(z[0], self.xp.zeros([self.x_size], dtype=self.xp.float32),
                                               ln_var_x, reduce='no'), axis=1) - logdet[0])
        nll_x /= self.x_size
        if nll_x.array < 0:
            print('nll_x:{}'.format(nll_x))

        return [nll_x, nll_adj] 
开发者ID:pfnet-research,项目名称:graph-nvp,代码行数:18,代码来源:model.py

示例5: __call__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import average [as 别名]
def __call__(self, x):
        h = F.leaky_relu(self.conv1(x), self.slope)
        h = F.leaky_relu(self.conv2(h), self.slope)

        if hasattr(self, 'conv_bridge'):
            x = self.conv_bridge(x[:, :, 2:-2, 2:-2])
        else:
            x = x[:, :, 2:-2, 2:-2]

        if hasattr(self, 'fc1') and hasattr(self, 'fc2'):
            se = F.relu(self.fc1(F.average(h, axis=(2, 3))))
            se = F.sigmoid(self.fc2(se))[:, :, None, None]
            se = F.broadcast_to(se, h.shape)
            h = h * se

        return h + x 
开发者ID:tsurumeso,项目名称:waifu2x-chainer,代码行数:18,代码来源:srcnn.py

示例6: forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import average [as 别名]
def forward(self, u):
        B, C, H, W = u.shape

        z = F.average(u, axis=(2, 3))
        x = F.relu(self.down(z))
        x = F.sigmoid(self.up(x))
        x = F.reshape(x, x.shape[:2] + (1, 1))
        # Spatial axes of `x` will be broadcasted.
        return u * x 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:11,代码来源:seblock.py

示例7: forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import average [as 别名]
def forward(self, inputs, device):
        x, w = inputs
        if not self.use_weights:
            w = None
        if self.use_variable_method:
            y = x.mean(axis=self.axis, weights=w, keepdims=self.keepdims)
        else:
            y = functions.average(
                x, axis=self.axis, weights=w, keepdims=self.keepdims)
        return y, 
开发者ID:chainer,项目名称:chainer,代码行数:12,代码来源:test_average.py

示例8: test_duplicate_value

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import average [as 别名]
def test_duplicate_value(self):
        x = numpy.random.uniform(-1, 1, 24).reshape(2, 3, 4).astype(self.dtype)
        with self.assertRaises(ValueError):
            functions.average(x, axis=(0, 0)) 
开发者ID:chainer,项目名称:chainer,代码行数:6,代码来源:test_average.py

示例9: test_duplicate_value_negative

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import average [as 别名]
def test_duplicate_value_negative(self):
        x = numpy.random.uniform(-1, 1, 24).reshape(2, 3, 4).astype(self.dtype)
        with self.assertRaises(ValueError):
            functions.average(x, axis=(1, -2)) 
开发者ID:chainer,项目名称:chainer,代码行数:6,代码来源:test_average.py

示例10: calc_direction_loss

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import average [as 别名]
def calc_direction_loss(self, grids):
        top_left_x, top_right_x, _, top_left_y, _, bottom_left_y = self.get_corners(grids)

        # penalize upside down images
        distance = top_left_y - bottom_left_y
        loss_values = F.maximum(distance, self.xp.zeros_like(distance))
        up_down_loss = F.average(loss_values)

        # penalize images that are vertically mirrored
        distance = top_left_x - top_right_x
        loss_values = F.maximum(distance, self.xp.zeros_like(distance))
        left_right_loss = F.average(loss_values)

        return up_down_loss + left_right_loss 
开发者ID:Bartzi,项目名称:see,代码行数:16,代码来源:loss_metrics.py

示例11: calc_height_loss

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import average [as 别名]
def calc_height_loss(self, height):
        # penalize bboxes that are not high enough to contain text (10 pixels)
        shifted_height = height - 10
        thresholded_height = F.minimum(shifted_height, self.xp.zeros_like(shifted_height))
        thresholded_height *= -1

        return F.average(thresholded_height) 
开发者ID:Bartzi,项目名称:see,代码行数:9,代码来源:loss_metrics.py

示例12: perform_visual_backprop

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import average [as 别名]
def perform_visual_backprop(self, variable):
        with chainer.no_backprop_mode(), chainer.cuda.get_device_from_array(variable.data):
            self.xp = cuda.get_array_module(variable)
            averaged_feature = F.average(variable, axis=1, keepdims=True)

            visualization = self.traverse_computational_graph(variable.creator, averaged_feature)
            visualization = visualization.data
            for i in range(len(visualization)):
                min_val = visualization[i].min()
                max_val = visualization[i].max()
                visualization[i] -= min_val
                visualization[i] *= 1.0 / (max_val - min_val)
        return visualization 
开发者ID:Bartzi,项目名称:see,代码行数:15,代码来源:visual_backprop.py

示例13: _pool

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import average [as 别名]
def _pool(
            self, h_cls_seg, h_ag_loc, rois, roi_indices, gt_roi_labels):
        # PSROI Pooling
        # shape: (n_roi, n_class, 2, roi_size, roi_size)
        roi_cls_ag_seg_scores = ps_roi_average_pooling_2d(
            h_cls_seg, rois, roi_indices,
            (self.n_class * 2, self.roi_size, self.roi_size),
            self.spatial_scale, self.group_size)
        roi_cls_ag_seg_scores = F.reshape(
            roi_cls_ag_seg_scores,
            (-1, self.n_class, 2, self.roi_size, self.roi_size))

        # shape: (n_roi, 2*4, roi_size, roi_size)
        roi_ag_loc_scores = ps_roi_average_pooling_2d(
            h_ag_loc, rois, roi_indices,
            (2 * 4, self.roi_size, self.roi_size),
            self.spatial_scale, self.group_size)

        # shape: (n_roi, n_class)
        roi_cls_scores = F.average(
            F.max(roi_cls_ag_seg_scores, axis=2), axis=(2, 3))

        # Bbox Regression
        # shape: (n_roi, 2, 4)
        roi_ag_locs = F.average(roi_ag_loc_scores, axis=(2, 3))
        roi_ag_locs = F.reshape(roi_ag_locs, (-1, 2, 4))

        # Mask Regression
        # shape: (n_roi, n_class, 2, roi_size, roi_size)
        if gt_roi_labels is None:
            max_cls_indices = roi_cls_scores.array.argmax(axis=1)
        else:
            max_cls_indices = gt_roi_labels

        # shape: (n_roi, 2, roi_size, roi_size)
        roi_ag_seg_scores = roi_cls_ag_seg_scores[
            self.xp.arange(len(max_cls_indices)), max_cls_indices]

        return roi_ag_seg_scores, roi_ag_locs, roi_cls_scores 
开发者ID:chainer,项目名称:chainercv,代码行数:41,代码来源:fcis_resnet101.py

示例14: __init__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import average [as 别名]
def __init__(self, n_layer,
                 n_class=None,
                 pretrained_model=None,
                 mean=None, initialW=None, fc_kwargs={}):
        blocks = self._blocks[n_layer]

        param, path = utils.prepare_pretrained_model(
            {'n_class': n_class, 'mean': mean},
            pretrained_model, self._models[n_layer],
            {'n_class': 1000, 'mean': _imagenet_mean})
        self.mean = param['mean']

        if initialW is None:
            initialW = initializers.HeNormal(scale=1., fan_option='fan_out')
        if 'initialW' not in fc_kwargs:
            fc_kwargs['initialW'] = initializers.Normal(scale=0.01)
        if pretrained_model:
            # As a sampling process is time-consuming,
            # we employ a zero initializer for faster computation.
            initialW = initializers.constant.Zero()
            fc_kwargs['initialW'] = initializers.constant.Zero()
        kwargs = {
            'initialW': initialW, 'stride_first': True, 'add_seblock': True}

        super(SEResNet, self).__init__()
        with self.init_scope():
            self.conv1 = Conv2DBNActiv(None, 64, 7, 2, 3, nobias=True,
                                       initialW=initialW)
            self.pool1 = lambda x: F.max_pooling_2d(x, ksize=3, stride=2)
            self.res2 = ResBlock(blocks[0], None, 64, 256, 1, **kwargs)
            self.res3 = ResBlock(blocks[1], None, 128, 512, 2, **kwargs)
            self.res4 = ResBlock(blocks[2], None, 256, 1024, 2, **kwargs)
            self.res5 = ResBlock(blocks[3], None, 512, 2048, 2, **kwargs)
            self.pool5 = lambda x: F.average(x, axis=(2, 3))
            self.fc6 = L.Linear(None, param['n_class'], **fc_kwargs)
            self.prob = F.softmax

        if path:
            chainer.serializers.load_npz(path, self) 
开发者ID:chainer,项目名称:chainercv,代码行数:41,代码来源:se_resnet.py

示例15: __init__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import average [as 别名]
def __init__(self, n_layer,
                 n_class=None,
                 pretrained_model=None,
                 mean=None, initialW=None, fc_kwargs={}):
        blocks = self._blocks[n_layer]

        param, path = utils.prepare_pretrained_model(
            {'n_class': n_class, 'mean': mean},
            pretrained_model, self._models[n_layer],
            {'n_class': 1000, 'mean': _imagenet_mean})
        self.mean = param['mean']

        if initialW is None:
            initialW = initializers.HeNormal(scale=1., fan_option='fan_out')
        if 'initialW' not in fc_kwargs:
            fc_kwargs['initialW'] = initializers.Normal(scale=0.01)
        if pretrained_model:
            # As a sampling process is time-consuming,
            # we employ a zero initializer for faster computation.
            initialW = initializers.constant.Zero()
            fc_kwargs['initialW'] = initializers.constant.Zero()
        kwargs = {
            'groups': 32, 'initialW': initialW, 'stride_first': False,
            'add_seblock': True}

        super(SEResNeXt, self).__init__()
        with self.init_scope():
            self.conv1 = Conv2DBNActiv(None, 64, 7, 2, 3, nobias=True,
                                       initialW=initialW)
            self.pool1 = lambda x: F.max_pooling_2d(x, ksize=3, stride=2)
            self.res2 = ResBlock(blocks[0], None, 128, 256, 1, **kwargs)
            self.res3 = ResBlock(blocks[1], None, 256, 512, 2, **kwargs)
            self.res4 = ResBlock(blocks[2], None, 512, 1024, 2, **kwargs)
            self.res5 = ResBlock(blocks[3], None, 1024, 2048, 2, **kwargs)
            self.pool5 = lambda x: F.average(x, axis=(2, 3))
            self.fc6 = L.Linear(None, param['n_class'], **fc_kwargs)
            self.prob = F.softmax

        if path:
            chainer.serializers.load_npz(path, self) 
开发者ID:chainer,项目名称:chainercv,代码行数:42,代码来源:se_resnext.py


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