TheSusHero commited on
Commit
3035020
·
verified ·
1 Parent(s): 5717e34

Update network.py

Browse files
Files changed (1) hide show
  1. network.py +18 -25
network.py CHANGED
@@ -2,60 +2,53 @@ import tensorflow as tf
2
  import numpy as np
3
  import tf_slim as slim
4
 
 
 
5
 
6
-
7
- def resblock(inputs, out_channel=32, name='resblock'):
8
-
9
-
10
- with tf.compat.v1.variable_scope(name, reuse=reuse):
11
- x = slim.convolution2d(inputs, out_channel, [3, 3],
12
  activation_fn=None, scope='conv1')
13
- x = tf.nn.leaky_relu(x)
14
- x = slim.convolution2d(x, out_channel, [3, 3],
15
  activation_fn=None, scope='conv2')
16
- return x + inputs
17
-
18
-
19
-
20
 
21
  def unet_generator(inputs, channel=32, num_blocks=4, name='generator', reuse=False):
22
- with tf.variable_scope(name, reuse=reuse):
23
-
24
  x0 = slim.convolution2d(inputs, channel, [7, 7], activation_fn=None)
25
  x0 = tf.nn.leaky_relu(x0)
26
 
27
  x1 = slim.convolution2d(x0, channel, [3, 3], stride=2, activation_fn=None)
28
  x1 = tf.nn.leaky_relu(x1)
29
- x1 = slim.convolution2d(x1, channel*2, [3, 3], activation_fn=None)
30
  x1 = tf.nn.leaky_relu(x1)
31
 
32
- x2 = slim.convolution2d(x1, channel*2, [3, 3], stride=2, activation_fn=None)
33
  x2 = tf.nn.leaky_relu(x2)
34
- x2 = slim.convolution2d(x2, channel*4, [3, 3], activation_fn=None)
35
  x2 = tf.nn.leaky_relu(x2)
36
 
37
  for idx in range(num_blocks):
38
- x2 = resblock(x2, out_channel=channel*4, name='block_{}'.format(idx))
39
 
40
- x2 = slim.convolution2d(x2, channel*2, [3, 3], activation_fn=None)
41
  x2 = tf.nn.leaky_relu(x2)
42
 
43
  h1, w1 = tf.shape(x2)[1], tf.shape(x2)[2]
44
- x3 = tf.image.resize_bilinear(x2, (h1*2, w1*2))
45
- x3 = slim.convolution2d(x3+x1, channel*2, [3, 3], activation_fn=None)
46
  x3 = tf.nn.leaky_relu(x3)
47
  x3 = slim.convolution2d(x3, channel, [3, 3], activation_fn=None)
48
  x3 = tf.nn.leaky_relu(x3)
49
 
50
  h2, w2 = tf.shape(x3)[1], tf.shape(x3)[2]
51
- x4 = tf.image.resize_bilinear(x3, (h2*2, w2*2))
52
- x4 = slim.convolution2d(x4+x0, channel, [3, 3], activation_fn=None)
53
  x4 = tf.nn.leaky_relu(x4)
54
  x4 = slim.convolution2d(x4, 3, [7, 7], activation_fn=None)
55
 
56
  return x4
57
 
58
  if __name__ == '__main__':
59
-
60
-
61
  pass
 
2
  import numpy as np
3
  import tf_slim as slim
4
 
5
+ # Enable TensorFlow 1.x compatibility mode
6
+ tf.compat.v1.disable_eager_execution()
7
 
8
+ def resblock(inputs, out_channel=32, name='resblock', reuse=False):
9
+ with tf.compat.v1.variable_scope(name, reuse=reuse):
10
+ x = slim.convolution2d(inputs, out_channel, [3, 3],
 
 
 
11
  activation_fn=None, scope='conv1')
12
+ x = tf.nn.leaky_relu(x)
13
+ x = slim.convolution2d(x, out_channel, [3, 3],
14
  activation_fn=None, scope='conv2')
15
+ return x + inputs
 
 
 
16
 
17
  def unet_generator(inputs, channel=32, num_blocks=4, name='generator', reuse=False):
18
+ with tf.compat.v1.variable_scope(name, reuse=reuse):
 
19
  x0 = slim.convolution2d(inputs, channel, [7, 7], activation_fn=None)
20
  x0 = tf.nn.leaky_relu(x0)
21
 
22
  x1 = slim.convolution2d(x0, channel, [3, 3], stride=2, activation_fn=None)
23
  x1 = tf.nn.leaky_relu(x1)
24
+ x1 = slim.convolution2d(x1, channel * 2, [3, 3], activation_fn=None)
25
  x1 = tf.nn.leaky_relu(x1)
26
 
27
+ x2 = slim.convolution2d(x1, channel * 2, [3, 3], stride=2, activation_fn=None)
28
  x2 = tf.nn.leaky_relu(x2)
29
+ x2 = slim.convolution2d(x2, channel * 4, [3, 3], activation_fn=None)
30
  x2 = tf.nn.leaky_relu(x2)
31
 
32
  for idx in range(num_blocks):
33
+ x2 = resblock(x2, out_channel=channel * 4, name=f'block_{idx}', reuse=reuse)
34
 
35
+ x2 = slim.convolution2d(x2, channel * 2, [3, 3], activation_fn=None)
36
  x2 = tf.nn.leaky_relu(x2)
37
 
38
  h1, w1 = tf.shape(x2)[1], tf.shape(x2)[2]
39
+ x3 = tf.image.resize(x2, (h1 * 2, w1 * 2), method='bilinear')
40
+ x3 = slim.convolution2d(x3 + x1, channel * 2, [3, 3], activation_fn=None)
41
  x3 = tf.nn.leaky_relu(x3)
42
  x3 = slim.convolution2d(x3, channel, [3, 3], activation_fn=None)
43
  x3 = tf.nn.leaky_relu(x3)
44
 
45
  h2, w2 = tf.shape(x3)[1], tf.shape(x3)[2]
46
+ x4 = tf.image.resize(x3, (h2 * 2, w2 * 2), method='bilinear')
47
+ x4 = slim.convolution2d(x4 + x0, channel, [3, 3], activation_fn=None)
48
  x4 = tf.nn.leaky_relu(x4)
49
  x4 = slim.convolution2d(x4, 3, [7, 7], activation_fn=None)
50
 
51
  return x4
52
 
53
  if __name__ == '__main__':
 
 
54
  pass