-
Notifications
You must be signed in to change notification settings - Fork 0
/
style_transform.py
39 lines (31 loc) · 985 Bytes
/
style_transform.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
from model import vgg19
from model import VGG
import torch
import torchvision
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from collections import OrderedDict
a = torch.zeros(2, 2, requires_grad=True)
#print(a.detach().numpy())
epochs = 100
optimizer = optim.SGD([a], lr=1e-3)
for i in range(epochs):
optimizer.zero_grad()
b = torch.norm((a - 2) ** 2, 2)
b.backward()
optimizer.step()
print('value of a: {}'.format(a.detach().numpy()))
class framework(nn.Module):
def __init__(self):
super(framework, self).__init__()
model = nn.Sequential(OrderedDict([
("layer_one", nn.Linear(1, 10)), ("layer_two", nn.Linear(10, 3))
]))
print(model._modules["layer_one"])
print(model._modules["layer_two"])
def forward(self):
x = torch.randn(5, 5)
class vgg_extractor(VGG):
def __init__(self, features, num_classes):
super(self, vgg_extractor).__init__()