实战卷积层
import torch
from torch import nn
from torch.nn import Conv2d
from torch.utils.data import DataLoader
import torchvision
from tensorboardX import SummaryWriter
dataset = torchvision.datasets.CIFAR10('./data',
train=False,
transform=torchvision.transforms.ToTensor(),
download=True)
dataloader = DataLoader(dataset, batch_size=64)
class qingfeng(nn.Module):
def __init__(self):
super(qingfeng, 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
qingfeng = qingfeng()
print(qingfeng)
writer = SummaryWriter('./logs')
step = 0
for data in dataloader:
imgs, targets = data
print("输入图片形状",imgs.shape)
output = qingfeng(imgs)
print("输出图片形状",output.shape)
writer.add_images("input", imgs, step)
output = torch.reshape(output, (-1, 3, 30, 30))
print("改变形状后的图像",output.shape)
writer.add_images('output', output, step)
step += 1
writer.close()
activate pytorch tensorboard --logdir “logs”
|