Python torch.nn.functional.adaptive_avg_pool1d() Examples
The following are 9
code examples of torch.nn.functional.adaptive_avg_pool1d().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
torch.nn.functional
, or try the search function
.
Example #1
Source File: frontend.py From pase with MIT License | 6 votes |
def fuse_skip(self, input_, skip): #print('input_ shape: ', input_.shape) #print('skip shape: ', skip.shape) dfactor = skip.shape[2] // input_.shape[2] if dfactor > 1: #print('dfactor: ', dfactor) # downsample skips # [B, F, T] maxlen = input_.shape[2] * dfactor skip = skip[:, :, :maxlen] bsz, feats, slen = skip.shape skip_re = skip.view(bsz, feats, slen // dfactor, dfactor) skip = torch.mean(skip_re, dim=3) #skip = F.adaptive_avg_pool1d(skip, input_.shape[2]) if self.densemerge == 'concat': return torch.cat((input_, skip), dim=1) elif self.densemerge == 'sum': return input_ + skip else: raise TypeError('Unknown densemerge: ', self.densemerge)
Example #2
Source File: spectral.py From torchsupport with MIT License | 6 votes |
def forward(self, graph): nodes = graph.node_tensor out = self.preprocess(nodes) out = out.reshape(out.size(0), out.size(1) * out.size(2), 1) out += self.merge(nodes).reshape(out.size(0), out.size(1) * out.size(2), 1) out = self.activation(out) for _ in range(self.depth - 1): out -= graph.laplacian_action(out) out = self.propagate(out) out += self.merge(nodes).reshape(out.size(0), out.size(1) * out.size(2), 1) out = self.activation(out) out = out.reshape(nodes.size(0), nodes.size(1), self.width) out = func.adaptive_avg_pool1d(out, 1).reshape( nodes.size(0), -1 ).unsqueeze(2) result = graph.new_like() result.node_tensor = out return result
Example #3
Source File: frontend.py From pase with MIT License | 5 votes |
def fuse(self, out): last_feature = out[-1] for i in range(len(out) - 1): out[i] = F.adaptive_avg_pool1d(out[i], last_feature.shape[-1]) return out
Example #4
Source File: spectral.py From torchsupport with MIT License | 5 votes |
def forward(self, data, structure): out = self.preprocess(data, data, structure) for block in self.blocks: out = block(out, data, structure) out = self.postprocess(out, data, structure) out = out.reshape(data.size(0), -1, self.width) return func.adaptive_avg_pool1d(out, 1)
Example #5
Source File: layers.py From TorchFusion with MIT License | 5 votes |
def pool(self, input): return F.adaptive_avg_pool1d(input,1)
Example #6
Source File: conv.py From seq2seq.pytorch with MIT License | 5 votes |
def forward(self, inputs, state): x = self.embedder(inputs) x = x.transpose(1, 2) state = F.adaptive_avg_pool1d(state, x.size(2)) x = torch.cat([x, state], 1) x = self.convs(x) x = x.transpose(1, 2) # BxTxN x = x.contiguous().view(-1, x.size(2)) x = self.classifier(x) x = x.view(inputs.size(0), inputs.size(1), -1) # BxTxN return x
Example #7
Source File: test_pyprof_nvtx.py From apex with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_adaptive_avg_pool1d(self): inp = torch.randn(1, 1, 28, device='cuda', dtype=self.dtype) out = F.adaptive_avg_pool1d(inp, output_size=5)
Example #8
Source File: bpv.py From ecom-rakuten with MIT License | 5 votes |
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)
Example #9
Source File: feature_model.py From starsem2018-entity-linking with Apache License 2.0 | 4 votes |
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)