-
Notifications
You must be signed in to change notification settings - Fork 0
/
nn.py
42 lines (30 loc) · 1.01 KB
/
nn.py
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
41
42
import torch.nn as nn
import torch
import torch.nn.functional as F
from torch.utils.data import DataLoader
import torchvision
from torch.utils.tensorboard import SummaryWriter
class Cht(nn.Module):
def __init__(self) -> None:
super(Cht, self).__init__()
self.conv = nn.Conv2d(3, 3, 5)
self.pool = nn.MaxPool2d(2,ceil_mode=True)
def forward(self, x):
x = self.conv(x)
return self.pool(x)
trans = torchvision.transforms.Compose(transforms=[
torchvision.transforms.ToTensor()
])
test_data = torchvision.datasets.CIFAR10('./Pytorch', train=False,
transform=trans)
data = DataLoader(test_data, batch_size=64, shuffle=True, num_workers=0)
writer = SummaryWriter('xxxpic')
model = Cht()
for i in range(2):
step = 1
for item in data:
imgs, label = item
if i == 1:
imgs = model(imgs)
writer.add_images('test{}'.format(i), imgs, step)
step += 1