-
Notifications
You must be signed in to change notification settings - Fork 13
/
model.py
52 lines (43 loc) · 2.05 KB
/
model.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
import tensorflow as tf
import tensorlayer as tl
def StructNet(input_data):
W_init = tf.truncated_normal_initializer(stddev=5e-2)
net=tl.layers.conv2d(input_data,n_filter=64,filter_size=(9,9), strides=(1,1),
act=tf.nn.relu,W_init=W_init,name="netS_conv0")
net=tl.layers.conv2d(net,n_filter=32,filter_size=(1,1),strides=(1,1),
act=tf.nn.relu,W_init=W_init,name="netS_conv1")
net=tl.layers.conv2d(net,n_filter=3,filter_size=(5,5),strides=(1,1),
act=tf.nn.relu,W_init=W_init,name="netS_conv2")
return net
def DetailNet(input_data):
W_init = tf.truncated_normal_initializer(stddev=5e-2)
net=tl.layers.conv2d(input_data,n_filter=64,filter_size=(5,5), strides=(1,1),
act=tf.nn.relu,W_init=W_init,name="netD_conv0")
for i in range(16):
net=tl.layers.conv2d(net,n_filter=64,filter_size=(3,3), strides=(1,1),
act=tf.nn.relu,W_init=W_init,name="netD_conv{}".format(i+1))
net=tl.layers.conv2d(net,n_filter=32,filter_size=(1,1), strides=(1,1),
act=tf.nn.relu,W_init=W_init,name="netD_convout1")
net=tl.layers.conv2d(net,n_filter=3,filter_size=(3,3), strides=(1,1),
act=tf.nn.relu,W_init=W_init,name="netD_convout")
return net
def DualCNN(x):
endpoints={}
net=tl.layers.InputLayer(x,name="img_in")
netD=DetailNet(net)
netS=StructNet(net)
net=tl.layers.ElementwiseLayer([netD, netS], tf.add,name="sumDS")
endpoints["compS"]=netS
endpoints["compD"]=netD
return net, endpoints
if __name__=="__main__":
tl.layers.clear_layers_name()
tf.reset_default_graph()
sess = tf.InteractiveSession()
x=tf.placeholder(tf.float32,shape=[None,64,64,3],name="x")
y=tf.placeholder(tf.float32,shape=[None,64,64,3],name="y")
net,endpoints=DualCNN(x)
tl.layers.initialize_global_variables(sess)
# print(tf.shape(net))
net.print_params()
net.print_layers()