当前位置:网站首页>Pytorch deep learning -- neural network convolution layer conv2d

Pytorch deep learning -- neural network convolution layer conv2d

2022-06-10 20:47:00 Hair will grow again without it

torn.nn.Conv2d

stay Official documents You can view the parameters
 Insert picture description here
 Insert picture description here

Code example :

import torch
import torchvision
from torch import nn
from torch.nn import Conv2d
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter

dataset = torchvision.datasets.CIFAR10("./data", train=False, transform=torchvision.transforms.ToTensor(), download=True)

dataloader = DataLoader(dataset, 64)

class MyMoudle(nn.Module):
   def __init__(self):
       super(MyMoudle, self).__init__()
       self.conv1 = Conv2d(3, 6, 3, stride=1, padding=0)

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

Myconv = MyMoudle()# neural network 

writer = SummaryWriter("logs")
step = 0
for data in dataloader:
    imgs, target = data
    output = Myconv(imgs)
    writer.add_images("input", imgs, step)
    output = torch.reshape(output, (-1, 3, 30, 30))# Because it was (XX, 6, 30, 30)6 individual channel Will report a mistake 
    writer.add_images("output", output, step)

writer.close()

Output :
 Insert picture description here

原网站

版权声明
本文为[Hair will grow again without it]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101947039888.html