赞
踩
神经网络卷积层
nn.Conv2d
import torch import torchvision 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.ToTenssor(), download = Ture) #下载数据集 dataloader = DataLoader(dataset, batch_size = 64) class Model_test(nn.Module): def__init__(self): super(Model_test, self).__init__() self.conv1 = Conv2d(in_channels =3, out_channels=6, kernel_size = 3, stride= 1, padding = 0) def forward(self, x): x=self.cconv1(x) return x model_test = Model_test() writer = SummaryWriter("../logs") step = 0 for data in dataloader: imgs, targets = data output = model_test(imgs) print(imgs.shape) print(output.shape) #torch.size([64,3,32,32]) writer.add_images("input", imgs, step) #tensorboard 输出 #torch.size([64,3,32,32])-->[xxx,3,30,30] 什么时候需要reshape torch.reshape(output, (-1, 3, 30,30)) writer.add_images("output", output, step) #tensorboard 输出 step = step +1 #terminal : tensorboard --logdir = logs
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。