-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDecoder.py
77 lines (49 loc) · 2 KB
/
Decoder.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
###################################################
# Nicolo Savioli, 2017 -- Conv-GRU pytorch v 1.0 #
###################################################
import torch
from torch import nn
import torch.nn.functional as f
from torch.autograd import Variable
from ConvGRUCell import ConvGRUCell
class Decoder(nn.Module):
def __init__(self, Elt_size, Rlt_top_size,\
hidden_size, kernel_size):
super(Decoder, self).__init__()
self.ConvGRU_error = 0
self.Elt_size = Elt_size
self.Rlt_top_size = Rlt_top_size
self.hidden_size = hidden_size
self.kernel_size = kernel_size
self.GRUcell = ConvGRUCell(self.Elt_size + self.Rlt_top_size,\
self.hidden_size,self.kernel_size)
def forward(self, Elt, Rlt_top, Rlt_state):
if Rlt_top is None:
self.ConvGRU_error = self.GRUcell(Elt,Rlt_state)
else:
up_Rlt_top = f.upsample(Rlt_top, scale_factor=2)
tot_error_in_GRU = torch.cat((Elt,up_Rlt_top),1)
self.ConvGRU_error = self.GRUcell(tot_error_in_GRU,Rlt_state)
return self.ConvGRU_error
def test():
Elt_size = 32
Rlt_top_size = 0
hidden_size = 32
kernel_size = 3
image_size = 256
cuda_flag = True
Decode = Decoder(Elt_size, Rlt_top_size, hidden_size,\
image_size, kernel_size)
# Decode start to create first image:
Elt = Variable(torch.randn(1, Elt_size, image_size, image_size))
GRU_state = Variable(torch.zeros(1, Elt_size, image_size, image_size))
if cuda_flag == True:
Elt = Elt.cuda()
#Decode = Decode.cuda()
#GRU_state = GRU_state.cuda()
Decode = Decode
GRU_state = GRU_state
err = Decode(Elt,None,GRU_state)
print(err.data.size())
if __name__ == '__main__':
test()