• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python functional.avg_pool2d函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中torch.nn.functional.avg_pool2d函数的典型用法代码示例。如果您正苦于以下问题:Python avg_pool2d函数的具体用法?Python avg_pool2d怎么用?Python avg_pool2d使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: forward

    def forward(self, x):
        x1 = self.layers1(x)
        x2 = self.layers2(x1)
        x3 = self.layers3(x2)
        x4 = self.layers4(x3)
        x5a = self.layers5a(x4)
        x5b = self.layers5b(x5a)
        x5c = self.layers5c(x5b)

        x5a_feat = F.avg_pool2d(x5a, x5a.size()[2:]).view(x5a.size(0), x5a.size(1))
        x5b_feat = F.avg_pool2d(x5b, x5b.size()[2:]).view(x5b.size(0), x5b.size(1))
        x5c_feat = F.avg_pool2d(x5c, x5c.size()[2:]).view(x5c.size(0), x5c.size(1))

        midfeat = torch.cat((x5a_feat, x5b_feat), dim=1)
        midfeat = self.fc_fuse(midfeat)

        combofeat = torch.cat((x5c_feat, midfeat), dim=1)
        
        if not self.training:
            return combofeat
        
        prelogits = self.classifier(combofeat)
        
        if self.loss == {'xent'}:
            return prelogits
        elif self.loss == {'xent', 'htri'}:
            return prelogits, combofeat
        else:
            raise KeyError("Unsupported loss: {}".format(self.loss))
开发者ID:zysolanine,项目名称:deep-person-reid,代码行数:29,代码来源:resnet.py


示例2: forward

    def forward(self, x):
        x = self.features(x)

        if hasattr(self, 'pooling_kernel_size') and self.pooling_kernel_size is not None:

            # 2D image output
            if hasattr(self, 'pooling_dropped') and self.pooling_dropped:
                x = x[:, :, self.pooling_dropped:-self.pooling_dropped, self.pooling_dropped:-self.pooling_dropped]
            x = F.avg_pool2d(x, kernel_size=self.pooling_kernel_size, stride=1)
            out = self.classifier(x)
            if self.raster_size is not None:
                out = out.view(out.size(0),
                               self.raster_size, self.raster_size, -1,
                               out.size(2), out.size(3))
                out = out.permute(0, 3, 4, 1, 5, 2).contiguous()
                out = out.view(out.size(0), out.size(1),
                               out.size(2)*out.size(3), out.size(4)*out.size(5))
            return out

        else:

            # Scalar output
            assert not hasattr(self, 'raster_size') or self.raster_size is None
            if not self.training and self.test_time_pool:
                x = F.avg_pool2d(x, kernel_size=7, stride=1)
                out = self.classifier(x)
                # The extra test time pool should be pooling an img_size//32 - 6 size patch
                out = adaptive_avgmax_pool2d(out, pool_type='avgmax')
            else:
                x = adaptive_avgmax_pool2d(x, pool_type='avg')
                out = self.classifier(x)
            return out.view(out.size(0), -1)
开发者ID:wangdingkang,项目名称:RoadDetector,代码行数:32,代码来源:dpn.py


示例3: forward

    def forward(self, x, class_em=True):
        for name, module in self.base._modules.items():
            if name == 'avgpool':
                break
            x = module(x)

        if self.cut_at_pooling:
            x = F.avg_pool2d(x, x.size()[2:])
            # x = x.max(1)[0][0]
            return x

        x = F.avg_pool2d(x, x.size()[2:])
        x = x.view(x.size(0), -1)
        # if self.dropout > 0:
        #     x = self.drop(x)
        if self.num_classes > 0 and not self.has_embedding:
            if class_em:
                x_class = self.classifier(x)
            else:
                x_class = x
        if self.has_embedding:
            x = self.feat(x)
            x = self.feat_bn(x)
            x = self.relu(x)
            if self.dropout > 0:
                x = self.drop(x)
        if self.num_diff_features > 0:
            x = self.diff_feat(x)
        if self.num_diff_features > 0 and self.num_classes > 0:
            return x, x_class
        elif self.num_classes > 0 and self.has_embedding:
            x_class = self.classifier(x)
            return x_class
        else:
            return x
