-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.py
55 lines (45 loc) · 1.19 KB
/
testing.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
43
44
45
46
47
48
49
50
51
52
import torch
import torch.nn as nn
from torch.autograd.variable import Variable
from torchvision import transforms
import numpy as np
import matplotlib.pyplot as plt
class Generator(nn.Module):
def __init__(self):
super(Generator,self).__init__()
self.in_feats = 128
self.out_feats = 784
self.fc0 = nn.Sequential(
nn.Linear(self.in_feats,256),
nn.ReLU()
)
self.fc1 = nn.Sequential(
nn.Linear(256,512),
nn.ReLU()
)
self.fc2 = nn.Sequential(
nn.Linear(512,1024),
nn.ReLU()
)
self.fc4 = nn.Sequential(
nn.Linear(1024,self.out_feats),
nn.Tanh()
)
def forward(self,x):
x = self.fc0(x)
x = self.fc1(x)
x = self.fc2(x)
x = self.fc4(x)
x = x.view(-1,1,28,28)
return x
device = "cpu"
generator = Generator()
generator.load_state_dict(torch.load("generator.pth", map_location=device))
generator.eval()
def noisydata(n,feats=128):
return Variable(torch.randn(n,feats)).to(device)
import matplotlib.pyplot as plt
for i in range(10):
img = generator(noisydata(1))
plt.imshow(img.detach()[0][0])
plt.show()