-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9_nn_conv2d.py
More file actions
40 lines (31 loc) · 1.01 KB
/
Copy path9_nn_conv2d.py
File metadata and controls
40 lines (31 loc) · 1.01 KB
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
39
40
import torch
import torch.nn as nn
import torchvision
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
from torchvision import transforms
dataset = torchvision.datasets.CIFAR10(root='./dataset', train=True, transform=transforms.ToTensor(), download=True)
dataloader = DataLoader(dataset, batch_size=64, shuffle=True)
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = nn.Conv2d(in_channels=3, out_channels=6, kernel_size=3)
def forward(self, x):
x = self.conv1(x)
return x
net = Net()
# print(net)
writer = SummaryWriter('./nn_conv2d_logs')
step = 1
for data in dataloader:
imgs, targets = data
output = net(imgs)
# torch.Size([64, 3, 32, 32])
# print(imgs.shape)
# torch.Size([64, 6, 30, 30])
# print(output.shape)
output = torch.reshape(output, (-1, 3, 30, 30))
writer.add_images('input', imgs, step)
writer.add_images('output', output, step)
step += 1
writer.close()