开发者ID:hh23333,项目名称:FVAE_adversarial,代码行数:35,代码来源:resnet.py


示例4: forward

    def forward(self, x):
        x = self.conv1(x)
        x = F.max_pool2d(x, 2) + F.avg_pool2d(x, 2)

        x = self.block1(x)
        x = self.group1(x)
        x = F.max_pool2d(x, 2) + F.avg_pool2d(x, 2)

        x = self.block2(x)
        x = self.group2(x)
        x = F.max_pool2d(x, 2) + F.avg_pool2d(x, 2)

        x = self.block3(x)
        x = self.group3(x)
        x = self.block4(x)
        x = self.group4(x)
        x = F.max_pool2d(x, 2) + F.avg_pool2d(x, 2)

        x = x.view(x.size(0), -1)
        fc = self.fc(x)
        x = F.dropout(fc, training=self.training)
        
        output = list()
        for name, fun in self.fc_dict.iteritems():
            out = fun(x)
            output.append(out)

        return output, fc
开发者ID:m-bain,项目名称:pytorch-multi-label-classifier,代码行数:28,代码来源:lightcnn.py


示例5: forward

 def forward(self, x):
     out = F.relu(self.bn1(self.conv1(x)))
     out = self.layers(out)
     out = F.avg_pool2d(out, 2)
     out = out.view(out.size(0), -1)
     out = self.linear(out)
     return out
开发者ID:howtocodewang,项目名称:DeepCompression-PyTorch,代码行数:7,代码来源:mobilenet.py


示例6: preprocess2

def preprocess2(img):
    # numpy to pytoch, float, scale, cuda, downsample
    img = torch.from_numpy(img).cuda().float() / 255.
    img = F.avg_pool2d(img, kernel_size=2, stride=None, padding=0, ceil_mode=False, count_include_pad=True)
    # print (img.shape) #[3,240,320]
    # fsdaf
    return img 
开发者ID:chriscremer,项目名称:Other_Code,代码行数:7,代码来源:dkf_doom.py


示例7: features

    def features(self, input):
        x_conv0 = self.conv0(input)
        x_stem_0 = self.cell_stem_0(x_conv0)
        x_stem_1 = self.cell_stem_1(x_conv0, x_stem_0)

        x_cell_0 = self.cell_0(x_stem_1, x_stem_0)
        x_cell_1 = self.cell_1(x_cell_0, x_stem_1)
        x_cell_2 = self.cell_2(x_cell_1, x_cell_0)
        x_cell_3 = self.cell_3(x_cell_2, x_cell_1)

        x_reduction_cell_0 = self.reduction_cell_0(x_cell_3, x_cell_2)

        x_cell_6 = self.cell_6(x_reduction_cell_0, x_cell_3)
        x_cell_7 = self.cell_7(x_cell_6, x_reduction_cell_0)
        x_cell_8 = self.cell_8(x_cell_7, x_cell_6)
        x_cell_9 = self.cell_9(x_cell_8, x_cell_7)

        x_reduction_cell_1 = self.reduction_cell_1(x_cell_9, x_cell_8)

        x_cell_12 = self.cell_12(x_reduction_cell_1, x_cell_9)
        x_cell_13 = self.cell_13(x_cell_12, x_reduction_cell_1)
        x_cell_14 = self.cell_14(x_cell_13, x_cell_12)
        x_cell_15 = self.cell_15(x_cell_14, x_cell_13)

        x_cell_15 = self.relu(x_cell_15)
        x_cell_15 = F.avg_pool2d(x_cell_15, x_cell_15.size()[2:])
        x_cell_15 = x_cell_15.view(x_cell_15.size(0), -1)
        x_cell_15 = self.dropout(x_cell_15)

        return x_cell_15
开发者ID:zysolanine,项目名称:deep-person-reid,代码行数:30,代码来源:nasnet.py


