-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_stuff.py
58 lines (49 loc) · 1.72 KB
/
load_stuff.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
53
54
55
56
57
import torch
from torch import nn
if torch.cuda.is_available():
device = torch.device('cuda')
else:
device = torch.device('cpu')
class Flatten(torch.nn.Module):
def forward(self, x):
return x.view(x.size()[0], -1)
classifier = torch.nn.Sequential(
torch.nn.Conv2d(3, 8, 3, padding=1),
torch.nn.ReLU(),
torch.nn.MaxPool2d(2),
torch.nn.Conv2d(8, 16, 3, padding=1),
torch.nn.ReLU(),
torch.nn.MaxPool2d(2),
Flatten(),
torch.nn.Linear(16*16*16, 1)
).to(device)
classifier.load_state_dict(torch.load('./toTransfer/classifier.pt'))
class Generator(nn.Module):
def __init__(self, in_dim, dim=64):
super(Generator, self).__init__()
def dconv_bn_relu(in_dim, out_dim):
return nn.Sequential(
nn.ConvTranspose2d(in_dim, out_dim, 5, 2,
padding=2, output_padding=1, bias=False),
nn.BatchNorm2d(out_dim),
nn.ReLU())
self.l1 = nn.Sequential(
nn.Linear(in_dim, dim * 8 * 4 * 4, bias=False),
nn.BatchNorm1d(dim * 8 * 4 * 4),
nn.ReLU())
self.l2_5 = nn.Sequential(
dconv_bn_relu(dim * 8, dim * 4),
dconv_bn_relu(dim * 4, dim * 2),
dconv_bn_relu(dim * 2, dim),
nn.ConvTranspose2d(dim, 3, 5, 2, padding=2, output_padding=1),
nn.Tanh())
def forward(self, x):
y = self.l1(x)
y = y.view(y.size(0), -1, 4, 4)
y = self.l2_5(y)
return y
z_dim = 100
generator = Generator(z_dim)
generator.load_state_dict(torch.load('toTransfer/generator.pt')['G'])
classifier = classifier.eval()
generator = generator.eval()