def _upscore_layer(bottom, shape, num_classes, name, debug, ksize=4, stride=2):
strides = [1, stride, stride, 1]
with tf.variable_scope(name) :
in_features = bottom.get_shape()[3].value
if shape is None:
# Compute shape out of Bottom
in_shape = bottom.get_shape()
h = ((in_shape[1] - 1) * stride) + 1
w = ((in_shape[2] - 1) * stride) + 1
new_shape = [in_shape[0], h, w, num_classes]
else:
new_shape = [shape[0], shape[1], shape[2], num_classes]
output_shape = tf.pack(new_shape)
logging.debug("Layer: %s, Fan-in: %d" % (name, in_features))
f_shape = [ksize, ksize, num_classes, in_features]
weights = get_deconv_filter(f_shape)
deconv = tf.nn.conv2d_transpose(bottom, weights, output_shape,
strides=strides, padding='SAME')
deconv.set_shape(new_shape)
print('Layer name: %s' % name)
print('Layer shape: %s' % str(deconv.get_shape()))
if debug:
deconv = tf.Print(deconv, [deconv.get_shape()],
message='Shape of %s' % name,
summarize=4, first_n=1)
_activation_summary(deconv)
return deconv
评论列表
文章目录