示例8: forward

 def forward(self, x):
     if self.transform_input:
         x = x.clone()
         x[:, 0] = x[:, 0] * (0.229 / 0.5) + (0.485 - 0.5) / 0.5
         x[:, 1] = x[:, 1] * (0.224 / 0.5) + (0.456 - 0.5) / 0.5
         x[:, 2] = x[:, 2] * (0.225 / 0.5) + (0.406 - 0.5) / 0.5
     else: warn("Input isn't transformed")
     x = self.Conv2d_1a_3x3(x)
     x = self.Conv2d_2a_3x3(x)
     x = self.Conv2d_2b_3x3(x)
     x = F.max_pool2d(x, kernel_size=3, stride=2)
     x = self.Conv2d_3b_1x1(x)
     x = self.Conv2d_4a_3x3(x)
     x = F.max_pool2d(x, kernel_size=3, stride=2)
     x = self.Mixed_5b(x)
     x = self.Mixed_5c(x)
     x = self.Mixed_5d(x)
     x = self.Mixed_6a(x)
     x = self.Mixed_6b(x)
     x = self.Mixed_6c(x)
     x = self.Mixed_6d(x)
     x = self.Mixed_6e(x)
     x = self.Mixed_7a(x)
     x = self.Mixed_7b(x)
     x_for_attn = x = self.Mixed_7c(x)
     # 8 x 8 x 2048
     x = F.avg_pool2d(x, kernel_size=8)
     # 1 x 1 x 2048
     x_for_capt = x = x.view(x.size(0), -1)
     # 2048
     x = self.fc(x)
     # 1000 (num_classes)
     return x_for_attn, x_for_capt, x
开发者ID:mdasadul,项目名称:Practical_DL,代码行数:33,代码来源:beheaded_inception3.py


示例9: forward

    def forward(self, x):
        x = F.relu(self.bn1(self.conv1(x)), True)
        x = F.avg_pool2d(self.conv2(x), 2, stride=2)
        x = self.conv3(x)
        x = self.conv4(x)

        previous = x

        outputs = []
        for i in range(self.num_modules):
            hg = self._modules['m' + str(i)](previous)

            ll = hg
            ll = self._modules['top_m_' + str(i)](ll)

            ll = F.relu(self._modules['bn_end' + str(i)]
                        (self._modules['conv_last' + str(i)](ll)), True)

            # Predict heatmaps
            tmp_out = self._modules['l' + str(i)](ll)
            outputs.append(tmp_out)

            if i < self.num_modules - 1:
                ll = self._modules['bl' + str(i)](ll)
                tmp_out_ = self._modules['al' + str(i)](tmp_out)
                previous = previous + ll + tmp_out_

        return outputs
开发者ID:RunningLeon,项目名称:face-alignment,代码行数:28,代码来源:models.py


示例10: forward

    def forward(self, x):
        residual = x

        out = self.conv1(x)
        out = self.bn1(out)
        out = self.relu(out)

        out = self.conv2(out)
        out = self.bn2(out)
        out = self.relu(out)

        out = self.conv3(out)
        out = self.bn3(out)


        ## senet
        out2 = F.avg_pool2d(out, kernel_size=out.size(2))
        out2 = self.conv4(out2)
        out2 = self.relu(out2)
        out2 = self.conv5(out2)
        out2 = self.sigmoid(out2)
        # out2 = self.se_block.forward(out)  # not used

        if self.downsample is not None:
            residual = self.downsample(x)

        out = out2 * out + residual
        # out = out2 + residual  # not used
        out = self.relu(out)
        return out
开发者ID:stjordanis,项目名称:VGGFace2-pytorch,代码行数:30,代码来源:senet.py


示例11: forward

    def forward(self, x):
        x1 = self.conv1(x)
        x1 = F.max_pool2d(x1, 3, stride=2)
        x2 = self.fire2(x1)
        x3 = self.fire3(x2)
        if self.bypass:
            x3 = x3 + x2
        x4 = self.fire4(x3)
        x4 = F.max_pool2d(x4, 3, stride=2)
        x5 = self.fire5(x4)
        if self.bypass:
            x5 = x5 + x4
        x6 = self.fire6(x5)
        x7 = self.fire7(x6)
        if self.bypass:
            x7 = x7 + x6
        x8 = self.fire8(x7)
        x8 = F.max_pool2d(x8, 3, stride=2)
        x9 = self.fire9(x8)
        if self.bypass:
            x9 = x9 + x8
        x9 = F.dropout(x9, training=self.training)
        x10 = F.relu(self.conv10(x9))
        f = F.avg_pool2d(x10, x10.size()[2:]).view(x10.size(0), -1)

        if not self.training:
            return f

        if self.loss == {'xent'}:
            return f
        elif self.loss == {'xent', 'htri'}:
            return f, f
        else:
            raise KeyError("Unsupported loss: {}".format(self.loss))
