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


Python functional.bilinear方法代码示例

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


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

示例1: forward

# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import bilinear [as 别名]
def forward(self, input_left, input_right):
        '''
        Args:
            input_left: Tensor
                the left input tensor with shape = [batch1, batch2, ..., left_features]
            input_right: Tensor
                the right input tensor with shape = [batch1, batch2, ..., right_features]
        Returns:
        '''

        left_size = input_left.size()
        right_size = input_right.size()
        assert left_size[:-1] == right_size[:-1], \
            "batch size of left and right inputs mis-match: (%s, %s)" % (left_size[:-1], right_size[:-1])
        batch = int(np.prod(left_size[:-1]))

        # convert left and right input to matrices [batch, left_features], [batch, right_features]
        input_left = input_left.view(batch, self.left_features)
        input_right = input_right.view(batch, self.right_features)

        # output [batch, out_features]
        output = F.bilinear(input_left, input_right, self.U, self.bias)
        output = output + F.linear(input_left, self.W_l, None) + F.linear(input_right, self.W_r, None)
        # convert back to [batch1, batch2, ..., out_features]
        return output.view(left_size[:-1] + (self.out_features, )) 
开发者ID:jcyk,项目名称:gtos,代码行数:27,代码来源:bilinear.py

示例2: forward

# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import bilinear [as 别名]
def forward(self, input_left, input_right):
        """

        Args:
            input_left: Tensor
                the left input tensor with shape = [batch1, batch2, ..., left_features]
            input_right: Tensor
                the right input tensor with shape = [batch1, batch2, ..., right_features]

        Returns:

        """

        batch_size = input_left.size()[:-1]
        batch = int(np.prod(batch_size))

        # convert left and right input to matrices [batch, left_features], [batch, right_features]
        input_left = input_left.view(batch, self.left_features)
        input_right = input_right.view(batch, self.right_features)

        # output [batch, out_features]
        output = F.bilinear(input_left, input_right, self.U, self.bias)
        output = output + F.linear(input_left, self.weight_left, None) + F.linear(input_right, self.weight_right, None)
        # convert back to [batch1, batch2, ..., out_features]
        return output.view(batch_size + (self.out_features, )) 
开发者ID:XuezheMax,项目名称:NeuroNLP2,代码行数:27,代码来源:modules.py

示例3: forward

# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import bilinear [as 别名]
def forward(self, input_left, input_right):
        '''

        Args:
            input_left: Tensor
                the left input tensor with shape = [batch1, batch2, ..., left_features]
            input_right: Tensor
                the right input tensor with shape = [batch1, batch2, ..., right_features]

        Returns:

        '''

        left_size = input_left.size()
        right_size = input_right.size()
        assert left_size[:-1] == right_size[:-1], \
            "batch size of left and right inputs mis-match: (%s, %s)" % (left_size[:-1], right_size[:-1])
        batch = int(np.prod(left_size[:-1]))

        # convert left and right input to matrices [batch, left_features], [batch, right_features]
        input_left = input_left.view(batch, self.left_features)
        input_right = input_right.view(batch, self.right_features)

        # output [batch, out_features]
        output = F.bilinear(input_left, input_right, self.U, self.bias)
        output = output + F.linear(input_left, self.W_l, None) + F.linear(input_right, self.W_r, None)
        # convert back to [batch1, batch2, ..., out_features]
        return output.view(left_size[:-1] + (self.out_features, )) 
开发者ID:thomas0809,项目名称:GraphIE,代码行数:30,代码来源:linear.py

示例4: forward

# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import bilinear [as 别名]
def forward(self, input1, input2):
        dir_ = self.direction
        direction = dir_.div(dir_.pow(2).sum(1).sum(1).sqrt()[:,N_,N_])
        weight = self.scale[:,N_,N_].mul(direction)
        return F.bilinear(input1, input2, weight, self.bias) 
开发者ID:CW-Huang,项目名称:torchkit,代码行数:7,代码来源:nn.py

示例5: forward

# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import bilinear [as 别名]
def forward(self, input1, input2):
        weight = self._regulize_parameter(self.weight)
        output = F.bilinear(input1, input2, weight, None)
        if self.norm:
            output = normalize_prob(output)
        return output 
开发者ID:vacancy,项目名称:Jacinle,代码行数:8,代码来源:probability.py

示例6: forward

# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import bilinear [as 别名]
def forward(self, input1, input2, params=None):
        if params is None:
            params = OrderedDict(self.named_parameters())
        bias = params.get('bias', None)
        return F.bilinear(input1, input2, params['weight'], bias) 
开发者ID:tristandeleu,项目名称:pytorch-meta,代码行数:7,代码来源:linear.py

示例7: test_grid_sample

# 需要导入模块: from torch.nn import functional [as 别名]
# 或者: from torch.nn.functional import bilinear [as 别名]
def test_grid_sample(self):
        inp = torch.randn(16, 8, 64, 64, device='cuda', dtype=self.dtype)
        grid = torch.randn(16, 32, 32, 2, device='cuda', dtype=self.dtype)
        output = F.grid_sample(inp, grid, mode='bilinear', padding_mode='zeros') 
开发者ID:NVIDIA,项目名称:apex,代码行数:6,代码来源:test_pyprof_nvtx.py


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