forked from RenYang-home/ALVC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CNN_img.py
128 lines (101 loc) · 4.36 KB
/
CNN_img.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
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
import tensorflow_compression as tfc
def MV_analysis(tensor, num_filters, M):
"""Builds the analysis transform."""
with tf.variable_scope("MV_analysis"):
with tf.variable_scope("layer_0"):
layer = tfc.SignalConv2D(
num_filters, (3, 3), corr=True, strides_down=2, padding="same_zeros",
use_bias=True, activation=tfc.GDN())
tensor = layer(tensor)
with tf.variable_scope("layer_1"):
layer = tfc.SignalConv2D(
num_filters, (3, 3), corr=True, strides_down=2, padding="same_zeros",
use_bias=True, activation=tfc.GDN())
tensor = layer(tensor)
with tf.variable_scope("layer_2"):
layer = tfc.SignalConv2D(
num_filters, (3, 3), corr=True, strides_down=2, padding="same_zeros",
use_bias=True, activation=tfc.GDN())
tensor = layer(tensor)
with tf.variable_scope("layer_3"):
layer = tfc.SignalConv2D(
M, (3, 3), corr=True, strides_down=2, padding="same_zeros",
use_bias=False, activation=None)
tensor = layer(tensor)
return tensor
def MV_synthesis(tensor, num_filters, out_filters=2):
"""Builds the synthesis transform."""
with tf.variable_scope("MV_synthesis"):
with tf.variable_scope("layer_0"):
layer = tfc.SignalConv2D(
num_filters, (3, 3), corr=False, strides_up=2, padding="same_zeros",
use_bias=True, activation=tfc.GDN(inverse=True))
tensor = layer(tensor)
with tf.variable_scope("layer_1"):
layer = tfc.SignalConv2D(
num_filters, (3, 3), corr=False, strides_up=2, padding="same_zeros",
use_bias=True, activation=tfc.GDN(inverse=True))
tensor = layer(tensor)
with tf.variable_scope("layer_2"):
layer = tfc.SignalConv2D(
num_filters, (3, 3), corr=False, strides_up=2, padding="same_zeros",
use_bias=True, activation=tfc.GDN(inverse=True))
tensor = layer(tensor)
with tf.variable_scope("layer_3"):
layer = tfc.SignalConv2D(
out_filters, (3, 3), corr=False, strides_up=2, padding="same_zeros",
use_bias=True, activation=None)
tensor = layer(tensor)
return tensor
def Res_analysis(tensor, num_filters, M, reuse=False):
"""Builds the analysis transform."""
with tf.variable_scope("analysis", reuse=reuse):
with tf.variable_scope("layer_0"):
layer = tfc.SignalConv2D(
num_filters, (5, 5), corr=True, strides_down=2, padding="same_zeros",
use_bias=True, activation=tfc.GDN())
tensor = layer(tensor)
with tf.variable_scope("layer_1"):
layer = tfc.SignalConv2D(
num_filters, (5, 5), corr=True, strides_down=2, padding="same_zeros",
use_bias=True, activation=tfc.GDN())
tensor = layer(tensor)
with tf.variable_scope("layer_2"):
layer = tfc.SignalConv2D(
num_filters, (5, 5), corr=True, strides_down=2, padding="same_zeros",
use_bias=True, activation=tfc.GDN())
tensor = layer(tensor)
with tf.variable_scope("layer_3"):
layer = tfc.SignalConv2D(
M, (5, 5), corr=True, strides_down=2, padding="same_zeros",
use_bias=False, activation=None)
tensor = layer(tensor)
return tensor
def Res_synthesis(tensor, num_filters, reuse=False):
"""Builds the synthesis transform."""
with tf.variable_scope("synthesis", reuse=reuse):
with tf.variable_scope("layer_0"):
layer = tfc.SignalConv2D(
num_filters, (5, 5), corr=False, strides_up=2, padding="same_zeros",
use_bias=True, activation=tfc.GDN(inverse=True))
tensor = layer(tensor)
with tf.variable_scope("layer_1"):
layer = tfc.SignalConv2D(
num_filters, (5, 5), corr=False, strides_up=2, padding="same_zeros",
use_bias=True, activation=tfc.GDN(inverse=True))
tensor = layer(tensor)
with tf.variable_scope("layer_2"):
layer = tfc.SignalConv2D(
num_filters, (5, 5), corr=False, strides_up=2, padding="same_zeros",
use_bias=True, activation=tfc.GDN(inverse=True))
tensor = layer(tensor)
with tf.variable_scope("layer_3"):
layer = tfc.SignalConv2D(
3, (5, 5), corr=False, strides_up=2, padding="same_zeros",
use_bias=True, activation=None)
tensor = layer(tensor)
return tensor