开发者ID:zysolanine,项目名称:deep-person-reid,代码行数:34,代码来源:squeeze.py


示例12: forward

    def forward(self, x):
        xhighres = x
        h = self.blocks[-(self.depth + 1)](xhighres, True)
        if self.depth > 0:
            h = F.avg_pool2d(h, 2)
            if self.alpha < 1.0:
                xlowres = F.avg_pool2d(xhighres, 2)
                preult_rgb = self.blocks[-self.depth].fromRGB(xlowres)
                h = h * self.alpha + (1 - self.alpha) * preult_rgb

        for i in range(self.depth, 0, -1):
            h = self.blocks[-i](h)
            if i > 1:
                h = F.avg_pool2d(h, 2)
        h = self.linear(h.squeeze(-1).squeeze(-1))
        return h
开发者ID:codealphago,项目名称:pggan-pytorch,代码行数:16,代码来源:network.py


示例13: forward

    def forward(self, x):
        # reshape input first with batch size tracked
        x = self.conv1(x)
        x = self.bn1(x)
        x = self.activation(x)
        x = self.dropout(x)
        x = self.main_avg_pool(x)

        x = self.conv2(x)
        x = self.bn2(x)
        x = self.activation(x)
        x = self.dropout(x)
        x = self.main_avg_pool(x)

        x = self.conv3(x)
        x = self.bn3(x)
        x = self.activation(x)
        x = self.dropout(x)
        x = self.main_avg_pool(x)

        x = self.conv4(x)
        x = self.bn4(x)
        x = self.activation(x)
        x = F.avg_pool2d(x, kernel_size=x.size()[-1])

        x = self.conv_to_class(x)
        x = x.view(x.size(0), -1)
        return x
开发者ID:ikhlestov,项目名称:caltech-ml-courses,代码行数:28,代码来源:model_conv.py


示例14: forward

 def forward(self, x):
     features = self.features(x)
     out = F.relu(features, inplace=True)
     out = F.avg_pool2d(out, kernel_size=self.avgpool_size).view(
         features.size(0), -1)
     out = self.classifier(out)
     return out
开发者ID:Robert0812,项目名称:efficient_densenet_pytorch,代码行数:7,代码来源:densenet_efficient_multi_gpu.py


示例15: forward

  def forward(self, x):
    """
    Returns:
      local_feat_list: each member with shape [N, c]
      logits_list: each member with shape [N, num_classes]
    """
    # shape [N, C, H, W]
    feat = self.base(x)
    assert feat.size(2) % self.num_stripes == 0
    stripe_h = int(feat.size(2) / self.num_stripes)
    local_feat_list = []
    logits_list = []
    for i in range(self.num_stripes):
      # shape [N, C, 1, 1]
      local_feat = F.avg_pool2d(
        feat[:, :, i * stripe_h: (i + 1) * stripe_h, :],
        (stripe_h, feat.size(-1)))
      # shape [N, c, 1, 1]
      local_feat = self.local_relu(self.local_bn(self.local_conv(local_feat)))
      # shape [N, c]
      local_feat = local_feat.view(local_feat.size(0), -1)
      local_feat_list.append(local_feat)
      if hasattr(self, 'fc_list'):
        logits_list.append(self.fc_list[i](local_feat))

    if hasattr(self, 'fc_list'):
      return local_feat_list, logits_list

    return local_feat_list
开发者ID:southatsouth,项目名称:beyond-part-models,代码行数:29,代码来源:PCBModel.py


