当前位置:   article > 正文

神经网络卷积层nn.Conv2d

nn.conv2d

神经网络卷积层

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



  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/691169
推荐阅读
相关标签
  

闽ICP备14008679号