This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
hinet.py
136 lines (115 loc) · 4.53 KB
/
hinet.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from model import *
from invblock import INV_block_addition
from invblock import INV_block_affine
class Hinet_stage1(nn.Module):
'''Residual in Residual Dense Block'''
def __init__(self):
super(Hinet_stage1, self).__init__()
self.inv1 = INV_block_affine(imp_map=False)
self.inv2 = INV_block_affine(imp_map=False)
self.inv3 = INV_block_affine(imp_map=False)
self.inv4 = INV_block_affine(imp_map=False)
self.inv5 = INV_block_affine(imp_map=False)
self.inv6 = INV_block_affine(imp_map=False)
self.inv7 = INV_block_affine(imp_map=False)
self.inv8 = INV_block_affine(imp_map=False)
self.inv9 = INV_block_affine(imp_map=False)
self.inv10 = INV_block_affine(imp_map=False)
self.inv11 = INV_block_affine(imp_map=False)
self.inv12 = INV_block_affine(imp_map=False)
self.inv13 = INV_block_affine(imp_map=False)
self.inv14 = INV_block_affine(imp_map=False)
self.inv15 = INV_block_affine(imp_map=False)
self.inv16 = INV_block_affine(imp_map=False)
def forward(self, x, rev=False):
if not rev:
out = self.inv1(x)
out = self.inv2(out)
out = self.inv3(out)
out = self.inv4(out)
out = self.inv5(out)
out = self.inv6(out)
out = self.inv7(out)
out = self.inv8(out)
out = self.inv9(out)
out = self.inv10(out)
out = self.inv11(out)
out = self.inv12(out)
out = self.inv13(out)
out = self.inv14(out)
out = self.inv15(out)
out = self.inv16(out)
else:
out = self.inv16(x, rev=True)
out = self.inv15(out, rev=True)
out = self.inv14(out, rev=True)
out = self.inv13(out, rev=True)
out = self.inv12(out, rev=True)
out = self.inv11(out, rev=True)
out = self.inv10(out, rev=True)
out = self.inv9(out, rev=True)
out = self.inv8(out, rev=True)
out = self.inv7(out, rev=True)
out = self.inv6(out, rev=True)
out = self.inv5(out, rev=True)
out = self.inv4(out, rev=True)
out = self.inv3(out, rev=True)
out = self.inv2(out, rev=True)
out = self.inv1(out, rev=True)
return out
class Hinet_stage2(nn.Module):
'''Residual in Residual Dense Block'''
def __init__(self):
super(Hinet_stage2, self).__init__()
self.inv1 = INV_block_affine()
self.inv2 = INV_block_affine()
self.inv3 = INV_block_affine()
self.inv4 = INV_block_affine()
self.inv5 = INV_block_affine()
self.inv6 = INV_block_affine()
self.inv7 = INV_block_affine()
self.inv8 = INV_block_affine()
self.inv9 = INV_block_affine()
self.inv10 = INV_block_affine()
self.inv11 = INV_block_affine()
self.inv12 = INV_block_affine()
self.inv13 = INV_block_affine()
self.inv14 = INV_block_affine()
self.inv15 = INV_block_affine()
self.inv16 = INV_block_affine()
def forward(self, x, rev=False):
if not rev:
out = self.inv1(x)
out = self.inv2(out)
out = self.inv3(out)
out = self.inv4(out)
out = self.inv5(out)
out = self.inv6(out)
out = self.inv7(out)
out = self.inv8(out)
out = self.inv9(out)
out = self.inv10(out)
out = self.inv11(out)
out = self.inv12(out)
out = self.inv13(out)
out = self.inv14(out)
out = self.inv15(out)
out = self.inv16(out)
else:
out = self.inv16(x, rev=True)
out = self.inv15(out, rev=True)
out = self.inv14(out, rev=True)
out = self.inv13(out, rev=True)
out = self.inv12(out, rev=True)
out = self.inv11(out, rev=True)
out = self.inv10(out, rev=True)
out = self.inv9(out, rev=True)
out = self.inv8(out, rev=True)
out = self.inv7(out, rev=True)
out = self.inv6(out, rev=True)
out = self.inv5(out, rev=True)
out = self.inv4(out, rev=True)
out = self.inv3(out, rev=True)
out = self.inv2(out, rev=True)
out = self.inv1(out, rev=True)
return out