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


Python functional.adaptive_max_pool1d方法代码示例

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


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

示例1: forward

# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_max_pool1d [as 别名]
def forward(self, x, phase='train'):
        feats = self.densenet121(x)  # (32, 1024, 2, 16)
        if not args.small:
            feats = F.max_pool2d(feats, kernel_size=2, stride=2)  # (32, 1024, 1, 8)
        out = self.classifier_font(feats)  # (32, 1824, 1, 8)
        out_size = out.size()
        # print out.size()
        out = out.view(out.size(0), out.size(1), -1)  # (32, 1824, 8)
        # print out.size()
        if phase == 'train':
            out = F.adaptive_max_pool1d(out, output_size=(1)).view(out.size(0), -1)  # (32, 1824)
            return out
        else:
            out = out.transpose(1, 2).contiguous()
            out = out.view(out_size[0], out_size[2], out_size[3], out_size[1])  # (32, 1, 8, 1824)
            return out, feats 
开发者ID:HLIG,项目名称:HUAWEIOCR-2019,代码行数:18,代码来源:main.py

示例2: pool

# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_max_pool1d [as 别名]
def pool(self, input):
        return F.adaptive_max_pool1d(input, 1) 
开发者ID:johnolafenwa,项目名称:TorchFusion,代码行数:4,代码来源:layers.py

示例3: test_adaptive_max_pool1d

# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_max_pool1d [as 别名]
def test_adaptive_max_pool1d(self):
        inp = torch.randn(1, 16, 28, device='cuda', dtype=self.dtype)
        out = F.adaptive_max_pool1d(inp, output_size=5, return_indices=True) 
开发者ID:NVIDIA,项目名称:apex,代码行数:5,代码来源:test_pyprof_nvtx.py

示例4: pool

# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_max_pool1d [as 别名]
def pool(self, x, bs, is_max):
        f = F.adaptive_max_pool1d if is_max else F.adaptive_avg_pool1d
        return f(x.permute(1, 2, 0), (1,)).view(bs, -1) 
开发者ID:mcskinner,项目名称:ecom-rakuten,代码行数:5,代码来源:bpv.py

示例5: forward

# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_max_pool1d [as 别名]
def forward(self, sent_m, mention_m,
                relations_m, relations_words_m,
                entities_m, candidates_m, candidates_labels_m, features_m):
        choices = candidates_labels_m.size(1)  # number of possible candidates per one mention
        real_choices_num = torch.sum((candidates_m > 0).float(), dim=1).unsqueeze(1)

        sent_emb = self._words2vector(sent_m).unsqueeze(1)
        mention_emb = self._chars2vector(mention_m).unsqueeze(1)

        sent_emb_expanded = sent_emb.expand(sent_emb.size(0), choices, sent_emb.size(2)).contiguous()
        mention_emb_expanded = mention_emb.expand(mention_emb.size(0), choices, mention_emb.size(2)).contiguous()

        relations_words_m = relations_words_m.view(relations_words_m.size(0) *
                                                   relations_words_m.size(1) * relations_words_m.size(2), -1)
        relations_m = relations_m.view(relations_m.size(0) * relations_m.size(1), -1)
        entities_m = entities_m.view(entities_m.size(0) * entities_m.size(1), -1)
        candidates_labels_m = candidates_labels_m.view(candidates_labels_m.size(0) * candidates_labels_m.size(1), -1, 2)

        candidate_vectors = self.compute_candidate_vectors(relations_m, relations_words_m,
                                           entities_m, candidates_m, candidates_labels_m)
        candidate_vectors = candidate_vectors.view(-1, choices, candidate_vectors.size(-1))

        features_m = features_m.float()

        concatenated_embed = torch.cat((sent_emb_expanded,
                                        mention_emb_expanded,
                                        candidate_vectors,
                                        features_m
                                        ), dim=-1).contiguous()
        concatenated_embed = concatenated_embed.view(-1, concatenated_embed.size(-1))
        sem_vector = self.sem_layers(concatenated_embed)
        sem_vector = sem_vector.view(-1, choices, sem_vector.size(-1))

        sem_vector_pooled_over_choices = sem_vector.transpose(-2, -1)
        sem_vector_pooled_over_choices = self._pool(sem_vector_pooled_over_choices)
        sem_vector_pooled_over_choices = sem_vector_pooled_over_choices.transpose(-2, -1)
        sem_vector = torch.cat((sem_vector, sem_vector_pooled_over_choices.expand_as(sem_vector)), dim=-1)
        sem_vector = sem_vector.view(-1, sem_vector.size(-1))

        candidate_scores = self.score_weights(sem_vector).squeeze(dim=-1)
        candidate_scores = candidate_scores.view(-1, choices)

        negative_vector = torch.cat((sent_emb.squeeze(dim=1),
                                     mention_emb.squeeze(dim=1)), dim=1)
        negative_vector = self.negative_layers(negative_vector)
        real_choices_num = self._nonlinearity(real_choices_num)
        choices_pooled_for_negative = sem_vector_pooled_over_choices.squeeze(dim=1)
        negative_vector = torch.cat((negative_vector,
                                     choices_pooled_for_negative,
                                     F.adaptive_max_pool1d(candidate_scores.unsqueeze(1), 1).squeeze(dim=-1),
                                     real_choices_num
                                     ), dim=-1)
        negative_score = self.negative_weight(negative_vector)

        candidate_scores = self._nonlinearity(candidate_scores)
        return F.sigmoid(negative_score.squeeze(dim=-1)), candidate_scores 
开发者ID:UKPLab,项目名称:starsem2018-entity-linking,代码行数:58,代码来源:vector_model.py

示例6: forward

# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import adaptive_max_pool1d [as 别名]
def forward(self, e_x, e_sig, x, x_sig):
        e_x = e_x.long()
        x = x.float()
        x_sig = x_sig.float()
        e_sig = e_sig.float()
        choices = x.size(1)

        e_x = self._pos_embeddings(e_x)
        e_x = e_x.transpose(1, 2)
        e_x = F.adaptive_avg_pool1d(e_x, 1).view(*e_x.size()[:2])
        e_x = e_x.unsqueeze(1)
        e_x = e_x.expand(e_x.size(0), choices, e_x.size(2)).contiguous()
        e_sig = e_sig.unsqueeze(1)
        e_sig = e_sig.expand(e_sig.size(0), choices, e_sig.size(2)).contiguous()

        x = torch.cat((
            x,
            x_sig,
            e_x,
            e_sig), dim=-1)
        x = x.view(-1, x.size(-1))

        i = self.individual_weights(x)
        i = F.relu(i)
        i = self.hidden_weights(i)
        i = F.relu(i)
        i = i.view(-1, choices, i.size(-1))

        s = i.transpose(1, 2)
        s = F.adaptive_max_pool1d(s, 1)
        s = s.transpose(1, 2)

        v = s.expand_as(i)
        v = torch.cat((i, v), dim=-1)
        v = v.view(-1, v.size(-1))

        v = self._dropout(v)
        x = self.score_weights(v)
        x = x.view(-1, choices)
        # x = F.relu(x)

        z = s.view(-1,  s.size(-1))

        z = self._dropout(z)
        z = self.negative_weights(z)

        # x = torch.cat((z, x), dim=-1)

        return F.sigmoid(z.squeeze(dim=-1)), F.softmax(x, dim=-1) 
开发者ID:UKPLab,项目名称:starsem2018-entity-linking,代码行数:51,代码来源:feature_model.py


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