线性层 就是拉平

本文介绍了如何在PyTorch中使用CIFAR-10数据集构建一个基础的卷积神经网络模型,包括数据预处理、模型定义(线性层和展平操作)以及模型在数据上的前向传播过程。
摘要由CSDN通过智能技术生成
import torch
import torchvision
from torch import nn

from torch.nn import MaxPool2d
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter

from torch.nn import Linear
from torch.nn import Flatten


input = torch.tensor([
    [1,2,0,3,1],
    [0,1,2,3,1],
    [1,2,1,0,0],
    [5,2,3,1,1],
    [2,1,0,1,1]
],dtype=torch.float32)

print(input.shape)


data = torchvision.datasets.CIFAR10("./dataset",train=False,transform=torchvision.transforms.ToTensor())
dataloader = DataLoader(data,batch_size=64)

# for data in dataloader:
#     img,target = data
#     print(img.shape)
#     print(    img.reshape(1,1,1,-1).shape )




class Tudui(nn.Module):
    def __init__(self):
        super(Tudui, self).__init__()
        self.liner1 = Linear(196608,10)    #不够3*3的边缘,要

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

tudui = Tudui()

for data in dataloader:
    img,target = data
    print(img.shape)


    output = img.reshape(1, 1, 1, -1)
    # output = torch.flatten(img)

    output = tudui(output)
    print(output.shape)
    print(output)







  • 7
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值