LinearLayer

线性层的作用,类似于这边荧光绿的两层,就是fully connected layer

将1*1*4096的向量,变成1*1*1000的向量

  • 代码示例
import torch
import torchvision
from torch import nn
from torch.nn import Linear
from torch.utils.data import DataLoader

class Module(nn.Module):

    def __init__(self):
        super().__init__()
        self.linear = Linear(196608,10)

    def forward(self, input):
        output = self.linear(input)
        return output


test_data = torchvision.datasets.CIFAR10('dataset',train=False,transform=torchvision.transforms.ToTensor(),download=True)
# drop_last (bool, optional) – set to True to drop the last incomplete batch, if the dataset size is not divisible by the batch size.
# If False and the size of dataset is not divisible by the batch size, then the last batch will be smaller. (default: False)
# drop_last可以把最后不足64张图的batch补足
data_loader = DataLoader(test_data,batch_size=64,drop_last=True)

module = Module()
for data in data_loader:
    images ,target =data
    # print(images.shape)
    output = torch.reshape(images,(1,1,1,-1))
    print(output.shape)
    output=module(output)
    print(output.shape)

  1.  另外,将向量展开成一行有一个特殊的函数:torch.flatten()

 output = torch.flatten(images)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值