PyTorch深度学习快速入门教程-P18神经网络层-卷积层

# coding=gbk 
import torchvision
import torch
from torch import nn
from torch.nn import Conv2d
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter

#这个文件在C盘里也需要下载一遍,此python文件属于Vscode不属于Jupyter
dataset = torchvision.datasets.CIFAR10("dataset", train=False, transform=torchvision.transforms.ToTensor(),download=True)

dataloader = DataLoader(dataset, batch_size=64)
 
class JYW(nn.Module):
    def __init__(self):
        super(JYW, self).__init__()
        self.conv1 = Conv2d(in_channels=3, out_channels=6, kernel_size=3, stride=1, padding=0)

    def forward(self, x):
        x = self.conv1(x)
        return x

TD = JYW()

writer = SummaryWriter("/logs")
step = 0
for data in dataloader:

    imgs, targets = data
    output = TD(imgs)
    print(imgs.shape)
    print(output.shape)

    writer.add_images("input", imgs, step)

    output = torch.reshape(output, (-1, 3, 30, 30))
    writer.add_images("output", output, step)

    step += 1

writer.close()

#视频18,如何使用卷积层进行简单的一次卷积处理
#需要注意,卷积之后的图片需要转换一下图片大小,第二维度必须要为3才能显示图片

#Tips:
#Tensorboard可以直接在Vscode里运行,选中C盘下的logs文件就可以

#Question
#现在不知道如何让程序自动导入Python第三方库

你可能感兴趣的:(PyTorch深度学习-小土堆,深度学习,pytorch,神经网络)