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


Python torch.flatten方法代码示例

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


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

示例1: forward

# 需要导入模块: import torch [as 别名]
# 或者: from torch import flatten [as 别名]
def forward(self, x):
        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)
        x = self.maxpool(x)

        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)

        x = self.avgpool(x)
        #x = x.view(x.size(0), -1)
        x = torch.flatten(x, 1)
        if self.drop:
            x = self.drop(x)
        x = self.fc(x)

        return x 
开发者ID:zhanghang1989,项目名称:PyTorch-Encoding,代码行数:21,代码来源:resnet.py

示例2: forward

# 需要导入模块: import torch [as 别名]
# 或者: from torch import flatten [as 别名]
def forward(self, x):
        x = self.model(x)

        x = torch.flatten(x, start_dim=1)  # Flattens layers without losing batches

        x = self.full_conn1(x)
        x = self.norm1(x)
        x = F.relu(x)
        x = F.dropout(x)

        x = self.full_conn2(x)
        x = F.relu(x)
        x = F.dropout(x)

        x = self.full_conn3(x)

        return x 
开发者ID:CMU-CREATE-Lab,项目名称:deep-smoke-machine,代码行数:19,代码来源:pytorch_ts.py

示例3: _forward_impl

# 需要导入模块: import torch [as 别名]
# 或者: from torch import flatten [as 别名]
def _forward_impl(self, x):
        # See note [TorchScript super()]
        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)
        x = self.maxpool(x)

        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)

        x = self.avgpool(x)
        # EDIT(momohatt): Add 'start_dim='
        x = torch.flatten(x, start_dim=1)
        x = self.fc(x)

        return x 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:20,代码来源:resnet.py

示例4: forward

# 需要导入模块: import torch [as 别名]
# 或者: from torch import flatten [as 别名]
def forward(self, x):
        x = self.conv1(x)
        x = F.relu(x)
        x = self.conv2(x)
        x = F.max_pool2d(x, 2)
        x = self.dropout1(x)
        x = torch.flatten(x, start_dim=1) # EDIT(momohatt): Add 'start_dim='
        x = self.fc1(x)
        x = F.relu(x)
        x = self.dropout2(x)
        x = self.fc2(x)
        output = F.log_softmax(x, dim=1)
        return output


# Example input 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:18,代码来源:mnist.py

示例5: protobuf_tensor_serializer

# 需要导入模块: import torch [as 别名]
# 或者: from torch import flatten [as 别名]
def protobuf_tensor_serializer(worker: AbstractWorker, tensor: torch.Tensor) -> TensorDataPB:
    """Strategy to serialize a tensor using Protobuf"""
    dtype = TORCH_DTYPE_STR[tensor.dtype]

    protobuf_tensor = TensorDataPB()

    if tensor.is_quantized:
        protobuf_tensor.is_quantized = True
        protobuf_tensor.scale = tensor.q_scale()
        protobuf_tensor.zero_point = tensor.q_zero_point()
        data = torch.flatten(tensor).int_repr().tolist()
    else:
        data = torch.flatten(tensor).tolist()

    protobuf_tensor.dtype = dtype
    protobuf_tensor.shape.dims.extend(tensor.size())
    getattr(protobuf_tensor, "contents_" + dtype).extend(data)

    return protobuf_tensor 
开发者ID:OpenMined,项目名称:PySyft,代码行数:21,代码来源:torch_serde.py

示例6: forward

# 需要导入模块: import torch [as 别名]
# 或者: from torch import flatten [as 别名]
def forward(self, x):
        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)
        x = self.maxpool(x)

        x, layer1_sum = self.layer1(x)
        x, layer2_sum = self.layer2(x)
        x, layer3_sum = self.layer3(x)
        x, layer4_sum = self.layer4(x)

        x = self.avgpool(x)
        x = torch.flatten(x, 1)
        x = self.fc(x)

        return x, layer1_sum + layer2_sum + layer3_sum + layer4_sum 
开发者ID:d-li14,项目名称:dgconv.pytorch,代码行数:18,代码来源:g_resnext.py

示例7: _forward_impl

# 需要导入模块: import torch [as 别名]
# 或者: from torch import flatten [as 别名]
def _forward_impl(self, x):
        # See note [TorchScript super()]
        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)
        x = self.maxpool(x)

        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)
        x = self.bn5(x)
        x = self.relu(x)
        x = self.avgpool(x)
        x = torch.flatten(x, 1)
        #x = self.fc(x)

        return x 
开发者ID:legolas123,项目名称:cv-tricks.com,代码行数:20,代码来源:resnet_preact_bin.py

示例8: _forward_impl

# 需要导入模块: import torch [as 别名]
# 或者: from torch import flatten [as 别名]
def _forward_impl(self, x):
        # See note [TorchScript super()]
        x = self.conv1(x)
        # x = self.bn1(x)
        # x = self.relu(x)
        x = self.maxpool(x)

        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)
        x = self.bn5(x)
        x = self.relu(x)
        x = self.avgpool(x)
        x = torch.flatten(x, 1)
        #x = self.fc(x)

        return x 
开发者ID:legolas123,项目名称:cv-tricks.com,代码行数:20,代码来源:resnet_preact.py

示例9: forward