示例16: on_step_validation

    def on_step_validation(self, state):
        if not self.done:
            x = state[torchbearer.X].data.clone()

            if len(x.size()) == 3:
                x = x.unsqueeze(1)

            x = F.avg_pool2d(x, self.avg_pool_size).data

            data = None

            if state[torchbearer.EPOCH] == 0 and self.write_data:
                if self.avg_data_channels:
                    data = torch.mean(x, 1)
                else:
                    data = x

                data = data.view(data.size(0), -1)

            feature = None

            if self.write_features:
                feature = state[self.features_key].data.clone()
                feature = feature.view(feature.size(0), -1)

            label = state[torchbearer.Y_TRUE].data.clone()

            if state[torchbearer.BATCH] == 0:
                remaining = self.num_images if self.num_images < label.size(0) else label.size(0)

                self._images = x[:remaining].to('cpu')
                self._labels = label[:remaining].to('cpu')

                if data is not None:
                    self._data = data[:remaining].to('cpu')

                if feature is not None:
                    self._features = feature[:remaining].to('cpu')
            else:
                remaining = self.num_images - self._labels.size(0)

                if remaining > label.size(0):
                    remaining = label.size(0)

                self._images = torch.cat((self._images, x[:remaining].to('cpu')), dim=0)
                self._labels = torch.cat((self._labels, label[:remaining].to('cpu')), dim=0)

                if data is not None:
                    self._data = torch.cat((self._data, data[:remaining].to('cpu')), dim=0)

                if feature is not None:
                    self._features = torch.cat((self._features, feature[:remaining].to('cpu')), dim=0)

            if self._labels.size(0) >= self.num_images:
                if state[torchbearer.EPOCH] == 0 and self.write_data:
                    self._writer.add_embedding(self._data, metadata=self._labels, label_img=self._images, tag='data', global_step=-1)
                if self.write_features:
                    self._writer.add_embedding(self._features, metadata=self._labels, label_img=self._images, tag='features', global_step=state[torchbearer.EPOCH])
                self.done = True
开发者ID:little1tow,项目名称:torchbearer,代码行数:59,代码来源:tensor_board.py


示例17: forward

 def forward(self, x):
     out = self.conv1(x)
     out = self.trans1(self.dense1(out))
     out = self.trans2(self.dense2(out))
     out = self.dense3(out)
     out = torch.squeeze(F.avg_pool2d(F.relu(self.bn1(out)), 8))
     out = F.log_softmax(self.fc(out))
     return out
开发者ID:shubhampachori12110095,项目名称:densenet.pytorch,代码行数:8,代码来源:densenet.py


示例18: forward

 def forward(self, x):
     B = x.data.size(0)
     C = x.data.size(1)
     H = x.data.size(2)
     W = x.data.size(3)
     x = F.avg_pool2d(x, (H, W))
     x = x.view(B, C)
     return x
开发者ID:GUOShuxuan,项目名称:ObjectDetection-OneStageDet,代码行数:8,代码来源:_darknet.py


示例19: forward

 def forward(self, x):
     x = self.conv_1_3x3.forward(x)
     x = F.relu(self.bn_1.forward(x), inplace=True)
     x = self.stage_1.forward(x)
     x = self.stage_2.forward(x)
     x = self.stage_3.forward(x)
     x = F.avg_pool2d(x, 8, 1)
     x = x.view(-1, 1024)
     return self.classifier(x)
开发者ID:YJieZhang,项目名称:pytorch-classification,代码行数:9,代码来源:resnext.py


示例20: forward

 def forward(self, x):
     out = F.relu(self.bn1(self.conv1(x)))
     out = self.layers(out)
     out = F.relu(self.bn2(self.conv2(out)))
     # NOTE: change pooling kernel_size 7 -> 4 for CIFAR10
     out = F.avg_pool2d(out, 4)
     out = out.view(out.size(0), -1)
     out = self.linear(out)
     return out
开发者ID:jiqiujia,项目名称:kaggle_camera_id,代码行数:9,代码来源:mobilenetv2.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python functional.cross_entropy函数代码示例发布时间:2022-05-27
下一篇:
Python utils.broadcast_all函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap