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

Class Model

examples/HED/hed.py:103–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101
102
103class Model(ModelDesc):
104 def inputs(self):
105 return [tf.TensorSpec([None, None, None, 3], tf.float32, 'image'),
106 tf.TensorSpec([None, None, None], tf.int32, 'edgemap')]
107
108 def build_graph(self, image, edgemap):
109 image = image - tf.constant([104, 116, 122], dtype='float32')
110 image = tf.transpose(image, [0, 3, 1, 2])
111 edgemap = tf.expand_dims(edgemap, 3, name='edgemap4d')
112
113 def branch(name, l, up):
114 with tf.variable_scope(name):
115 l = Conv2D('convfc', l, 1, kernel_size=1, activation=tf.identity,
116 use_bias=True,
117 kernel_initializer=tf.constant_initializer())
118 while up != 1:
119 l = CaffeBilinearUpSample('upsample{}'.format(up), l, 2)
120 up = up // 2
121 return l
122
123 with argscope(Conv2D, kernel_size=3, activation=tf.nn.relu), \
124 argscope([Conv2D, MaxPooling], data_format='NCHW'):
125 l = Conv2D('conv1_1', image, 64)
126 l = Conv2D('conv1_2', l, 64)
127 b1 = branch('branch1', l, 1)
128 l = MaxPooling('pool1', l, 2)
129
130 l = Conv2D('conv2_1', l, 128)
131 l = Conv2D('conv2_2', l, 128)
132 b2 = branch('branch2', l, 2)
133 l = MaxPooling('pool2', l, 2)
134
135 l = Conv2D('conv3_1', l, 256)
136 l = Conv2D('conv3_2', l, 256)
137 l = Conv2D('conv3_3', l, 256)
138 b3 = branch('branch3', l, 4)
139 l = MaxPooling('pool3', l, 2)
140
141 l = Conv2D('conv4_1', l, 512)
142 l = Conv2D('conv4_2', l, 512)
143 l = Conv2D('conv4_3', l, 512)
144 b4 = branch('branch4', l, 8)
145 l = MaxPooling('pool4', l, 2)
146
147 l = Conv2D('conv5_1', l, 512)
148 l = Conv2D('conv5_2', l, 512)
149 l = Conv2D('conv5_3', l, 512)
150 b5 = branch('branch5', l, 16)
151
152 final_map = Conv2D('convfcweight',
153 tf.concat([b1, b2, b3, b4, b5], 1), 1, kernel_size=1,
154 kernel_initializer=tf.constant_initializer(0.2),
155 use_bias=False, activation=tf.identity)
156 costs = []
157 for idx, b in enumerate([b1, b2, b3, b4, b5, final_map]):
158 b = tf.transpose(b, [0, 2, 3, 1])
159 output = tf.nn.sigmoid(b, name='output{}'.format(idx + 1))
160 xentropy = class_balanced_sigmoid_cross_entropy(

Callers 2

get_configFunction · 0.70
runFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected