MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / Model

Class Model

examples/SuperResolution/enet-pat.py:45–218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43
44
45class Model(GANModelDesc):
46
47 def __init__(self, height=SHAPE_LR, width=SHAPE_LR):
48 super(Model, self).__init__()
49 self.height = height
50 self.width = width
51
52 def inputs(self):
53 return [tf.TensorSpec((None, self.height * 1, self.width * 1, CHANNELS), tf.float32, 'Ilr'),
54 tf.TensorSpec((None, self.height * 4, self.width * 4, CHANNELS), tf.float32, 'Ihr')]
55
56 def build_graph(self, Ilr, Ihr):
57 Ilr, Ihr = Ilr / 255.0, Ihr / 255.0
58 Ibicubic = tf.image.resize_bicubic(
59 Ilr, [4 * self.height, 4 * self.width], align_corners=True,
60 name='bicubic_baseline') # (0,1)
61
62 VGG_MEAN_TENSOR = tf.constant(VGG_MEAN, dtype=tf.float32)
63
64 def resnet_block(x, name):
65 with tf.variable_scope(name):
66 y = Conv2D('conv0', x, NF, activation=tf.nn.relu)
67 y = Conv2D('conv1', y, NF, activation=tf.identity)
68 return x + y
69
70 def upsample(x, factor=2):
71 _, h, w, _ = x.get_shape().as_list()
72 x = tf.image.resize_nearest_neighbor(x, [factor * h, factor * w], align_corners=True)
73 return x
74
75 def generator(x, Ibicubic):
76 x = x - VGG_MEAN_TENSOR / 255.0
77 with argscope(Conv2D, kernel_size=3, activation=tf.nn.relu):
78 x = Conv2D('conv1', x, NF)
79 for i in range(10):
80 x = resnet_block(x, 'block_%i' % i)
81 x = upsample(x)
82 x = Conv2D('conv_post_1', x, NF)
83 x = upsample(x)
84 x = Conv2D('conv_post_2', x, NF)
85 x = Conv2D('conv_post_3', x, NF)
86 Ires = Conv2D('conv_post_4', x, 3, activation=tf.identity)
87 Iest = tf.add(Ibicubic, Ires, name='Iest')
88 return Iest # [0,1]
89
90 @auto_reuse_variable_scope
91 def discriminator(x):
92 x = x - VGG_MEAN_TENSOR / 255.0
93 with argscope(Conv2D, kernel_size=3, activation=tf.nn.leaky_relu):
94 x = Conv2D('conv0', x, 32)
95 x = Conv2D('conv0b', x, 32, strides=2)
96 x = Conv2D('conv1', x, 64)
97 x = Conv2D('conv1b', x, 64, strides=2)
98 x = Conv2D('conv2', x, 128)
99 x = Conv2D('conv2b', x, 128, strides=2)
100 x = Conv2D('conv3', x, 256)
101 x = Conv2D('conv3b', x, 256, strides=2)
102 x = Conv2D('conv4', x, 512)

Callers 2

applyFunction · 0.70
enet-pat.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…