# 需要导入模块: import torch [as 别名]
# 或者: from torch import flatten [as 别名]
def forward(self, x):
    x = x.reshape(280, 280, 4)
    x = torch.narrow(x, dim=2, start=3, length=1)
    x = x.reshape(1, 1, 280, 280)
    x = F.avg_pool2d(x, 10, stride=10)
    x = x / 255
    x = (x - MEAN) / STANDARD_DEVIATION

    x = self.conv1(x)
    x = F.relu(x)
    x = self.conv2(x)
    x = F.max_pool2d(x, 2)
    x = self.dropout1(x)
    x = torch.flatten(x, 1)
    x = self.fc1(x)
    x = F.relu(x)
    x = self.dropout2(x)
    x = self.fc2(x)
    output = F.softmax(x, dim=1)
    return output 
开发者ID:elliotwaite,项目名称:pytorch-to-javascript-with-onnx-js,代码行数:22,代码来源:inference_mnist_model.py

示例10: forward

# 需要导入模块: import torch [as 别名]
# 或者: from torch import flatten [as 别名]
def forward(self, x):
        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)
        #x = self.maxpool(x)

        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)

        x = self.avgpool(x)
        x = torch.flatten(x, 1)
        x = self.fc(x)

        return x 
开发者ID:facebookresearch,项目名称:fastMRI,代码行数:18,代码来源:unpooled_resnet.py

示例11: forward

# 需要导入模块: import torch [as 别名]
# 或者: from torch import flatten [as 别名]
def forward(self, x):
        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)
        x = self.maxpool(x)

        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)

        x = self.avgpool(x)
        x = torch.flatten(x, 1)
        x = self.fc(x)

        return x 
开发者ID:facebookresearch,项目名称:fastMRI,代码行数:18,代码来源:torchvision_resnet.py

示例12: forward

# 需要导入模块: import torch [as 别名]
# 或者: from torch import flatten [as 别名]
def forward(self, x):
        x = self.conv1(x)       # batch*32*20*20
        x = self.bn1(x)
        x = F.relu(x)
        x = F.max_pool2d(x, 2)  # batch*32*10*10
        x = self.conv2(x)       # batch*64*8*8
        x = self.bn2(x)
        x = F.relu(x)
        x = F.max_pool2d(x, 2)  # batch*64*4*4
        x = self.conv3(x)       # batch*128*2*2
        x = self.bn3(x)
        x = F.relu(x)
        x = torch.flatten(x, 1) # batch*512
        x = self.fc1(x)         # batch*128
        x = F.relu(x)
        x = self.fc2(x)         # batch*55
        x = F.log_softmax(x, dim=1)
        return x 
开发者ID:zhongxinghong,项目名称:PKUAutoElective,代码行数:20,代码来源:cnn.py

示例13: findwordlist

# 需要导入模块: import torch [as 别名]
# 或者: from torch import flatten [as 别名]
def findwordlist(template, closewordind, vocab, numwords=10, addeos=False):
    """
    Based on a template sentence, find the candidate word list.
    
    Input:
        template: source sentence.
        closewordind: precalculated 100 closest word indices (using character embeddings). torch.LongTensor.
        vocab: full vocabulary.
        numwords: number of closest words per word in the template.
        addeos: whether to include '<eos>' in the candidate word list.
    """
    if isinstance(template, str):
        template = template.split()
    templateind = closewordind.new_tensor([vocab.stoi[w] for w in template])
    # subvocab = closewordind[templateind, :numwords].flatten().cpu()  # torch.flatten() only exists from PyTorch 0.4.1
    subvocab = closewordind[templateind, :numwords].view(-1).cpu()
    if addeos:
        subvocab = torch.cat([subvocab, torch.LongTensor([vocab.stoi['<eos>']])])
    subvocab = subvocab.unique(sorted=True)
    word_list = [vocab.itos[i] for i in subvocab]
    
    return word_list, subvocab 
开发者ID:jzhou316,项目名称:Unsupervised-Sentence-Summarization,代码行数:24,代码来源:pre_word_list.py

示例14: _forward_impl

# 需要导入模块: import torch [as 别名]
# 或者: from torch import flatten [as 别名]
def _forward_impl(self, x):
        # See note [TorchScript super()]
        x = self.conv1(x)
        x = self.bn1(x)
        x = self.relu(x)
        x = self.maxpool(x)

        x = self.layer1(x)
        x = self.layer2(x)
        x = self.layer3(x)
        x = self.layer4(x)

        x = self.avgpool(x)
        x = torch.flatten(x, 1)
        x = self.fc(x)

        return x 
开发者ID:intel,项目名称:optimized-models,代码行数:19,代码来源:resnet.py

示例15: forward

# 需要导入模块: import torch [as 别名]
# 或者: from torch import flatten [as 别名]
def forward(self, x):
        # N x 768 x 17 x 17
        x = F.avg_pool2d(x, kernel_size=5, stride=3)
        # N x 768 x 5 x 5
        x = self.conv0(x)
        # N x 128 x 5 x 5
        x = self.conv1(x)
        # N x 768 x 1 x 1
        # Adaptive average pooling
        x = F.adaptive_avg_pool2d(x, (1, 1))
        # N x 768 x 1 x 1
        x = torch.flatten(x, 1)
        # N x 768
        x = self.fc(x)
        # N x 1000
        return x 
开发者ID:rwightman,项目名称:pytorch-image-models,代码行数:18,代码来源:inception_v3.py


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